Compare commits

...

8 Commits

Author SHA1 Message Date
MoneroOcean 8729782845 Fixed raven block processing 2020-12-09 04:26:14 +00:00
MoneroOcean df11d9c2bf Fixed raven block processing 2020-12-09 04:21:22 +00:00
MoneroOcean 9d722a83a3 Fixed raven block processing 2020-12-09 04:19:26 +00:00
MoneroOcean 16acb844d7 Fixed raven block processing 2020-12-09 04:19:15 +00:00
MoneroOcean 1647e8ccd6 Fixed raven block processing 2020-12-09 03:45:40 +00:00
MoneroOcean 95870f3f47 Fixed raven block processing 2020-12-09 03:07:40 +00:00
MoneroOcean f8941cbe83 Fixed raven block processing 2020-12-09 03:02:01 +00:00
MoneroOcean a0153d8eb3 Fixed raven block processing 2020-12-09 02:58:01 +00:00
2 changed files with 20 additions and 24 deletions
+19 -23
View File
@@ -5,7 +5,6 @@ const bignum = require('bignum');
const bitcoin = require('bitcoinjs-lib');
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'));
@@ -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,13 +37,22 @@ function txesHaveWitnessCommit(transactions) {
);
}
function getMerkleRoot2(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;
function hash256(buffer) {
return crypto.createHash('sha256').update(buffer).digest();
};
function getMerkleRoot(transactions) {
// error
if (transactions.length === 0) return new Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
// coinbase tx only
const txhash0 = transactions[0].getHash();
if (transactions.length === 1) return txhash0;
// have other txs
let hashes = [ reverseBuffer(txhash0).toString('hex') ];
transactions.slice(1).forEach(function (value) {
hashes.push(value.hash);
});
return reverseBuffer(new Buffer(Object.values(merklebitcoin(hashes))[2].root, 'hex'));
}
let last_epoch_number;
@@ -91,14 +90,13 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
txCoinbase.addOutput(new Buffer(rpcData.default_witness_commitment, 'hex'), 0);
}
}
const merkleRoot = getMerkleRoot(rpcData, txCoinbase.getHash().toString('hex'));
let header = new Buffer(80);
{ let position = 0;
header.writeUInt32BE(rpcData.height, position, 4); // height 42-46
header.write(rpcData.bits, position += 4, 4, 'hex'); // bits 47-50
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.writeUInt32BE(rpcData.version, position += 32, 4); // version 121-153
header = reverseBuffer(header);
@@ -157,15 +155,13 @@ function update_merkle_root_hash(blob_in, blob_out) {
transactions.push(tx);
offset += tx.byteLength();
}
const rpcData = { transactions: transactions.slice(1) };
reverseBuffer(new Buffer(getMerkleRoot(rpcData, transactions[0].getHash().toString('hex')), 'hex')).copy(blob_out, 4 + 32);
getMerkleRoot(transactions).copy(blob_out, 4 + 32);
};
module.exports.convertRavenBlob = function(blobBuffer) {
let header = blobBuffer.slice(0, 80);
update_merkle_root_hash(blobBuffer, header);
const hash256 = function (buffer) { return crypto.createHash('sha256').update(buffer).digest(); };
return reverseBuffer(hash256(crypto.createHash('sha256').update(header).digest()));
return reverseBuffer(hash256(hash256(header)));
};
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "cryptoforknote-util",
"version": "9.0.10",
"version": "9.0.16",
"main": "cryptoforknote-util",
"author": {
"name": "LucasJones",