Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c6f6e6dd2 | |||
| 8729782845 | |||
| df11d9c2bf | |||
| 9d722a83a3 | |||
| 16acb844d7 | |||
| 1647e8ccd6 | |||
| 95870f3f47 | |||
| f8941cbe83 | |||
| a0153d8eb3 | |||
| 3ddf060490 | |||
| 2805366502 | |||
| 8e2572248d | |||
| 0fc0e0ac9f | |||
| e4d961cd99 |
@@ -6,8 +6,6 @@ const bitcoin = require('bitcoinjs-lib');
|
|||||||
const varuint = require('varuint-bitcoin');
|
const varuint = require('varuint-bitcoin');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const fastMerkleRoot = require('merkle-lib/fastRoot');
|
const fastMerkleRoot = require('merkle-lib/fastRoot');
|
||||||
const promise = require('promise');
|
|
||||||
const merklebitcoin = promise.denodeify(require('merkle-bitcoin'));
|
|
||||||
|
|
||||||
function scriptCompile(addrHash) {
|
function scriptCompile(addrHash) {
|
||||||
return bitcoin.script.compile([
|
return bitcoin.script.compile([
|
||||||
@@ -25,15 +23,6 @@ function reverseBuffer(buff) {
|
|||||||
return reversed;
|
return reversed;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMerkleRoot(rpcData, generateTxRaw) {
|
|
||||||
hashes = [ reverseBuffer(new Buffer(generateTxRaw, 'hex')).toString('hex') ];
|
|
||||||
rpcData.transactions.forEach(function (value) {
|
|
||||||
hashes.push(value.txid ? value.txid : value.hash);
|
|
||||||
});
|
|
||||||
if (hashes.length === 1) return hashes[0];
|
|
||||||
return Object.values(merklebitcoin(hashes))[2].root;
|
|
||||||
}
|
|
||||||
|
|
||||||
function txesHaveWitnessCommit(transactions) {
|
function txesHaveWitnessCommit(transactions) {
|
||||||
return (
|
return (
|
||||||
transactions instanceof Array &&
|
transactions instanceof Array &&
|
||||||
@@ -47,12 +36,20 @@ function txesHaveWitnessCommit(transactions) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMerkleRoot2(transactions) {
|
function sha256(buffer) {
|
||||||
if (transactions.length === 0) return null;
|
return crypto.createHash('sha256').update(buffer).digest();
|
||||||
|
};
|
||||||
|
|
||||||
|
function hash256(buffer) {
|
||||||
|
return sha256(sha256(buffer));
|
||||||
|
};
|
||||||
|
|
||||||
|
function getMerkleRoot(transactions) {
|
||||||
|
if (transactions.length === 0) return new Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
||||||
const forWitness = txesHaveWitnessCommit(transactions);
|
const forWitness = txesHaveWitnessCommit(transactions);
|
||||||
const hashes = transactions.map(transaction => transaction.getHash(forWitness));
|
const hashes = transactions.map(transaction => transaction.getHash(forWitness));
|
||||||
const hash256 = function (buffer) { return crypto.createHash('sha256').update(buffer).digest(); };
|
|
||||||
const rootHash = fastMerkleRoot(hashes, hash256);
|
const rootHash = fastMerkleRoot(hashes, hash256);
|
||||||
|
console.log(forWitness);
|
||||||
return forWitness ? hash256(Buffer.concat([rootHash, transactions[0].ins[0].witness[0]])) : rootHash;
|
return forWitness ? hash256(Buffer.concat([rootHash, transactions[0].ins[0].witness[0]])) : rootHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +59,7 @@ const diff1 = 0x00000000ff000000000000000000000000000000000000000000000000000000
|
|||||||
|
|
||||||
module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
||||||
const poolAddrHash = bitcoin.address.fromBase58Check(poolAddress).hash;
|
const poolAddrHash = bitcoin.address.fromBase58Check(poolAddress).hash;
|
||||||
|
|
||||||
let txCoinbase = new bitcoin.Transaction();
|
let txCoinbase = new bitcoin.Transaction();
|
||||||
let bytesHeight;
|
let bytesHeight;
|
||||||
{ // input for coinbase tx
|
{ // input for coinbase tx
|
||||||
@@ -90,14 +88,13 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
txCoinbase.addOutput(new Buffer(rpcData.default_witness_commitment, 'hex'), 0);
|
txCoinbase.addOutput(new Buffer(rpcData.default_witness_commitment, 'hex'), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const merkleRoot = getMerkleRoot(rpcData, txCoinbase.getHash().toString('hex'));
|
|
||||||
|
|
||||||
let header = new Buffer(80);
|
let header = new Buffer(80);
|
||||||
{ let position = 0;
|
{ let position = 0;
|
||||||
header.writeUInt32BE(rpcData.height, position, 4); // height 42-46
|
header.writeUInt32BE(rpcData.height, position, 4); // height 42-46
|
||||||
header.write(rpcData.bits, position += 4, 4, 'hex'); // bits 47-50
|
header.write(rpcData.bits, position += 4, 4, 'hex'); // bits 47-50
|
||||||
header.writeUInt32BE(rpcData.curtime, position += 4, 4, 'hex'); // nTime 51-54
|
header.writeUInt32BE(rpcData.curtime, position += 4, 4, 'hex'); // nTime 51-54
|
||||||
header.write(merkleRoot, position += 4, 32, 'hex'); // merkelRoot 55-87
|
header.write('DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD', position += 4, 32, 'hex'); // merkelRoot 55-87
|
||||||
header.write(rpcData.previousblockhash, position += 32, 32, 'hex'); // prevblockhash 88-120
|
header.write(rpcData.previousblockhash, position += 32, 32, 'hex'); // prevblockhash 88-120
|
||||||
header.writeUInt32BE(rpcData.version, position += 32, 4); // version 121-153
|
header.writeUInt32BE(rpcData.version, position += 32, 4); // version 121-153
|
||||||
header = reverseBuffer(header);
|
header = reverseBuffer(header);
|
||||||
@@ -156,13 +153,13 @@ function update_merkle_root_hash(blob_in, blob_out) {
|
|||||||
transactions.push(tx);
|
transactions.push(tx);
|
||||||
offset += tx.byteLength();
|
offset += tx.byteLength();
|
||||||
}
|
}
|
||||||
getMerkleRoot2(transactions).copy(blob_out, 4 + 32);
|
getMerkleRoot(transactions).copy(blob_out, 4 + 32);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.convertRavenBlob = function(blobBuffer) {
|
module.exports.convertRavenBlob = function(blobBuffer) {
|
||||||
let header = blobBuffer.slice(0, 80);
|
let header = blobBuffer.slice(0, 80);
|
||||||
update_merkle_root_hash(blobBuffer, header);
|
update_merkle_root_hash(blobBuffer, header);
|
||||||
return reverseBuffer(crypto.createHash('sha256').update(header).digest());
|
return reverseBuffer(hash256(header));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
|
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
|
||||||
|
|||||||
+2
-3
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cryptoforknote-util",
|
"name": "cryptoforknote-util",
|
||||||
"version": "9.0.5",
|
"version": "9.0.17",
|
||||||
"main": "cryptoforknote-util",
|
"main": "cryptoforknote-util",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LucasJones",
|
"name": "LucasJones",
|
||||||
@@ -17,8 +17,7 @@
|
|||||||
"bignum": "^0.13.1",
|
"bignum": "^0.13.1",
|
||||||
"sha3": "*",
|
"sha3": "*",
|
||||||
"varuint-bitcoin": "^1.0.4",
|
"varuint-bitcoin": "^1.0.4",
|
||||||
"bitcoinjs-lib": "git+https://github.com/bitcoinjs/bitcoinjs-lib.git#533d6c2e6d0aa4111f7948b1c12003cf6ef83137",
|
"bitcoinjs-lib": "git+https://github.com/bitcoinjs/bitcoinjs-lib.git#533d6c2e6d0aa4111f7948b1c12003cf6ef83137"
|
||||||
"merkle-bitcoin": "git+https://github.com/CloudMining/merkle-bitcoin.git#ec00ae20ba60d444e150ead03c747695ddaa83a1"
|
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"cryptonight",
|
"cryptonight",
|
||||||
|
|||||||
Reference in New Issue
Block a user