Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f8941cbe83 | |||
| a0153d8eb3 | |||
| 3ddf060490 | |||
| 2805366502 | |||
| 8e2572248d | |||
| 0fc0e0ac9f | |||
| e4d961cd99 | |||
| 18eedca1e9 |
@@ -7,7 +7,6 @@ const varuint = require('varuint-bitcoin');
|
||||
const crypto = require('crypto');
|
||||
const fastMerkleRoot = require('merkle-lib/fastRoot');
|
||||
const promise = require('promise');
|
||||
const merklebitcoin = promise.denodeify(require('merkle-bitcoin'));
|
||||
|
||||
function scriptCompile(addrHash) {
|
||||
return bitcoin.script.compile([
|
||||
@@ -25,15 +24,6 @@ function reverseBuffer(buff) {
|
||||
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) {
|
||||
return (
|
||||
transactions instanceof Array &&
|
||||
@@ -47,11 +37,14 @@ function txesHaveWitnessCommit(transactions) {
|
||||
);
|
||||
}
|
||||
|
||||
function getMerkleRoot2(transactions) {
|
||||
function hash256(buffer) {
|
||||
return crypto.createHash('sha256').update(buffer).digest();
|
||||
};
|
||||
|
||||
function getMerkleRoot(transactions) {
|
||||
if (transactions.length === 0) return null;
|
||||
const forWitness = txesHaveWitnessCommit(transactions);
|
||||
const hashes = transactions.map(transaction => transaction.getHash(forWitness));
|
||||
const hash256 = function (buffer) { return crypto.createHash('sha256').update(buffer).digest(); };
|
||||
const rootHash = fastMerkleRoot(hashes, hash256);
|
||||
return forWitness ? hash256(Buffer.concat([rootHash, transactions[0].ins[0].witness[0]])) : rootHash;
|
||||
}
|
||||
@@ -62,6 +55,7 @@ const diff1 = 0x00000000ff000000000000000000000000000000000000000000000000000000
|
||||
|
||||
module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
||||
const poolAddrHash = bitcoin.address.fromBase58Check(poolAddress).hash;
|
||||
|
||||
let txCoinbase = new bitcoin.Transaction();
|
||||
let bytesHeight;
|
||||
{ // input for coinbase tx
|
||||
@@ -90,7 +84,7 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
||||
txCoinbase.addOutput(new Buffer(rpcData.default_witness_commitment, 'hex'), 0);
|
||||
}
|
||||
}
|
||||
const merkleRoot = getMerkleRoot(rpcData, txCoinbase.getHash().toString('hex'));
|
||||
const merkleRoot = new Buffer('DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD', 'hex'); // 32 bytes
|
||||
|
||||
let header = new Buffer(80);
|
||||
{ let position = 0;
|
||||
@@ -146,22 +140,27 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.convertRavenBlob = function(blobBuffer) {
|
||||
let header = blobBuffer.slice(0, 80); // header
|
||||
function update_merkle_root_hash(blob_in, blob_out) {
|
||||
let offset = 80 + 8 + 32;
|
||||
const nTransactions = varuint.decode(blobBuffer, offset);
|
||||
const nTransactions = varuint.decode(blob_in, offset);
|
||||
offset += varuint.decode.bytes;
|
||||
let transactions = [];
|
||||
for (let i = 0; i < nTransactions; ++i) {
|
||||
const tx = bitcoin.Transaction.fromBuffer(blobBuffer.slice(offset), true);
|
||||
const tx = bitcoin.Transaction.fromBuffer(blob_in.slice(offset), true);
|
||||
transactions.push(tx);
|
||||
offset += tx.byteLength();
|
||||
}
|
||||
getMerkleRoot2(transactions).copy(header, 4 + 32);
|
||||
return reverseBuffer(crypto.createHash('sha256').update(header).digest());
|
||||
reverseBuffer(getMerkleRoot(transactions)).copy(blob_out, 4 + 32);
|
||||
};
|
||||
|
||||
module.exports.convertRavenBlob = function(blobBuffer) {
|
||||
let header = blobBuffer.slice(0, 80);
|
||||
update_merkle_root_hash(blobBuffer, header);
|
||||
return reverseBuffer(hash256(hash256(header)));
|
||||
};
|
||||
|
||||
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
|
||||
update_merkle_root_hash(blockTemplate, blockTemplate);
|
||||
nonceBuff.copy (blockTemplate, 80, 0, 8);
|
||||
mixhashBuff.copy(blockTemplate, 88, 0, 32);
|
||||
return blockTemplate;
|
||||
|
||||
+2
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cryptoforknote-util",
|
||||
"version": "9.0.4",
|
||||
"version": "9.0.11",
|
||||
"main": "cryptoforknote-util",
|
||||
"author": {
|
||||
"name": "LucasJones",
|
||||
@@ -17,8 +17,7 @@
|
||||
"bignum": "^0.13.1",
|
||||
"sha3": "*",
|
||||
"varuint-bitcoin": "^1.0.4",
|
||||
"bitcoinjs-lib": "git+https://github.com/bitcoinjs/bitcoinjs-lib.git#533d6c2e6d0aa4111f7948b1c12003cf6ef83137",
|
||||
"merkle-bitcoin": "git+https://github.com/CloudMining/merkle-bitcoin.git#ec00ae20ba60d444e150ead03c747695ddaa83a1"
|
||||
"bitcoinjs-lib": "git+https://github.com/bitcoinjs/bitcoinjs-lib.git#533d6c2e6d0aa4111f7948b1c12003cf6ef83137"
|
||||
},
|
||||
"keywords": [
|
||||
"cryptonight",
|
||||
|
||||
Reference in New Issue
Block a user