updated
This commit is contained in:
parent
3b7c7dff29
commit
5f43747ffb
@ -13,6 +13,7 @@ Features (mostly untested)
|
||||
* Block template / job manager
|
||||
|
||||
#### To do
|
||||
* Optimized generation transaction building
|
||||
* Integrate with PostgreSQL database
|
||||
* Handle share submissions
|
||||
* Payment processing module
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
var binpack = require('binpack');
|
||||
|
||||
var merkleTree = require('./merkleTree.js');
|
||||
var coinbase = require('./coinbase.js');
|
||||
var transactions = require('./transactions.js');
|
||||
var util = require('./util.js');
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, addr
|
||||
this.jobId = jobId;
|
||||
this.merkleTree = new merkleTree(getTransactionBuffers(rpcData.transactions));
|
||||
this.merkleBranch = getMerkleHashes(this.merkleTree.steps);
|
||||
this.coinbase = new coinbase.GenerationTransaction(
|
||||
this.coinbase = new transactions.Generation(
|
||||
rpcData.coinbasevalue,
|
||||
rpcData.coinbaseaux.flags,
|
||||
rpcData.height,
|
||||
|
||||
158
coinbase.js
158
coinbase.js
@ -1,158 +0,0 @@
|
||||
/*
|
||||
|
||||
Ported from https://github.com/slush0/stratum-mining
|
||||
|
||||
*/
|
||||
|
||||
|
||||
var binpack = require('binpack');
|
||||
var buffertools = require('buffertools');
|
||||
|
||||
var util = require('./util.js');
|
||||
|
||||
|
||||
function COutPoint(){
|
||||
this.hash = 0;
|
||||
this.n = 0;
|
||||
}
|
||||
COutPoint.prototype = {
|
||||
deserialize: function(f){
|
||||
this.hash = util.hexFromReversedBuffer(f.read(32));
|
||||
this.n = f.read(4).readUInt32LE(0);
|
||||
},
|
||||
serialize: function(){
|
||||
return Buffer.concat([
|
||||
util.uint256BufferFromHash(this.hash),
|
||||
binpack.packUInt32(this.n, 'little')
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function CTxIn(){
|
||||
this.prevout = new COutPoint();
|
||||
this.scriptSig = "";
|
||||
this.nSequence = 0;
|
||||
}
|
||||
CTxIn.prototype = {
|
||||
deserialize: function(f){
|
||||
this.prevout = new COutPoint();
|
||||
this.prevout.deserialize(f);
|
||||
this.scriptSig = util.deser_string(f);
|
||||
this.nSequence = f.read(4).readUInt32LE(0);
|
||||
},
|
||||
serialize: function(){
|
||||
return Buffer.concat([
|
||||
this.prevout.serialize(),
|
||||
util.ser_string(this.scriptSig),
|
||||
binpack.packUInt32(this.nSequence, 'little')
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function CTxOut(){
|
||||
this.nValue = 0;
|
||||
this.scriptPubKey = '';
|
||||
}
|
||||
CTxOut.prototype = {
|
||||
deserialize: function(f){
|
||||
this.nValue = f.read(8).readInt64LE(0);
|
||||
this.scriptPubKey = util.deser_string(f);
|
||||
},
|
||||
serialize: function(){
|
||||
return Buffer.concat([
|
||||
binpack.packInt64(this.nValue, 'little'),
|
||||
util.ser_string(this.scriptPubKey)
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function CTransaction(){
|
||||
this.nVersion = 1;
|
||||
this.vin = [];
|
||||
this.vout = [];
|
||||
this.nLockTime = 0;
|
||||
this.sha256 = null;
|
||||
};
|
||||
CTransaction.prototype = {
|
||||
deserialize: function(f){
|
||||
util.makeBufferReadable(f);
|
||||
this.nVersion = f.read(4).readInt32LE(0);
|
||||
this.vin = util.deser_vector(f, CTxIn);
|
||||
this.vout = util.deser_vector(f, CTxOut);
|
||||
this.nLockTime = r.read(4).readUInt32LE(0);
|
||||
this.sha256 = null;
|
||||
},
|
||||
serialize: function(){
|
||||
return Buffer.concat([
|
||||
binpack.packInt32(this.nVersion, 'little'),
|
||||
util.ser_vector(this.vin),
|
||||
util.ser_vector(this.vout),
|
||||
binpack.packUInt32(this.nLockTime, 'little')
|
||||
]);
|
||||
}
|
||||
};
|
||||
exports.CTransaction = CTransaction;
|
||||
|
||||
|
||||
var extranonce_placeholder = new Buffer('f000000ff111111f', 'hex');
|
||||
exports.extranonce_size = extranonce_placeholder.length;
|
||||
|
||||
|
||||
function GenerationTransaction(coinbaseValue, coinbaseAuxFlags, height, address){
|
||||
var CTrans = new CTransaction();
|
||||
|
||||
var tx_in = new CTxIn();
|
||||
tx_in.prevout.hash = 0;
|
||||
tx_in.prevout.n = Math.pow(2, 32) - 1;
|
||||
tx_in._scriptSig_template = [
|
||||
Buffer.concat([
|
||||
util.serializeNumber(height),
|
||||
new Buffer(coinbaseAuxFlags, 'hex'),
|
||||
util.serializeNumber(Date.now() / 1000 | 0),
|
||||
new Buffer([exports.extranonce_size])
|
||||
]),
|
||||
util.ser_string('/stratum/')
|
||||
];
|
||||
|
||||
tx_in.scriptSig = Buffer.concat([
|
||||
tx_in._scriptSig_template[0],
|
||||
extranonce_placeholder,
|
||||
tx_in._scriptSig_template[1]
|
||||
]);
|
||||
|
||||
var tx_out = new CTxOut();
|
||||
tx_out.nValue = coinbaseValue;
|
||||
tx_out.scriptPubKey = util.script_to_address(address);
|
||||
|
||||
CTrans.vin.push(tx_in);
|
||||
CTrans.vout.push(tx_out);
|
||||
|
||||
var cTransBin = CTrans.serialize();
|
||||
var epIndex = buffertools.indexOf(cTransBin, extranonce_placeholder);
|
||||
var p1 = cTransBin.slice(0, epIndex);
|
||||
var p2 = cTransBin.slice(epIndex + extranonce_placeholder.length);
|
||||
|
||||
this.tx = CTrans;
|
||||
this.serialized = [p1, p2];
|
||||
}
|
||||
GenerationTransaction.prototype = {
|
||||
setExtraNonce: function(extraNonce){
|
||||
if (extraNonce.length != exports.extranonce_size){
|
||||
throw "Incorrect extranonce size";
|
||||
}
|
||||
|
||||
var part1 = this.tx.vin[0]._scriptSig_template[0];
|
||||
var part2 = this.tx.vin[0]._scriptSig_template[1];
|
||||
this.tx.vin[0].scriptSig = Buffer.concat([
|
||||
part1,
|
||||
extraNonce,
|
||||
part2
|
||||
]);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
exports.GenerationTransaction = GenerationTransaction;
|
||||
@ -2,7 +2,7 @@ var events = require('events');
|
||||
|
||||
var binpack = require('binpack');
|
||||
|
||||
var coinbase = require('./coinbase.js');
|
||||
var transactions = require('./transactions.js');
|
||||
var util = require('./util.js');
|
||||
var blockTemplate = require('./blockTemplate.js');
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ var binpack = require('/usr/lib/node_modules/binpack');
|
||||
var bignum = require('/usr/lib/node_modules/bignum');
|
||||
|
||||
var merkle = require('./merkleTree.js');
|
||||
var coinbase = require('./coinbase.js');
|
||||
var coinbase = require('./transactions.js');
|
||||
var util = require('./util.js');
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ exports.submit = function(job_id, worker_name, extranonce1_bin, extranonce2, nti
|
||||
|
||||
var job = JobStore.find(job_id);
|
||||
|
||||
var extraNonce2Size = coinbase.extranonce_size - ExtraNonceCounter.size();
|
||||
var extraNonce2Size = transactions.extranonce_size - ExtraNonceCounter.size();
|
||||
|
||||
if (extranonce2.length != extraNonce2Size * 2)
|
||||
return {error: 'rejected'} //Incorrect size of extranonce2
|
||||
|
||||
7
pool.js
7
pool.js
@ -7,7 +7,7 @@ var daemon = require('./daemon.js');
|
||||
var stratum = require('./stratum.js');
|
||||
var jobManager = require('./jobManager.js');
|
||||
var util = require('./util.js');
|
||||
var coinbase = require('./coinbase.js');
|
||||
var transactions = require('./transactions.js');
|
||||
|
||||
|
||||
|
||||
@ -31,7 +31,8 @@ var pool = module.exports = function pool(coin){
|
||||
[{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}],
|
||||
function(error, response){
|
||||
_this.jobManager.newTemplate(response.result);
|
||||
console.log(_this.jobManager.currentJob.getJobParams());
|
||||
console.log(response.result);
|
||||
//console.log(_this.jobManager.currentJob.getJobParams());
|
||||
}
|
||||
);
|
||||
}).on('startFailed', function(){
|
||||
@ -45,7 +46,7 @@ var pool = module.exports = function pool(coin){
|
||||
this.stratumServer.on('client', function(client){
|
||||
client.on('subscription', function(params, result){
|
||||
var extraNonce = _this.jobManager.extraNonceCounter.next();
|
||||
var extraNonce2Size = coinbase.extranonce_size - _this.jobManager.extraNonceCounter.size();
|
||||
var extraNonce2Size = transactions.extranonce_size - _this.jobManager.extraNonceCounter.size();
|
||||
result(extraNonce, extraNonce2Size);
|
||||
this.sendDifficulty(1);
|
||||
this.sendMiningJob(_this.jobManager.currentJob.getJobParams());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user