Added POS and transaction comment support
This commit is contained in:
parent
f4d38e12bb
commit
4691df0dc5
@ -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] : [])
|
||||
]);
|
||||
};
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user