Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9021066354 | |||
| 7c139874ce | |||
| 58f8aeb67b | |||
| 2c6f6e6dd2 |
@@ -5,8 +5,7 @@ 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 promise = require('promise');
|
const fastMerkleRoot = require('merkle-lib/fastRoot');
|
||||||
const merklebitcoin = promise.denodeify(require('merkle-bitcoin'));
|
|
||||||
|
|
||||||
function scriptCompile(addrHash) {
|
function scriptCompile(addrHash) {
|
||||||
return bitcoin.script.compile([
|
return bitcoin.script.compile([
|
||||||
@@ -37,27 +36,32 @@ function txesHaveWitnessCommit(transactions) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hash256(buffer) {
|
function sha256(buffer) {
|
||||||
return crypto.createHash('sha256').update(buffer).digest();
|
return crypto.createHash('sha256').update(buffer).digest();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function hash256(buffer) {
|
||||||
|
return sha256(sha256(buffer));
|
||||||
|
};
|
||||||
|
|
||||||
function getMerkleRoot(transactions) {
|
function getMerkleRoot(transactions) {
|
||||||
// error
|
if (transactions.length === 0) return new Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
||||||
if (transactions.length === 0) return new Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
|
const forWitness = txesHaveWitnessCommit(transactions);
|
||||||
// coinbase tx only
|
const hashes = transactions.map(transaction => transaction.getHash(forWitness));
|
||||||
const txhash0 = transactions[0].getHash();
|
const rootHash = fastMerkleRoot(hashes, hash256);
|
||||||
if (transactions.length === 1) return txhash0;
|
return forWitness ? hash256(Buffer.concat([rootHash, transactions[0].ins[0].witness[0]])) : rootHash;
|
||||||
// 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;
|
let last_epoch_number;
|
||||||
let last_seed_hash;
|
let last_seed_hash;
|
||||||
const diff1 = 0x00000000ff000000000000000000000000000000000000000000000000000000;
|
|
||||||
|
module.exports.baseRavenDiff = function() {
|
||||||
|
return parseInt('0x00000000ff000000000000000000000000000000000000000000000000000000');
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.baseEthDiff = function() {
|
||||||
|
return parseInt('0x00000000ffff0000000000000000000000000000000000000000000000000000');
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
||||||
const poolAddrHash = bitcoin.address.fromBase58Check(poolAddress).hash;
|
const poolAddrHash = bitcoin.address.fromBase58Check(poolAddress).hash;
|
||||||
@@ -131,7 +135,7 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
last_epoch_number = epoch_number;
|
last_epoch_number = epoch_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const difficulty = parseFloat((diff1 / bignum(rpcData.target, 16).toNumber()).toFixed(9));
|
const difficulty = parseFloat((module.exports.baseRavenDiff() / bignum(rpcData.target, 16).toNumber()).toFixed(9));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
blocktemplate_blob: blob.toString('hex'),
|
blocktemplate_blob: blob.toString('hex'),
|
||||||
@@ -142,6 +146,7 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
difficulty: difficulty,
|
difficulty: difficulty,
|
||||||
height: rpcData.height,
|
height: rpcData.height,
|
||||||
bits: rpcData.bits,
|
bits: rpcData.bits,
|
||||||
|
prev_hash: rpcData.previousblockhash,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -161,7 +166,7 @@ function update_merkle_root_hash(blob_in, blob_out) {
|
|||||||
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(blobBuffer, header);
|
update_merkle_root_hash(blobBuffer, header);
|
||||||
return reverseBuffer(hash256(hash256(header)));
|
return reverseBuffer(hash256(header));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
|
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
|
||||||
@@ -174,4 +179,13 @@ module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhas
|
|||||||
module.exports.constructNewDeroBlob = function(blockTemplate, nonceBuff) {
|
module.exports.constructNewDeroBlob = function(blockTemplate, nonceBuff) {
|
||||||
nonceBuff.copy(blockTemplate, 39, 0, 4);
|
nonceBuff.copy(blockTemplate, 39, 0, 4);
|
||||||
return blockTemplate;
|
return blockTemplate;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.EthBlockTemplate = function(rpcData) {
|
||||||
|
const difficulty = parseFloat((module.exports.baseEth() / bignum(rpcData[2].lstrip("0x"), 16).toNumber()).toFixed(19));
|
||||||
|
return {
|
||||||
|
hash: rpcData[0].lstrip("0x"),
|
||||||
|
seed_hash: rpcData[1].lstrip("0x"),
|
||||||
|
difficulty: difficulty
|
||||||
|
};
|
||||||
};
|
};
|
||||||
+2
-3
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cryptoforknote-util",
|
"name": "cryptoforknote-util",
|
||||||
"version": "9.0.16",
|
"version": "9.1.0",
|
||||||
"main": "cryptoforknote-util",
|
"main": "cryptoforknote-util",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LucasJones",
|
"name": "LucasJones",
|
||||||
@@ -17,8 +17,7 @@
|
|||||||
"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",
|
||||||
|
|||||||
Reference in New Issue
Block a user