Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7bbb0cf80e | |||
| 16f9569d0c | |||
| e6143eb9c0 | |||
| 1b2f6af8f8 | |||
| eb61aefe8b |
@@ -64,19 +64,11 @@ function transaction_hash3(transaction, forWitness) {
|
|||||||
return hash256_3(transaction.__toBuffer(undefined, undefined, forWitness));
|
return hash256_3(transaction.__toBuffer(undefined, undefined, forWitness));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMerkleRoot(transactions) {
|
function getMerkleRoot(transactions, transaction_hash_func, detectWitness) {
|
||||||
if (transactions.length === 0) return Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
if (transactions.length === 0) return Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
||||||
const forWitness = txesHaveWitnessCommit(transactions);
|
const forWitness = detectWitness ? txesHaveWitnessCommit(transactions) : false;
|
||||||
const hashes = transactions.map(transaction => transaction_hash(transaction, forWitness));
|
const hashes = transactions.map(transaction => transaction_hash_func(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
return forWitness ? hash256_3(Buffer.concat([rootHash, transactions[0].ins[0].witness[0]])) : rootHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +175,7 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function update_merkle_root_hash(offset, payload, blob_in, blob_out) {
|
function update_merkle_root_hash(offset, payload, blob_in, blob_out, transaction_hash_func, detectWitness) {
|
||||||
const nTransactions = varuint.decode(blob_in, offset);
|
const nTransactions = varuint.decode(blob_in, offset);
|
||||||
offset += varuint.decode.bytes;
|
offset += varuint.decode.bytes;
|
||||||
let transactions = [];
|
let transactions = [];
|
||||||
@@ -192,19 +184,7 @@ function update_merkle_root_hash(offset, payload, blob_in, blob_out) {
|
|||||||
transactions.push(tx);
|
transactions.push(tx);
|
||||||
offset += tx.byteLength();
|
offset += tx.byteLength();
|
||||||
}
|
}
|
||||||
getMerkleRoot(transactions).copy(blob_out, 4 + 32);
|
getMerkleRoot(transactions, transaction_hash_func, detectWitness).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) {
|
||||||
@@ -217,12 +197,12 @@ module.exports.blockHashBuff3 = function(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, transaction_hash, true);
|
||||||
return module.exports.blockHashBuff(header);
|
return module.exports.blockHashBuff(header);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
|
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
|
||||||
update_merkle_root_hash(80 + 8 + 32, false, blockTemplate, blockTemplate);
|
update_merkle_root_hash(80 + 8 + 32, false, blockTemplate, blockTemplate, transaction_hash, true);
|
||||||
nonceBuff.copy (blockTemplate, 80, 0, 8);
|
nonceBuff.copy (blockTemplate, 80, 0, 8);
|
||||||
mixhashBuff.copy(blockTemplate, 88, 0, 32);
|
mixhashBuff.copy(blockTemplate, 88, 0, 32);
|
||||||
return blockTemplate;
|
return blockTemplate;
|
||||||
@@ -259,24 +239,24 @@ module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
|
|
||||||
module.exports.convertRtmBlob = function(blobBuffer) {
|
module.exports.convertRtmBlob = function(blobBuffer) {
|
||||||
let header = blobBuffer.slice(0, 80);
|
let header = blobBuffer.slice(0, 80);
|
||||||
update_merkle_root_hash(80, true, blobBuffer, header);
|
update_merkle_root_hash(80, true, blobBuffer, header, transaction_hash, true);
|
||||||
return header;
|
return header;
|
||||||
};
|
};
|
||||||
|
|
||||||
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_hash3(80, false, blobBuffer, header);
|
update_merkle_root_hash(80, false, blobBuffer, header, transaction_hash3, false);
|
||||||
return header;
|
return header;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.constructNewRtmBlob = function(blockTemplate, nonceBuff) {
|
module.exports.constructNewRtmBlob = function(blockTemplate, nonceBuff) {
|
||||||
update_merkle_root_hash(80, true, blockTemplate, blockTemplate);
|
update_merkle_root_hash(80, true, blockTemplate, blockTemplate, transaction_hash, true);
|
||||||
nonceBuff.copy(blockTemplate, 76, 0, 4);
|
nonceBuff.copy(blockTemplate, 76, 0, 4);
|
||||||
return blockTemplate;
|
return blockTemplate;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.constructNewKcnBlob = function(blockTemplate, nonceBuff) {
|
module.exports.constructNewKcnBlob = function(blockTemplate, nonceBuff) {
|
||||||
update_merkle_root_hash3(80, false, blockTemplate, blockTemplate);
|
update_merkle_root_hash(80, false, blockTemplate, blockTemplate, transaction_hash3, false);
|
||||||
nonceBuff.copy(blockTemplate, 76, 0, 4);
|
nonceBuff.copy(blockTemplate, 76, 0, 4);
|
||||||
return blockTemplate;
|
return blockTemplate;
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cryptoforknote-util",
|
"name": "cryptoforknote-util",
|
||||||
"version": "15.3.14",
|
"version": "15.3.19",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LucasJones",
|
"name": "LucasJones",
|
||||||
"email": "lucasjonesdev@hotmail.co.uk"
|
"email": "lucasjonesdev@hotmail.co.uk"
|
||||||
|
|||||||
@@ -173,13 +173,13 @@ function createTransactionOutput(amount, payee, rewardToPool, reward, txOutputBu
|
|||||||
return { reward: reward - amount, rewardToPool: rewardToPool - amount };
|
return { reward: reward - amount, rewardToPool: rewardToPool - amount };
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateTransactionOutputs(rpcData, poolAddress, is_witness) {
|
function generateTransactionOutputs(rpcData, poolAddress) {
|
||||||
let reward = rpcData.coinbasevalue + (rpcData.coinbasedevreward ? rpcData.coinbasedevreward.value : 0);
|
let reward = rpcData.coinbasevalue + (rpcData.coinbasedevreward ? rpcData.coinbasedevreward.value : 0);
|
||||||
let rewardToPool = reward;
|
let rewardToPool = reward;
|
||||||
let txOutputBuffers = [];
|
let txOutputBuffers = [];
|
||||||
|
|
||||||
if (rpcData.coinbasedevreward) {
|
if (rpcData.coinbasedevreward) {
|
||||||
const rewards = createTransactionOutput(rpcData.coinbasedevreward.value, rpcData.coinbasedevreward.address, rewardToPool, reward, txOutputBuffers, Buffer.from(rpcData.coinbasedevreward.scriptpubkey, 'hex'));
|
const rewards = createTransactionOutput(rpcData.coinbasedevreward.value, null, rewardToPool, reward, txOutputBuffers, Buffer.from(rpcData.coinbasedevreward.scriptpubkey, 'hex'));
|
||||||
reward = rewards.reward;
|
reward = rewards.reward;
|
||||||
rewardToPool = rewards.rewardToPool;
|
rewardToPool = rewards.rewardToPool;
|
||||||
}
|
}
|
||||||
@@ -215,16 +215,16 @@ function generateTransactionOutputs(rpcData, poolAddress, is_witness) {
|
|||||||
|
|
||||||
createTransactionOutput(rewardToPool, null, rewardToPool, reward, txOutputBuffers, Buffer.from(addressToScript(poolAddress), "hex"));
|
createTransactionOutput(rewardToPool, null, rewardToPool, reward, txOutputBuffers, Buffer.from(addressToScript(poolAddress), "hex"));
|
||||||
|
|
||||||
if (is_witness) {
|
if (rpcData.default_witness_commitment) {
|
||||||
const witness_commitment = Buffer.from(rpcData.default_witness_commitment, 'hex');
|
createTransactionOutput(0, null, rewardToPool, reward, txOutputBuffers, Buffer.from(rpcData.default_witness_commitment, 'hex'));
|
||||||
txOutputBuffers.push(Buffer.concat([
|
txOutputBuffers.push(Buffer.concat([
|
||||||
varIntBuffer(1),
|
varIntBuffer(1),
|
||||||
varIntBuffer(witness_commitment.length),
|
varIntBuffer(32),
|
||||||
witness_commitment
|
Buffer.alloc(32, 0)
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Buffer.concat([ varIntBuffer(is_witness ? txOutputBuffers.length - 1 : txOutputBuffers.length), Buffer.concat(txOutputBuffers)]);
|
return Buffer.concat([ varIntBuffer(rpcData.default_witness_commitment ? txOutputBuffers.length - 1 : txOutputBuffers.length), Buffer.concat(txOutputBuffers)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
||||||
@@ -240,7 +240,7 @@ module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
|
|
||||||
const scriptSigPart2 = serializeString('/nodeStratum/');
|
const scriptSigPart2 = serializeString('/nodeStratum/');
|
||||||
|
|
||||||
const is_witness = false; //rpcData.default_witness_commitment !== undefined;
|
const is_witness = rpcData.default_witness_commitment !== undefined;
|
||||||
|
|
||||||
const blob1 = Buffer.concat([
|
const blob1 = Buffer.concat([
|
||||||
coinbaseVersion,
|
coinbaseVersion,
|
||||||
|
|||||||
Reference in New Issue
Block a user