diff --git a/.gitignore b/.gitignore index d35bbf75a..1b18ef571 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ -.idea/ \ No newline at end of file +.idea/ +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md index 25c93c09b..8766f6710 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Features * ✓ __Quark__ (Quarkcoin [QRK]) * ✓ __X11__ (Darkcoin [DRK], Hirocoin, Limecoin) * ✓ __X13__ (MaruCoin, BoostCoin) +* ✓ __NIST5__ (Talkcoin) * ✓ __Keccak__ (Maxcoin [MAX], HelixCoin, CryptoMeth, Galleon, 365coin, Slothcoin, BitcointalkCoin) * ✓ __Skein__ (Skeincoin [SKC]) * ✓ __Groestl__ (Groestlcoin [GRS]) @@ -53,13 +54,13 @@ May be working (needs additional testing): * ? *Blake* (Blakecoin [BLC]) * ? *Fugue* (Fuguecoin [FC]) * ? *Qubit* (Qubitcoin [Q2C], Myriadcoin [MYR]) -* ? *Hefty1* (Heavycoin [HVC]) * ? *SHAvite-3* (INKcoin [INK]) +* ? *Sha1* (Sha1coin [SHA], Yaycoin [YAY]) Not working currently: * *Groestl* - for Myriadcoin * *Keccak* - for eCoin & Copperlark - +* *Hefty1* (Heavycoin [HVC]) Requirements @@ -83,7 +84,7 @@ npm update Create the configuration for your coin: Possible options for `algorithm`: *sha256, scrypt, scrypt-jane, scrypt-n, quark, x11, keccak, blake, -skein, groestl, fugue, shavite3, hefty1, or qubit*. +skein, groestl, fugue, shavite3, hefty1, qubit, or sha1*. ```javascript var myCoin = { @@ -276,7 +277,7 @@ var pool = Stratum.createPool({ } -}, function(ip, workerName, password, callback){ //stratum authorization function +}, function(ip, port , workerName, password, callback){ //stratum authorization function console.log("Authorize " + workerName + ":" + password + "@" + ip); callback({ error: null, diff --git a/lib/algoProperties.js b/lib/algoProperties.js index d2494c0de..7725ee622 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -26,6 +26,19 @@ var algos = module.exports = global.algos = { } } }, + 'scrypt-og': { + //Aiden settings + //Uncomment diff if you want to use hardcoded truncated diff + //diff: '0000ffff00000000000000000000000000000000000000000000000000000000', + multiplier: Math.pow(2, 16), + hash: function(coinConfig){ + var nValue = coinConfig.nValue || 64; + var rValue = coinConfig.rValue || 1; + return function(data){ + return multiHashing.scrypt(data,nValue,rValue); + } + } + }, 'scrypt-jane': { multiplier: Math.pow(2, 16), hash: function(coinConfig){ @@ -60,6 +73,13 @@ var algos = module.exports = global.algos = { } } }, + sha1: { + hash: function(){ + return function(){ + return multiHashing.sha1.apply(this, arguments); + } + } + }, x11: { hash: function(){ return function(){ @@ -74,6 +94,20 @@ var algos = module.exports = global.algos = { } } }, + x15: { + hash: function(){ + return function(){ + return multiHashing.x15.apply(this, arguments); + } + } + }, + nist5: { + hash: function(){ + return function(){ + return multiHashing.nist5.apply(this, arguments); + } + } + }, quark: { hash: function(){ return function(){ diff --git a/lib/blockTemplate.js b/lib/blockTemplate.js index 886cdd19b..89a3079c5 100644 --- a/lib/blockTemplate.js +++ b/lib/blockTemplate.js @@ -23,18 +23,21 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool function getTransactionBuffers(txs){ var txHashes = txs.map(function(tx){ + if (tx.txid !== undefined) { + return util.uint256BufferFromHash(tx.txid); + } return util.uint256BufferFromHash(tx.hash); }); return [null].concat(txHashes); } 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'); }) ) ); @@ -56,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); @@ -84,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'); @@ -107,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] : []) ]); }; @@ -136,4 +139,4 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool } return this.jobParams; }; -}; \ No newline at end of file +}; diff --git a/lib/jobManager.js b/lib/jobManager.js index b84d2805f..07087e0f8 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -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; @@ -90,6 +90,12 @@ var JobManager = module.exports = function JobManager(options){ return util.reverseBuffer(hashDigest.apply(this, arguments)); }; } + case 'scrypt-og': + if (options.coin.reward === 'POS') { + return function (d) { + return util.reverseBuffer(hashDigest.apply(this, arguments)); + }; + } case 'scrypt-jane': if (options.coin.reward === 'POS') { return function (d) { @@ -97,6 +103,7 @@ var JobManager = module.exports = function JobManager(options){ }; } case 'scrypt-n': + case 'sha1': return function (d) { return util.reverseBuffer(util.sha256d(d)); }; @@ -176,6 +183,18 @@ var JobManager = module.exports = function JobManager(options){ }); return {error: error, result: null}; }; + /*console.log("processShare - Stuff passed in", { + "jobId": jobId, + "previousDifficulty": previousDifficulty, + "difficulty": difficulty, + "extraNonce1": extraNonce1, + "extraNonce2": extraNonce2, + "nTime": nTime, + "nonce": nonce, + "ipAddress": ipAddress, + "port": port, + "workerName": workerName + });*/ var submitTime = Date.now() / 1000 | 0; @@ -205,9 +224,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); @@ -226,10 +244,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) diff --git a/lib/peer.js b/lib/peer.js index 5435c3b97..7ce61e0e0 100644 --- a/lib/peer.js +++ b/lib/peer.js @@ -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; @@ -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]); @@ -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; @@ -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'), @@ -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; } diff --git a/lib/pool.js b/lib/pool.js index 88abbbfc6..c12075a3d 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -119,7 +119,7 @@ var pool = module.exports = function pool(options, authorizeFn){ function OnBlockchainSynced(syncedCallback){ var checkSynced = function(displayNotSynced){ - _this.daemon.cmd('getblocktemplate', [], function(results){ + _this.daemon.cmd('getblocktemplate', [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ], "rules": [ "segwit" ]}], function(results){ var synced = results.every(function(r){ return !r.error || r.error.code !== -10; }); @@ -231,7 +231,7 @@ var pool = module.exports = function pool(options, authorizeFn){ } else{ rpcCommand = 'getblocktemplate'; - rpcArgs = [{'mode': 'submit', 'data': blockHex}]; + rpcArgs = [{'mode': 'submit', 'data': blockHex}]; // TODO: is mode submit even correct? } @@ -398,10 +398,12 @@ var pool = module.exports = function pool(options, authorizeFn){ return; } - if (isNaN(rpcResults.getdifficulty) && 'proof-of-stake' in rpcResults.getdifficulty) - options.coin.reward = 'POS'; - else - options.coin.reward = 'POW'; + if (!options.coin.reward) { + if (isNaN(rpcResults.getdifficulty) && 'proof-of-stake' in rpcResults.getdifficulty) + options.coin.reward = 'POS'; + else + options.coin.reward = 'POW'; + } /* POS coins must use the pubkey in coinbase transaction, and pubkey is @@ -564,9 +566,10 @@ var pool = module.exports = function pool(options, authorizeFn){ function GetBlockTemplate(callback){ _this.daemon.cmd('getblocktemplate', - [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}], + [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ], "rules": [ "segwit" ]}], function(result){ if (result.error){ + console.log("GetBlockTemplate()", result); emitErrorLog('getblocktemplate call failed for daemon instance ' + result.instance.index + ' with error ' + JSON.stringify(result.error)); callback(result.error); @@ -625,6 +628,7 @@ var pool = module.exports = function pool(options, authorizeFn){ Object.keys(origStratumClients).forEach(function (subId) { stratumClients.push({subId: subId, client: origStratumClients[subId]}); }); + //TODO: Think of a way to use API 8's async/await and promises to replace async lib async.filter( stratumClients, filterFn, @@ -644,7 +648,8 @@ var pool = module.exports = function pool(options, authorizeFn){ ); }); } - ) + ); + }; diff --git a/lib/stratum.js b/lib/stratum.js index 02f2728e8..9377e5eab 100644 --- a/lib/stratum.js +++ b/lib/stratum.js @@ -61,6 +61,8 @@ var StratumClient = function(options){ function handleMessage(message){ switch(message.method){ + //case 'mining.extranonce.subscribe': + // handleExtraNounceSubscribe(message); case 'mining.subscribe': handleSubscribe(message); break; @@ -84,6 +86,20 @@ var StratumClient = function(options){ } } + function handleExtraNounceSubscribe(message) { + // TODO: Apparently even trying to catch this message causes low difficulty shares to be submitted by client, more investigation needed + + // Support for mining.extranonce.subscribe is currently not written. The client sends this to let the server know + // its supported, not handeling it is ok. The client first sends mining.subscribe, then send the extranounce command. + // It expects a return of the extranounce value and size if supported. + //_this.emit('unknownStratumMethod', { method: "Currently " + message.method + " is not supported, sending not supported back to client." }); + sendJson({ + id: message.id, + result: false, + "error": [20, "Not supported.", null] + }); + } + function handleSubscribe(message){ if (! _this._authorized ) { _this.requestedSubscriptionBeforeAuth = true; diff --git a/lib/transactions.js b/lib/transactions.js index d8bc88044..dfbdf4427 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -1,121 +1,5 @@ var util = require('./util.js'); - -/* -function Transaction(params){ - - var version = params.version || 1, - inputs = params.inputs || [], - outputs = params.outputs || [], - lockTime = params.lockTime || 0; - - - this.toBuffer = function(){ - return Buffer.concat([ - binpack.packUInt32(version, 'little'), - util.varIntBuffer(inputs.length), - Buffer.concat(inputs.map(function(i){ return i.toBuffer() })), - util.varIntBuffer(outputs.length), - Buffer.concat(outputs.map(function(o){ return o.toBuffer() })), - binpack.packUInt32(lockTime, 'little') - ]); - }; - - this.inputs = inputs; - this.outputs = outputs; - -} - -function TransactionInput(params){ - - var prevOutHash = params.prevOutHash || 0, - prevOutIndex = params.prevOutIndex, - sigScript = params.sigScript, - sequence = params.sequence || 0; - - - this.toBuffer = function(){ - sigScriptBuffer = sigScript.toBuffer(); - console.log('scriptSig length ' + sigScriptBuffer.length); - return Buffer.concat([ - util.uint256BufferFromHash(prevOutHash), - binpack.packUInt32(prevOutIndex, 'little'), - util.varIntBuffer(sigScriptBuffer.length), - sigScriptBuffer, - binpack.packUInt32(sequence) - ]); - }; -} - -function TransactionOutput(params){ - - var value = params.value, - pkScriptBuffer = params.pkScriptBuffer; - - this.toBuffer = function(){ - return Buffer.concat([ - binpack.packInt64(value, 'little'), - util.varIntBuffer(pkScriptBuffer.length), - pkScriptBuffer - ]); - }; -} - -function ScriptSig(params){ - - var height = params.height, - flags = params.flags, - extraNoncePlaceholder = params.extraNoncePlaceholder; - - this.toBuffer = function(){ - - return Buffer.concat([ - util.serializeNumber(height), - new Buffer(flags, 'hex'), - util.serializeNumber(Date.now() / 1000 | 0), - new Buffer([extraNoncePlaceholder.length]), - extraNoncePlaceholder, - util.serializeString('/nodeStratum/') - ]); - } -}; - - -var Generation = exports.Generation = function Generation(rpcData, publicKey, extraNoncePlaceholder){ - - var tx = new Transaction({ - inputs: [new TransactionInput({ - prevOutIndex : Math.pow(2, 32) - 1, - sigScript : new ScriptSig({ - height : rpcData.height, - flags : rpcData.coinbaseaux.flags, - extraNoncePlaceholder : extraNoncePlaceholder - }) - })], - outputs: [new TransactionOutput({ - value : rpcData.coinbasevalue, - pkScriptBuffer : publicKey - })] - }); - - var txBuffer = tx.toBuffer(); - var epIndex = buffertools.indexOf(txBuffer, extraNoncePlaceholder); - var p1 = txBuffer.slice(0, epIndex); - var p2 = txBuffer.slice(epIndex + extraNoncePlaceholder.length); - - this.transaction = tx; - this.coinbase = [p1, p2]; - -}; -*/ - - -/* - ^^^^ The above code was a bit slow. The below code is uglier but optimized. - */ - - - /* This function creates the generation transaction that accepts the reward for successfully mining a new block. @@ -173,6 +57,7 @@ var generateOutputTransactions = function(poolRecipient, recipients, rpcData){ payeeReward = Math.ceil(reward / 5); } + reward -= payeeReward; rewardToPool -= payeeReward; @@ -203,7 +88,15 @@ var generateOutputTransactions = function(poolRecipient, recipients, rpcData){ util.varIntBuffer(poolRecipient.length), poolRecipient ])); - + + if (rpcData.default_witness_commitment !== undefined){ + witness_commitment = Buffer.from(rpcData.default_witness_commitment, 'hex'); + txOutputBuffers.unshift(Buffer.concat([ + util.packInt64LE(0), + util.varIntBuffer(witness_commitment.length), + witness_commitment + ])); + } return Buffer.concat([ util.varIntBuffer(txOutputBuffers.length), @@ -226,19 +119,19 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, r //Only required for POS coins var txTimestamp = reward === 'POS' ? - util.packUInt32LE(rpcData.curtime) : new Buffer([]); + util.packUInt32LE(rpcData.curtime) : Buffer.from([]); //For coins that support/require transaction comments var txComment = txMessages === true ? util.serializeString('https://github.com/zone117x/node-stratum') : - new Buffer([]); + Buffer.from([]); var scriptSigPart1 = Buffer.concat([ util.serializeNumber(rpcData.height), - new Buffer(rpcData.coinbaseaux.flags, 'hex'), + Buffer.from(rpcData.coinbaseaux.flags, 'hex'), util.serializeNumber(Date.now() / 1000 | 0), - new Buffer([extraNoncePlaceholder.length]) + Buffer.from([extraNoncePlaceholder.length]) ]); var scriptSigPart2 = util.serializeString('/nodeStratum/'); @@ -280,4 +173,4 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, r return [p1, p2]; -}; \ No newline at end of file +}; diff --git a/lib/util.js b/lib/util.js index 453939cf3..f233b480c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -7,7 +7,7 @@ var bignum = require('bignum'); exports.addressFromEx = function(exAddress, ripdm160Key){ try { var versionByte = exports.getVersionByte(exAddress); - var addrBase = Buffer.concat([versionByte, new Buffer(ripdm160Key, 'hex')]); + var addrBase = Buffer.concat([versionByte, Buffer.from(ripdm160Key, 'hex')]); var checksum = exports.sha256d(addrBase).slice(0, 4); var address = Buffer.concat([addrBase, checksum]); return base58.encode(address); @@ -34,14 +34,14 @@ exports.sha256d = function(buffer){ }; exports.reverseBuffer = function(buff){ - var reversed = new Buffer(buff.length); + var reversed = Buffer.alloc(buff.length); for (var i = buff.length - 1; i >= 0; i--) reversed[buff.length - i - 1] = buff[i]; return reversed; }; exports.reverseHex = function(hex){ - return exports.reverseBuffer(new Buffer(hex, 'hex')).toString('hex'); + return exports.reverseBuffer(Buffer.from(hex, 'hex')).toString('hex'); }; exports.reverseByteOrder = function(buff){ @@ -51,13 +51,13 @@ exports.reverseByteOrder = function(buff){ exports.uint256BufferFromHash = function(hex){ - var fromHex = new Buffer(hex, 'hex'); + var fromHex; - if (fromHex.length != 32){ - var empty = new Buffer(32); - empty.fill(0); - fromHex.copy(empty); - fromHex = empty; + if (hex != 0) { + fromHex = Buffer.from(hex, 'hex'); + } else { + fromHex = Buffer.alloc(32); + //fromHex.fill(0); This is not needed because it happens by default with .alloc } return exports.reverseBuffer(fromHex); @@ -74,21 +74,21 @@ Defined in bitcoin protocol here: */ exports.varIntBuffer = function(n){ if (n < 0xfd) - return new Buffer([n]); - else if (n < 0xffff){ - var buff = new Buffer(3); + return Buffer.from([n]); + else if (n <= 0xffff){ + var buff = Buffer.alloc(3); buff[0] = 0xfd; buff.writeUInt16LE(n, 1); return buff; } - else if (n < 0xffffffff){ - var buff = new Buffer(5); + else if (n <= 0xffffffff){ + var buff = Buffer.alloc(5); buff[0] = 0xfe; buff.writeUInt32LE(n, 1); return buff; } else{ - var buff = new Buffer(9); + var buff = Buffer.alloc(9); buff[0] = 0xff; exports.packUInt16LE(n).copy(buff, 1); return buff; @@ -96,7 +96,7 @@ exports.varIntBuffer = function(n){ }; exports.varStringBuffer = function(string){ - var strBuff = new Buffer(string); + var strBuff = Buffer.from(string); return Buffer.concat([exports.varIntBuffer(strBuff.length), strBuff]); }; @@ -108,33 +108,10 @@ Used to format height and date when putting into script signature: */ exports.serializeNumber = function(n){ - /* Old version that is bugged - if (n < 0xfd){ - var buff = new Buffer(2); - buff[0] = 0x1; - buff.writeUInt8(n, 1); - return buff; - } - else if (n <= 0xffff){ - var buff = new Buffer(4); - buff[0] = 0x3; - buff.writeUInt16LE(n, 1); - return buff; - } - else if (n <= 0xffffffff){ - var buff = new Buffer(5); - buff[0] = 0x4; - buff.writeUInt32LE(n, 1); - return buff; - } - else{ - return Buffer.concat([new Buffer([0x9]), binpack.packUInt64(n, 'little')]); - }*/ - - //New version from TheSeven - if (n >= 1 && n <= 16) return new Buffer([0x50 + n]); + //Version from TheSeven + if (n >= 1 && n <= 16) return Buffer.from([0x50 + n]); var l = 1; - var buff = new Buffer(9); + var buff = Buffer.alloc(9); while (n > 0x7f) { buff.writeUInt8(n & 0xff, l++); @@ -154,58 +131,58 @@ exports.serializeString = function(s){ if (s.length < 253) return Buffer.concat([ - new Buffer([s.length]), - new Buffer(s) + Buffer.from([s.length]), + Buffer.from(s) ]); else if (s.length < 0x10000) return Buffer.concat([ - new Buffer([253]), + Buffer.from([253]), exports.packUInt16LE(s.length), - new Buffer(s) + Buffer.from(s) ]); else if (s.length < 0x100000000) return Buffer.concat([ - new Buffer([254]), + Buffer.from([254]), exports.packUInt32LE(s.length), - new Buffer(s) + Buffer.from(s) ]); else return Buffer.concat([ - new Buffer([255]), + Buffer.from([255]), exports.packUInt16LE(s.length), - new Buffer(s) + Buffer.from(s) ]); }; exports.packUInt16LE = function(num){ - var buff = new Buffer(2); + var buff = Buffer.alloc(2); buff.writeUInt16LE(num, 0); return buff; }; exports.packInt32LE = function(num){ - var buff = new Buffer(4); + var buff = Buffer.alloc(4); buff.writeInt32LE(num, 0); return buff; }; exports.packInt32BE = function(num){ - var buff = new Buffer(4); + var buff = Buffer.alloc(4); buff.writeInt32BE(num, 0); return buff; }; exports.packUInt32LE = function(num){ - var buff = new Buffer(4); + var buff = Buffer.alloc(4); buff.writeUInt32LE(num, 0); return buff; }; exports.packUInt32BE = function(num){ - var buff = new Buffer(4); + var buff = Buffer.alloc(4); buff.writeUInt32BE(num, 0); return buff; }; exports.packInt64LE = function(num){ - var buff = new Buffer(8); + var buff = Buffer.alloc(8); buff.writeUInt32LE(num % Math.pow(2, 32), 0); buff.writeUInt32LE(Math.floor(num / Math.pow(2, 32)), 4); return buff; @@ -245,17 +222,17 @@ exports.pubkeyToScript = function(key){ console.error('Invalid pubkey: ' + key); throw new Error(); } - var pubkey = new Buffer(35); + var pubkey = Buffer.alloc(35); pubkey[0] = 0x21; pubkey[34] = 0xac; - new Buffer(key, 'hex').copy(pubkey, 1); + Buffer.from(key, 'hex').copy(pubkey, 1); return pubkey; }; exports.miningKeyToScript = function(key){ - var keyBuffer = new Buffer(key, 'hex'); - return Buffer.concat([new Buffer([0x76, 0xa9, 0x14]), keyBuffer, new Buffer([0x88, 0xac])]); + var keyBuffer = Buffer.from(key, 'hex'); + return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), keyBuffer, Buffer.from([0x88, 0xac])]); }; /* @@ -277,7 +254,7 @@ exports.addressToScript = function(addr){ var pubkey = decoded.slice(1,-4); - return Buffer.concat([new Buffer([0x76, 0xa9, 0x14]), pubkey, new Buffer([0x88, 0xac])]); + return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), pubkey, Buffer.from([0x88, 0xac])]); }; @@ -324,7 +301,7 @@ exports.shiftMax256Right = function(shiftRight){ } - return new Buffer(octets); + return Buffer.from(octets); }; @@ -332,9 +309,9 @@ exports.bufferToCompactBits = function(startingBuff){ var bigNum = bignum.fromBuffer(startingBuff); var buff = bigNum.toBuffer(); - buff = buff.readUInt8(0) > 0x7f ? Buffer.concat([new Buffer([0x00]), buff]) : buff; + buff = buff.readUInt8(0) > 0x7f ? Buffer.concat([Buffer.from([0x00]), buff]) : buff; - buff = Buffer.concat([new Buffer([buff.length]), buff]); + buff = Buffer.concat([Buffer.from([buff.length]), buff]); var compact = buff.slice(0, 4); return compact; }; @@ -358,14 +335,14 @@ exports.bignumFromBitsBuffer = function(bitsBuff){ }; exports.bignumFromBitsHex = function(bitsString){ - var bitsBuff = new Buffer(bitsString, 'hex'); + var bitsBuff = Buffer.from(bitsString, 'hex'); return exports.bignumFromBitsBuffer(bitsBuff); }; exports.convertBitsToBuff = function(bitsBuff){ var target = exports.bignumFromBitsBuffer(bitsBuff); var resultBuff = target.toBuffer(); - var buff256 = new Buffer(32); + var buff256 = Buffer.alloc(32); buff256.fill(0); resultBuff.copy(buff256, buff256.length - resultBuff.length); return buff256; @@ -373,4 +350,4 @@ exports.convertBitsToBuff = function(bitsBuff){ exports.getTruncatedDiff = function(shift){ return exports.convertBitsToBuff(exports.bufferToCompactBits(exports.shiftMax256Right(shift))); -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 6b195a55e..95cab00d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stratum-pool", - "version": "0.1.6", + "version": "0.1.9", "description": "High performance Stratum poolserver in Node.js", "keywords": [ "stratum", @@ -28,10 +28,10 @@ "url": "https://github.com/zone117x/node-stratum-pool.git" }, "dependencies": { - "multi-hashing": "git://github.com/zone117x/node-multi-hashing.git", - "bignum": "*", - "base58-native": "*", - "async": "*" + "async": "^2.5.0", + "base58-native": "^0.1.4", + "bignum": "^0.12.5", + "multi-hashing": "git://github.com/vagabondan/node-multi-hashing.git" }, "engines": { "node": ">=0.10"