Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c48ad7e46 | |||
| f0c26e6d5b | |||
| 7a1d7271a1 | |||
| 30e051fa46 | |||
| 4ccd4fdca7 |
@@ -46,14 +46,40 @@ function hash256(buffer) {
|
|||||||
return sha256(sha256(buffer));
|
return sha256(sha256(buffer));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function sha256_3(buffer) {
|
||||||
|
return crypto.createHash('sha3-256').update(buffer).digest();
|
||||||
|
};
|
||||||
|
|
||||||
|
function hash256_3(buffer) {
|
||||||
|
return sha256_3(sha256_3(buffer));
|
||||||
|
};
|
||||||
|
|
||||||
|
function transaction_hash(transaction, forWitness) {
|
||||||
|
if (forWitness && transaction.isCoinbase()) return Buffer.alloc(32, 0);
|
||||||
|
return hash256(transaction.__toBuffer(undefined, undefined, forWitness));
|
||||||
|
}
|
||||||
|
|
||||||
|
function transaction_hash3(transaction, forWitness) {
|
||||||
|
if (forWitness && transaction.isCoinbase()) return Buffer.alloc(32, 0);
|
||||||
|
return hash256_3(transaction.__toBuffer(undefined, undefined, forWitness));
|
||||||
|
}
|
||||||
|
|
||||||
function getMerkleRoot(transactions) {
|
function getMerkleRoot(transactions) {
|
||||||
if (transactions.length === 0) return Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
if (transactions.length === 0) return Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
||||||
const forWitness = txesHaveWitnessCommit(transactions);
|
const forWitness = txesHaveWitnessCommit(transactions);
|
||||||
const hashes = transactions.map(transaction => transaction.getHash(forWitness));
|
const hashes = transactions.map(transaction => transaction_hash(transaction, forWitness));
|
||||||
const rootHash = fastMerkleRoot(hashes, hash256);
|
const rootHash = fastMerkleRoot(hashes, hash256);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMerkleRoot3(transactions) {
|
||||||
|
if (transactions.length === 0) return Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
||||||
|
const forWitness = txesHaveWitnessCommit(transactions);
|
||||||
|
const hashes = transactions.map(transaction => transaction_hash3(transaction, forWitness));
|
||||||
|
const rootHash = fastMerkleRoot(hashes, hash256_3);
|
||||||
|
return forWitness ? hash256_3(Buffer.concat([rootHash, transactions[0].ins[0].witness[0]])) : rootHash;
|
||||||
|
}
|
||||||
|
|
||||||
let last_epoch_number;
|
let last_epoch_number;
|
||||||
let last_seed_hash;
|
let last_seed_hash;
|
||||||
|
|
||||||
@@ -169,10 +195,26 @@ function update_merkle_root_hash(offset, payload, blob_in, blob_out) {
|
|||||||
getMerkleRoot(transactions).copy(blob_out, 4 + 32);
|
getMerkleRoot(transactions).copy(blob_out, 4 + 32);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function update_merkle_root_hash3(offset, payload, blob_in, blob_out) {
|
||||||
|
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(blob_in.slice(offset), true, payload && i == 0);
|
||||||
|
transactions.push(tx);
|
||||||
|
offset += tx.byteLength();
|
||||||
|
}
|
||||||
|
getMerkleRoot3(transactions).copy(blob_out, 4 + 32);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.blockHashBuff = function(blobBuffer) {
|
module.exports.blockHashBuff = function(blobBuffer) {
|
||||||
return reverseBuffer(hash256(blobBuffer));
|
return reverseBuffer(hash256(blobBuffer));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.blockHashBuff3 = function(blobBuffer) {
|
||||||
|
return reverseBuffer(hash256_3(blobBuffer));
|
||||||
|
};
|
||||||
|
|
||||||
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(80 + 8 + 32, false, blobBuffer, header);
|
update_merkle_root_hash(80 + 8 + 32, false, blobBuffer, header);
|
||||||
@@ -223,7 +265,7 @@ module.exports.convertRtmBlob = function(blobBuffer) {
|
|||||||
|
|
||||||
module.exports.convertKcnBlob = function(blobBuffer) {
|
module.exports.convertKcnBlob = function(blobBuffer) {
|
||||||
let header = blobBuffer.slice(0, 80);
|
let header = blobBuffer.slice(0, 80);
|
||||||
update_merkle_root_hash(80, false, blobBuffer, header);
|
update_merkle_root_hash3(80, false, blobBuffer, header);
|
||||||
return header;
|
return header;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cryptoforknote-util",
|
"name": "cryptoforknote-util",
|
||||||
"version": "15.3.8",
|
"version": "15.3.12",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LucasJones",
|
"name": "LucasJones",
|
||||||
"email": "lucasjonesdev@hotmail.co.uk"
|
"email": "lucasjonesdev@hotmail.co.uk"
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ function createTransactionOutput(amount, payee, rewardToPool, reward, txOutputBu
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateTransactionOutputs(rpcData, poolAddress, is_witness) {
|
function generateTransactionOutputs(rpcData, poolAddress, is_witness) {
|
||||||
let reward = rpcData.coinbasevalue;
|
let reward = rpcData.coinbasevalue + (rpcData.coinbasedevreward ? rpcData.coinbasedevreward : 0);
|
||||||
let rewardToPool = reward;
|
let rewardToPool = reward;
|
||||||
let txOutputBuffers = [];
|
let txOutputBuffers = [];
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ function generateTransactionOutputs(rpcData, poolAddress, is_witness) {
|
|||||||
|
|
||||||
module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
||||||
const extraNoncePlaceholderLength = 17;
|
const extraNoncePlaceholderLength = 17;
|
||||||
const coinbaseVersion = Buffer.concat([packUInt16LE(3), packUInt16LE(5)]);
|
const coinbaseVersion = rpcData.coinbasedevreward ? Buffer.concat([packUInt16LE(1), packUInt16LE(0)]) : Buffer.concat([packUInt16LE(3), packUInt16LE(5)]);
|
||||||
|
|
||||||
const scriptSigPart1 = Buffer.concat([
|
const scriptSigPart1 = Buffer.concat([
|
||||||
serializeNumber(rpcData.height),
|
serializeNumber(rpcData.height),
|
||||||
@@ -240,7 +240,7 @@ module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
|
|
||||||
const scriptSigPart2 = serializeString('/nodeStratum/');
|
const scriptSigPart2 = serializeString('/nodeStratum/');
|
||||||
|
|
||||||
const is_witness = rpcData.default_witness_commitment !== undefined;
|
const is_witness = false; //rpcData.default_witness_commitment !== undefined;
|
||||||
|
|
||||||
const blob1 = Buffer.concat([
|
const blob1 = Buffer.concat([
|
||||||
coinbaseVersion,
|
coinbaseVersion,
|
||||||
|
|||||||
Reference in New Issue
Block a user