Draft implementation of Ravencoin utils
This commit is contained in:
24
index.js
24
index.js
@@ -56,6 +56,9 @@ function varIntBuffer(n) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let last_epoch_number;
|
||||||
|
let last_seedhash;
|
||||||
|
|
||||||
module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
||||||
// epoch length
|
// epoch length
|
||||||
const EPOCH_LENGTH = 7500;
|
const EPOCH_LENGTH = 7500;
|
||||||
@@ -112,12 +115,19 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
blob = new Buffer.concat([ blob, new Buffer(value.data, 'hex') ]);
|
blob = new Buffer.concat([ blob, new Buffer(value.data, 'hex') ]);
|
||||||
});
|
});
|
||||||
|
|
||||||
let sha3 = new SHA3.SHA3Hash(256);
|
|
||||||
let seedhash_buf = new Buffer(32, 0);
|
|
||||||
const epoch_number = Math.floor(rpcData.height / EPOCH_LENGTH);
|
const epoch_number = Math.floor(rpcData.height / EPOCH_LENGTH);
|
||||||
for (let i=0; i < epoch_number; i++) {
|
if (last_epoch_number !== epoch_number) {
|
||||||
seedhash_buf = sha3.update(seedhash_buf).digest();
|
let sha3 = new SHA3.SHA3Hash(256);
|
||||||
sha3.reset();
|
if (last_epoch_number && last_epoch_number + 1 === epoch_number) {
|
||||||
|
last_seedhash = sha3.update(last_seedhash).digest();
|
||||||
|
} else {
|
||||||
|
last_seedhash = new Buffer(32, 0);
|
||||||
|
for (let i=0; i < epoch_number; i++) {
|
||||||
|
last_seedhash = sha3.update(last_seedhash).digest();
|
||||||
|
sha3.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last_epoch_number = epoch_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const diff1 = 0x00000000ff000000000000000000000000000000000000000000000000000000;
|
const diff1 = 0x00000000ff000000000000000000000000000000000000000000000000000000;
|
||||||
@@ -125,8 +135,8 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
blocktemplate_blob: blob.toString('hex'),
|
blocktemplate_blob: blob.toString('hex'),
|
||||||
reserved_offset: offset1 + 4 /* txCoinbase.version */ + 1 /* txCoinbase.marker */ + 1 /* txCoinbase.flag */ + 1 /* txCoinbase.vinLen */,
|
reserved_offset: offset1 + 4 /* txCoinbase.version */ + 1 /* txCoinbase.vinLen */,
|
||||||
seed_hash: seedhash_buf.toString('hex'),
|
seed_hash: last_seedhash.toString('hex'),
|
||||||
difficulty: difficulty,
|
difficulty: difficulty,
|
||||||
height: rpcData.height,
|
height: rpcData.height,
|
||||||
rpc: rpcData,
|
rpc: rpcData,
|
||||||
|
|||||||
Reference in New Issue
Block a user