Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There a lot of thing has been update by krisklosterman #128

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.idea/
.idea/
.vscode/
9 changes: 9 additions & 0 deletions lib/algoProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ var algos = module.exports = global.algos = {
}
}
},
'equihash': {
multiplier: 1,
diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'),
hash: function(){
return function(){
return multiHashing.equihash(this, arguments);
}
}
},
'scrypt': {
//Uncomment diff if you want to use hardcoded truncated diff
//diff: '0000ffff00000000000000000000000000000000000000000000000000000000',
Expand Down
12 changes: 6 additions & 6 deletions lib/blockTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool
}

function getVoteData(){
if (!rpcData.masternode_payments) return new Buffer([]);
if (!rpcData.masternode_payments) return Buffer.from([]);

return Buffer.concat(
[util.varIntBuffer(rpcData.votes.length)].concat(
rpcData.votes.map(function (vt) {
return new Buffer(vt, 'hex');
return Buffer.from(vt, 'hex');
})
)
);
Expand All @@ -59,9 +59,9 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool



this.prevHashReversed = util.reverseByteOrder(new Buffer(rpcData.previousblockhash, 'hex')).toString('hex');
this.prevHashReversed = util.reverseByteOrder(Buffer.from(rpcData.previousblockhash, 'hex')).toString('hex');
this.transactionData = Buffer.concat(rpcData.transactions.map(function(tx){
return new Buffer(tx.data, 'hex');
return Buffer.from(tx.data, 'hex');
}));
this.merkleTree = new merkleTree(getTransactionBuffers(rpcData.transactions));
this.merkleBranch = getMerkleHashes(this.merkleTree.steps);
Expand All @@ -87,7 +87,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool
//https://en.bitcoin.it/wiki/Protocol_specification#Block_Headers
this.serializeHeader = function(merkleRoot, nTime, nonce){

var header = new Buffer(80);
var header = Buffer.alloc(80);
var position = 0;
header.write(nonce, position, 4, 'hex');
header.write(rpcData.bits, position += 4, 4, 'hex');
Expand All @@ -110,7 +110,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool
getVoteData(),

//POS coins require a zero byte appended to block which the daemon replaces with the signature
new Buffer(reward === 'POS' ? [0] : [])
Buffer.from(reward === 'POS' ? [0] : [])
]);
};

Expand Down
48 changes: 36 additions & 12 deletions lib/jobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var ExtraNonceCounter = function(configInstanceId){
};

//Unique job per new block template
var JobCounter = function(){
var JobCounter = () => {
var counter = 0;

this.next = function(){
Expand Down Expand Up @@ -58,7 +58,7 @@ var JobManager = module.exports = function JobManager(options){
//public members

this.extraNonceCounter = new ExtraNonceCounter(options.instanceId);
this.extraNoncePlaceholder = new Buffer('f000000ff111111f', 'hex');
this.extraNoncePlaceholder = Buffer.from('f000000ff111111f', 'hex');
this.extraNonce2Size = this.extraNoncePlaceholder.length - this.extraNonceCounter.size;

this.currentJob;
Expand All @@ -82,33 +82,37 @@ var JobManager = module.exports = function JobManager(options){
})();


var blockHasher = (function () {
var blockHasher = (() => {
switch (options.coin.algorithm) {
case 'scrypt':
if (options.coin.reward === 'POS') {
return function (d) {
return (d) => {
return util.reverseBuffer(hashDigest.apply(this, arguments));
};
}
case 'scrypt-og':
if (options.coin.reward === 'POS') {
return function (d) {
return (d) => {
return util.reverseBuffer(hashDigest.apply(this, arguments));
};
}
case 'scrypt-jane':
if (options.coin.reward === 'POS') {
return function (d) {
return (d) => {
return util.reverseBuffer(hashDigest.apply(this, arguments));
};
}
case 'scrypt-n':
case 'sha1':
return function (d) {
return (d) => {
return util.reverseBuffer(util.sha256d(d));
};
case 'equihash':
return (d) => {
return util.reverseBuffer(util.sha256(d));
};
default:
return function () {
return () => {
return util.reverseBuffer(hashDigest.apply(this, arguments));
};
}
Expand Down Expand Up @@ -183,7 +187,7 @@ var JobManager = module.exports = function JobManager(options){
});
return {error: error, result: null};
};

var submitTime = Date.now() / 1000 | 0;

if (extraNonce2.length / 2 !== _this.extraNonce2Size)
Expand Down Expand Up @@ -212,9 +216,8 @@ var JobManager = module.exports = function JobManager(options){
return shareError([22, 'duplicate share']);
}


var extraNonce1Buffer = new Buffer(extraNonce1, 'hex');
var extraNonce2Buffer = new Buffer(extraNonce2, 'hex');
var extraNonce1Buffer = Buffer.from(extraNonce1, 'hex');
var extraNonce2Buffer = Buffer.from(extraNonce2, 'hex');

var coinbaseBuffer = job.serializeCoinbase(extraNonce1Buffer, extraNonce2Buffer);
var coinbaseHash = coinbaseHasher(coinbaseBuffer);
Expand All @@ -233,10 +236,31 @@ var JobManager = module.exports = function JobManager(options){

var blockDiffAdjusted = job.difficulty * shareMultiplier;

/*console.log("processShare - Stuff calculated", {
"extraNonce1Buffer": extraNonce1Buffer,
"extraNonce2Buffer": extraNonce2Buffer,
"coinbaseBuffer": coinbaseBuffer,
"coinbaseHash": coinbaseHash,
"merkleRoot": merkleRoot,
"headerBuffer": headerBuffer,
"headerHash": headerHash,
"headerBigNum": headerBigNum,
"shareDiff": shareDiff,
"blockDiffAdjusted": blockDiffAdjusted
});*/

/*console.log("processShare - Globals", {
"job.target": job.target
});*/

//Check if share is a block candidate (matched network difficulty)
if (job.target.ge(headerBigNum)){
blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex');
blockHash = blockHasher(headerBuffer, nTime).toString('hex');
/*console.log("processShare - Block Candidate", {
"blockHex": blockHex,
"blockHash": blockHash
});*/
}
else {
if (options.emitInvalidBlockHashes)
Expand Down
18 changes: 9 additions & 9 deletions lib/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var util = require('./util.js');


var fixedLenStringBuffer = function(s, len) {
var buff = new Buffer(len);
var buff = Buffer.alloc(len);
buff.fill(0);
buff.write(s);
return buff;
Expand All @@ -26,7 +26,7 @@ var commandStringBuffer = function (s) {
- callback returns 1) data buffer and 2) lopped/over-read data */
var readFlowingBytes = function (stream, amount, preRead, callback) {

var buff = preRead ? preRead : new Buffer([]);
var buff = preRead ? preRead : Buffer.from([]);

var readData = function (data) {
buff = Buffer.concat([buff, data]);
Expand All @@ -39,14 +39,14 @@ var readFlowingBytes = function (stream, amount, preRead, callback) {
stream.once('data', readData);
};

readData(new Buffer([]));
readData(Buffer.from([]));
};

var Peer = module.exports = function (options) {

var _this = this;
var client;
var magic = new Buffer(options.testnet ? options.coin.peerMagicTestnet : options.coin.peerMagic, 'hex');
var magic = Buffer.from(options.testnet ? options.coin.peerMagicTestnet : options.coin.peerMagic, 'hex');
var magicInt = magic.readUInt32LE(0);
var verack = false;
var validConnectionConfig = true;
Expand All @@ -58,14 +58,14 @@ var Peer = module.exports = function (options) {
block: 2
};

var networkServices = new Buffer('0100000000000000', 'hex'); //NODE_NETWORK services (value 1 packed as uint64)
var emptyNetAddress = new Buffer('010000000000000000000000000000000000ffff000000000000', 'hex');
var networkServices = Buffer.from('0100000000000000', 'hex'); //NODE_NETWORK services (value 1 packed as uint64)
var emptyNetAddress = Buffer.from('010000000000000000000000000000000000ffff000000000000', 'hex');
var userAgent = util.varStringBuffer('/node-stratum/');
var blockStartHeight = new Buffer('00000000', 'hex'); //block start_height, can be empty
var blockStartHeight = Buffer.from('00000000', 'hex'); //block start_height, can be empty

//If protocol version is new enough, add do not relay transactions flag byte, outlined in BIP37
//https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki#extensions-to-existing-messages
var relayTransactions = options.p2p.disableTransactions === true ? new Buffer([false]) : new Buffer([]);
var relayTransactions = options.p2p.disableTransactions === true ? Buffer.from([false]) : Buffer.from([]);

var commands = {
version: commandStringBuffer('version'),
Expand Down Expand Up @@ -127,7 +127,7 @@ var Peer = module.exports = function (options) {
if (header.readUInt32LE(0) === magicInt) {
beginReadingMessage(header);
} else {
beginReadingMessage(new Buffer([]));
beginReadingMessage(Buffer.from([]));
}
return;
}
Expand Down
Loading