diff --git a/lib/blockTemplate.js b/lib/blockTemplate.js index eda9c96..f2236f2 100644 --- a/lib/blockTemplate.js +++ b/lib/blockTemplate.js @@ -11,7 +11,7 @@ var util = require('./util.js'); * The BlockTemplate class holds a single job. * and provides several methods to validate and submit it to the daemon coin **/ -var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publicKey, extraNoncePlaceholder){ +var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publicKey, extraNoncePlaceholder, reward){ //private members @@ -52,7 +52,9 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ this.generationTransaction = transactions.CreateGeneration(//new transactions.Generation( rpcData, publicKey, - extraNoncePlaceholder + extraNoncePlaceholder, + reward, + txMessages ); this.serializeCoinbase = function(extraNonce1, extraNonce2){ @@ -64,6 +66,8 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ ]); }; + + //https://en.bitcoin.it/wiki/Protocol_specification#Block_Headers this.serializeHeader = function(merkleRoot, nTime, nonce){ var header = new Buffer(80); @@ -75,7 +79,6 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ header.write(rpcData.previousblockhash, position += 32, 32, 'hex'); header.writeUInt32BE(rpcData.version, position + 32); var header = util.reverseBuffer(header); - return header; }; @@ -84,7 +87,8 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ header, util.varIntBuffer(this.rpcData.transactions.length + 1), coinbase, - this.transactionData + this.transactionData, + new Buffer(reward === 'POS' ? [0] : []) ]); }; diff --git a/lib/jobManager.js b/lib/jobManager.js index d0d7233..608eca6 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -116,7 +116,16 @@ var JobManager = module.exports = function JobManager(options){ this.processTemplate = function(rpcData, publicKey){ if (CheckNewIfNewBlock(rpcData.previousblockhash)){ - var tmpBlockTemplate = new blockTemplate(jobCounter.next(), rpcData, publicKey, _this.extraNoncePlaceholder); + + var tmpBlockTemplate = new blockTemplate( + jobCounter.next(), + rpcData, + publicKey, + _this.extraNoncePlaceholder, + options.reward, + options.txMessages + ); + this.currentJob = tmpBlockTemplate; _this.emit('newBlock', tmpBlockTemplate); } diff --git a/lib/transactions.js b/lib/transactions.js index 0770bc2..c3e31be 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -129,15 +129,21 @@ For some (probably outdated and incorrect) documentation about whats kinda going see: https://en.bitcoin.it/wiki/Protocol_specification#tx */ -exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder){ +exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, reward, txMessages){ - var txVersion = 1; + var txInputsCount = 1; + var txOutputsCount = 1; + var txVersion = txMessages === true ? 2 : 1; var txLockTime = 0; var txInPrevOutHash = 0; var txInPrevOutIndex = Math.pow(2, 32) - 1; var txInSequence = 0; + var txComment = txMessages === true ? + util.serializeString('https://github.com/zone117x/node-stratum') : + new Buffer([]); + var scriptSigPart1 = Buffer.concat([ util.serializeNumber(rpcData.height), new Buffer(rpcData.coinbaseaux.flags, 'hex'), @@ -150,7 +156,8 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder){ var p1 = Buffer.concat([ binpack.packUInt32(txVersion, 'little'), - util.varIntBuffer(1), + reward === 'POS' ? binpack.packUInt32(rpcData.curtime, 'little') : new Buffer([]), + util.varIntBuffer(txInputsCount), //transaction input util.uint256BufferFromHash(txInPrevOutHash), @@ -164,7 +171,7 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder){ binpack.packUInt32(txInSequence), //end transaction input - util.varIntBuffer(1), + util.varIntBuffer(txOutputsCount), //transaction output binpack.packInt64(rpcData.coinbasevalue, 'little'), @@ -172,7 +179,8 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder){ publicKey, //end transaction ouput - binpack.packUInt32(txLockTime, 'little') + binpack.packUInt32(txLockTime, 'little'), + txComment ]); return [p1, p2];