Fixed raven block processing

This commit is contained in:
MoneroOcean
2020-12-09 03:45:40 +00:00
parent 95870f3f47
commit 1647e8ccd6
2 changed files with 11 additions and 8 deletions

View File

@@ -5,8 +5,8 @@ const bignum = require('bignum');
const bitcoin = require('bitcoinjs-lib'); 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 promise = require('promise'); 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([
@@ -43,10 +43,12 @@ function hash256(buffer) {
function getMerkleRoot(transactions) { function getMerkleRoot(transactions) {
if (transactions.length === 0) return null; if (transactions.length === 0) return null;
const forWitness = txesHaveWitnessCommit(transactions); if (transactions.length === 1) return transactions[0];
const hashes = transactions.map(transaction => transaction.getHash(forWitness)); let hashes = [ reverseBuffer(transactions[0]).toString('hex') ];
const rootHash = fastMerkleRoot(hashes, hash256); transactions.split(1).forEach(function (value) {
return forWitness ? hash256(Buffer.concat([rootHash, transactions[0].ins[0].witness[0]])) : rootHash; hashes.push(value.hash);
});
return reverseBuffer(new Buffer(Object.values(merklebitcoin(hashes))[2].root, 'hex'));
} }
let last_epoch_number; let last_epoch_number;
@@ -149,7 +151,7 @@ function update_merkle_root_hash(blob_in, blob_out) {
transactions.push(tx); transactions.push(tx);
offset += tx.byteLength(); offset += tx.byteLength();
} }
reverseBuffer(getMerkleRoot(transactions)).copy(blob_out, 4 + 32); getMerkleRoot(transactions).copy(blob_out, 4 + 32);
}; };
module.exports.convertRavenBlob = function(blobBuffer) { module.exports.convertRavenBlob = function(blobBuffer) {

View File

@@ -1,6 +1,6 @@
{ {
"name": "cryptoforknote-util", "name": "cryptoforknote-util",
"version": "9.0.12", "version": "9.0.13",
"main": "cryptoforknote-util", "main": "cryptoforknote-util",
"author": { "author": {
"name": "LucasJones", "name": "LucasJones",
@@ -17,7 +17,8 @@
"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",