Another fix for serializing height in coinbase. and removed old code
This commit is contained in:
parent
5328250d06
commit
3e77791509
|
@ -108,9 +108,9 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
|
|||
this.generationTransaction[0].toString('hex'),
|
||||
this.generationTransaction[1].toString('hex'),
|
||||
this.merkleBranch,
|
||||
util.packInt32BE(this.rpcData.version).toString('hex'),//binpack.packInt32(this.rpcData.version, 'big').toString('hex'),
|
||||
util.packInt32BE(this.rpcData.version).toString('hex'),
|
||||
this.rpcData.bits,
|
||||
util.packUInt32BE(this.rpcData.curtime).toString('hex'), //binpack.packUInt32(this.rpcData.curtime, 'big').toString('hex'),
|
||||
util.packUInt32BE(this.rpcData.curtime).toString('hex'),
|
||||
true
|
||||
];
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ var blockTemplate = require('./blockTemplate.js');
|
|||
var ExtraNonceCounter = function(){
|
||||
var instanceId = 31;
|
||||
var counter = instanceId << 27;
|
||||
var size = util.packUInt32BE(Math.abs(counter)).length; //binpack.packUInt32(counter, 'big').length;
|
||||
var size = util.packUInt32BE(Math.abs(counter)).length;
|
||||
|
||||
this.next = function(){
|
||||
var extraNonce = util.packUInt32BE(Math.abs(counter++));//binpack.packUInt32(counter++, 'big');
|
||||
var extraNonce = util.packUInt32BE(Math.abs(counter++));
|
||||
return extraNonce.toString('hex');
|
||||
};
|
||||
this.size = function(){
|
||||
|
|
|
@ -11,7 +11,6 @@ var SubscriptionCounter = function(){
|
|||
next: function(){
|
||||
count++;
|
||||
if (Number.MAX_VALUE === count) count = 0;
|
||||
//return padding + binpack.packUInt64(count, 'big').toString('hex');
|
||||
return padding + util.packInt64LE(count).toString('hex');
|
||||
}
|
||||
};
|
||||
|
|
|
@ -128,137 +128,6 @@ see: https://en.bitcoin.it/wiki/Protocol_specification#tx
|
|||
|
||||
|
||||
|
||||
//Replaced binpack with native utils
|
||||
/*
|
||||
exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, reward, txMessages){
|
||||
|
||||
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'),
|
||||
util.serializeNumber(Date.now() / 1000 | 0),
|
||||
new Buffer([extraNoncePlaceholder.length])
|
||||
]);
|
||||
|
||||
var scriptSigPart2 = util.serializeString('/nodeStratum/');
|
||||
|
||||
|
||||
var p1 = Buffer.concat([
|
||||
binpack.packUInt32(txVersion, 'little'),
|
||||
reward === 'POS' ? binpack.packUInt32(rpcData.curtime, 'little') : new Buffer([]),
|
||||
util.varIntBuffer(txInputsCount),
|
||||
|
||||
//transaction input
|
||||
util.uint256BufferFromHash(txInPrevOutHash),
|
||||
binpack.packUInt32(txInPrevOutIndex, 'little'),
|
||||
util.varIntBuffer(scriptSigPart1.length + extraNoncePlaceholder.length + scriptSigPart2.length),
|
||||
scriptSigPart1
|
||||
]);
|
||||
|
||||
var p2 = Buffer.concat([
|
||||
scriptSigPart2,
|
||||
binpack.packUInt32(txInSequence),
|
||||
//end transaction input
|
||||
|
||||
util.varIntBuffer(txOutputsCount),
|
||||
|
||||
//transaction output
|
||||
binpack.packInt64(rpcData.coinbasevalue, 'little'),
|
||||
util.varIntBuffer(publicKey.length),
|
||||
publicKey,
|
||||
//end transaction ouput
|
||||
|
||||
binpack.packUInt32(txLockTime, 'little'),
|
||||
txComment
|
||||
]);
|
||||
|
||||
return [p1, p2];
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
//Utilize bufferput
|
||||
/*
|
||||
exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, reward, txMessages){
|
||||
|
||||
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 encodedHeight = new Buffer(4);
|
||||
encodedHeight.writeUInt32LE(rpcData.height << 8 | 3, 0);
|
||||
|
||||
|
||||
var scriptSigPart1 = Buffer.concat([
|
||||
encodedHeight,
|
||||
new Buffer(rpcData.coinbaseaux.flags, 'hex'),
|
||||
util.serializeNumber(Date.now() / 1000 | 0),
|
||||
new Buffer([extraNoncePlaceholder.length])
|
||||
]);
|
||||
|
||||
var scriptSigPart2 = util.serializeString('/nodeStratum/');
|
||||
|
||||
|
||||
var p1 = Buffer.concat([
|
||||
util.packUInt32LE(txVersion),//binpack.packUInt32(txVersion, 'little'),
|
||||
|
||||
//reward === 'POS' ? binpack.packUInt32(rpcData.curtime, 'little') : new Buffer([]),
|
||||
reward === 'POS' ? util.packUInt32LE(rpcData.curtime) : new Buffer([]),
|
||||
|
||||
util.varIntBuffer(txInputsCount),
|
||||
|
||||
//transaction input
|
||||
util.uint256BufferFromHash(txInPrevOutHash),
|
||||
util.packUInt32LE(txInPrevOutIndex), //binpack.packUInt32(txInPrevOutIndex, 'little'),
|
||||
util.varIntBuffer(scriptSigPart1.length + extraNoncePlaceholder.length + scriptSigPart2.length),
|
||||
scriptSigPart1
|
||||
]);
|
||||
|
||||
var p2 = Buffer.concat([
|
||||
scriptSigPart2,
|
||||
util.packUInt32LE, //binpack.packUInt32(txInSequence),
|
||||
//end transaction input
|
||||
|
||||
util.varIntBuffer(txOutputsCount),
|
||||
|
||||
//transaction output
|
||||
util.packInt64LE(rpcData.coinbasevalue), //binpack.packInt64(rpcData.coinbasevalue, 'little'),
|
||||
util.varIntBuffer(publicKey.length),
|
||||
publicKey,
|
||||
//end transaction ouput
|
||||
|
||||
util.packUInt32LE(txLockTime), //binpack.packUInt32(txLockTime, 'little'),
|
||||
txComment
|
||||
]);
|
||||
|
||||
return [p1, p2];
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, reward, txMessages){
|
||||
|
||||
var txInputsCount = 1;
|
||||
|
|
10
lib/util.js
10
lib/util.js
|
@ -91,7 +91,7 @@ exports.varIntBuffer = function(n){
|
|||
else{
|
||||
var buff = new Buffer(9);
|
||||
buff[0] = 0xff;
|
||||
exports.packUInt16LE(n).copy(buff, 1);//binpack.packUInt64(n, 'little').copy(buff, 1);
|
||||
exports.packUInt16LE(n).copy(buff, 1);
|
||||
return buff;
|
||||
}
|
||||
};
|
||||
|
@ -131,7 +131,7 @@ exports.serializeNumber = function(n){
|
|||
//New version from TheSeven
|
||||
var l = 1;
|
||||
var buff = new Buffer(9);
|
||||
while (n > 0xff)
|
||||
while (n > 0x7f)
|
||||
{
|
||||
buff.writeUInt8(n & 0xff, l++);
|
||||
n >>= 8;
|
||||
|
@ -156,19 +156,19 @@ exports.serializeString = function(s){
|
|||
else if (s.length < 0x10000)
|
||||
return Buffer.concat([
|
||||
new Buffer([253]),
|
||||
exports.packUInt16LE(s.length),//binpack.packUInt16(s.length, 'little'),
|
||||
exports.packUInt16LE(s.length),
|
||||
new Buffer(s)
|
||||
]);
|
||||
else if (s.length < 0x100000000)
|
||||
return Buffer.concat([
|
||||
new Buffer([254]),
|
||||
exports.packUInt32LE(s.length),//binpack.packUInt32(s.length, 'little'),
|
||||
exports.packUInt32LE(s.length),
|
||||
new Buffer(s)
|
||||
]);
|
||||
else
|
||||
return Buffer.concat([
|
||||
new Buffer([255]),
|
||||
exports.packUInt16LE(s.length),//binpack.packUInt64(s.length),
|
||||
exports.packUInt16LE(s.length),
|
||||
new Buffer(s)
|
||||
]);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue