Added POS and transaction comment support

This commit is contained in:
Matt 2014-02-13 13:59:47 -07:00
parent f4d38e12bb
commit 4691df0dc5
3 changed files with 31 additions and 10 deletions

View File

@ -11,7 +11,7 @@ var util = require('./util.js');
* The BlockTemplate class holds a single job. * The BlockTemplate class holds a single job.
* and provides several methods to validate and submit it to the daemon coin * 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 //private members
@ -52,7 +52,9 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
this.generationTransaction = transactions.CreateGeneration(//new transactions.Generation( this.generationTransaction = transactions.CreateGeneration(//new transactions.Generation(
rpcData, rpcData,
publicKey, publicKey,
extraNoncePlaceholder extraNoncePlaceholder,
reward,
txMessages
); );
this.serializeCoinbase = function(extraNonce1, extraNonce2){ 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){ this.serializeHeader = function(merkleRoot, nTime, nonce){
var header = new Buffer(80); 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.write(rpcData.previousblockhash, position += 32, 32, 'hex');
header.writeUInt32BE(rpcData.version, position + 32); header.writeUInt32BE(rpcData.version, position + 32);
var header = util.reverseBuffer(header); var header = util.reverseBuffer(header);
return header; return header;
}; };
@ -84,7 +87,8 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
header, header,
util.varIntBuffer(this.rpcData.transactions.length + 1), util.varIntBuffer(this.rpcData.transactions.length + 1),
coinbase, coinbase,
this.transactionData this.transactionData,
new Buffer(reward === 'POS' ? [0] : [])
]); ]);
}; };

View File

@ -116,7 +116,16 @@ var JobManager = module.exports = function JobManager(options){
this.processTemplate = function(rpcData, publicKey){ this.processTemplate = function(rpcData, publicKey){
if (CheckNewIfNewBlock(rpcData.previousblockhash)){ 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.currentJob = tmpBlockTemplate;
_this.emit('newBlock', tmpBlockTemplate); _this.emit('newBlock', tmpBlockTemplate);
} }

View File

@ -129,15 +129,21 @@ For some (probably outdated and incorrect) documentation about whats kinda going
see: https://en.bitcoin.it/wiki/Protocol_specification#tx 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 txLockTime = 0;
var txInPrevOutHash = 0; var txInPrevOutHash = 0;
var txInPrevOutIndex = Math.pow(2, 32) - 1; var txInPrevOutIndex = Math.pow(2, 32) - 1;
var txInSequence = 0; var txInSequence = 0;
var txComment = txMessages === true ?
util.serializeString('https://github.com/zone117x/node-stratum') :
new Buffer([]);
var scriptSigPart1 = Buffer.concat([ var scriptSigPart1 = Buffer.concat([
util.serializeNumber(rpcData.height), util.serializeNumber(rpcData.height),
new Buffer(rpcData.coinbaseaux.flags, 'hex'), new Buffer(rpcData.coinbaseaux.flags, 'hex'),
@ -150,7 +156,8 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder){
var p1 = Buffer.concat([ var p1 = Buffer.concat([
binpack.packUInt32(txVersion, 'little'), binpack.packUInt32(txVersion, 'little'),
util.varIntBuffer(1), reward === 'POS' ? binpack.packUInt32(rpcData.curtime, 'little') : new Buffer([]),
util.varIntBuffer(txInputsCount),
//transaction input //transaction input
util.uint256BufferFromHash(txInPrevOutHash), util.uint256BufferFromHash(txInPrevOutHash),
@ -164,7 +171,7 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder){
binpack.packUInt32(txInSequence), binpack.packUInt32(txInSequence),
//end transaction input //end transaction input
util.varIntBuffer(1), util.varIntBuffer(txOutputsCount),
//transaction output //transaction output
binpack.packInt64(rpcData.coinbasevalue, 'little'), binpack.packInt64(rpcData.coinbasevalue, 'little'),
@ -172,7 +179,8 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder){
publicKey, publicKey,
//end transaction ouput //end transaction ouput
binpack.packUInt32(txLockTime, 'little') binpack.packUInt32(txLockTime, 'little'),
txComment
]); ]);
return [p1, p2]; return [p1, p2];