Fixed block submission hex.

This commit is contained in:
Andrea Baccega 2014-01-12 14:10:40 +01:00
parent 43517a8824
commit cb1e40d8eb
7 changed files with 50 additions and 14 deletions

View File

@ -44,6 +44,12 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
extraNoncePlaceholder
);
/**
* Checks if the rpcData provided as argument contains the same previousblockhash of the current job.
**/
this.isRPCDataFromSameBlock = function(rpcData) {
return this.rpcData.previousblockhash == rpcData.previousblockhash;
}
this.serializeCoinbase = function(extraNonce1, extraNonce2){
return Buffer.concat([
this.generationTransaction.coinbase[0],
@ -71,7 +77,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
this.serializeBlock = function(header, coinbase){
return Buffer.concat([
header,
util.varIntBuffer(this.rpcData.transaction.length + 1),
util.varIntBuffer(this.rpcData.transactions.length + 1),
coinbase,
this.transactionData
]);

View File

@ -3,13 +3,13 @@
"symbol": "doge",
"algorithm": "scrypt",
"reward": "POW",
"address": "DDt79i6P3Wro3SD3HSnkRLpMgUGUGdiNhS",
"address": "mkLyYQ5U8aFQ8aDAF1GS9zXStTzi3m29Tg",
"stratumPort": 3334,
"difficulty": 8,
"daemon": {
"host": "localhost",
"port": 8332,
"user": "test",
"password": "test"
"port": 19334,
"user": "testnet",
"password": "AHhQYqfSZqzQvkSXAtHtDAbKaZaoPih3wfmJfgCtjRx9"
}
}
}

View File

@ -1,6 +1,6 @@
{
"blockNotifyListener": {
"enabled": true,
"enabled": false,
"port": 8117,
"password": "test"
}

View File

@ -55,6 +55,11 @@ function DaemonInterface(options){
params: params
});
if (method == 'submitblock') {
console.log("SUBMITBLOCK daemon");
console.log(requestJson);
}
var options = {
hostname: 'localhost',
port: _this.options.port,

13
init.js
View File

@ -42,6 +42,7 @@ fs.readdir(confFolder, function(err, files){
if (config.blockNotifyListener.enabled){
console.log("ENABLED");
var blockNotifyServer = net.createServer(function(c) {
console.log('server connected');
var data = '';
@ -69,4 +70,16 @@ if (config.blockNotifyListener.enabled){
});
});
blockNotifyServer.listen(config.blockNotifyListener.port, function() {});
} else {
console.log("NOT ENABLED");
// If blockNotifyListener isn't enabled then we need to set up some polling parameters.
var pollingTime = typeof(config.blockPollingTime) === 'undefined' ? 5000 : parseInt(config.blockPollingTime, 10);
setInterval(
function () {
coins.forEach(function(coin) {
//coin.pool.
});
},
pollingTime
);
}

View File

@ -145,8 +145,8 @@ var JobManager = module.exports = function JobManager(options){
var headerBigNum = bignum.fromBuffer(headerHash, {endian: 'little', size: 32});
if (job.target.ge(headerBigNum)){
var blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer);
_this.emit('blockFound', blockHex);
var blockBuf = job.serializeBlock(headerBuffer, coinbaseBuffer);
_this.emit('blockFound', blockBuf.toString('hex'));
}
var targetUser = bignum(diffDividend / difficulty);

22
pool.js
View File

@ -24,20 +24,25 @@ var pool = module.exports = function pool(coin){
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
}).on('blockFound', function(blockHex){
if (coin.options.hasSubmitMethod)
if (coin.options.hasSubmitMethod) {
_this.daemon.cmd('submitblock',
[blockHex],
function(error, result){
console.log(JSON.stringify(error));
console.log(JSON.stringify(result));
console.log("submitblock", JSON.stringify(error), JSON.stringify(result));
}
);
else
} else {
_this.daemon.cmd('getblocktemplate',
[{'mode': 'submit', 'data': blockHex}],
function(error, result){
console.log(JSON.stringify(error));
console.log(JSON.stringify(result));
console.log("submitblockgetBlockTEmplate", JSON.stringify(error), JSON.stringify(result));
}
);
}
});
console.log('Connecting to daemon for ' + coin.options.name);
@ -132,11 +137,11 @@ var pool = module.exports = function pool(coin){
}
function GetBlockTemplate(callback){
console.log("getBlockTemplate");
_this.daemon.cmd('getblocktemplate',
[{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}],
function(error, result){
if (error){
console.log('getblocktemplate rpc error for ' + coin.options.name);
callback(error);
}
else{
@ -146,6 +151,13 @@ var pool = module.exports = function pool(coin){
);
}
this.processBlockPolling = function() {
GetBlockTemplate(function(error, result) {
console.log(JSON.stringify(result));
_this.jobManager.newTemplate(result, publicKeyBuffer);
});
}
this.processBlockNotify = function(blockHash){
if (blockHash !== _this.jobManager.currentJob.rpcData.previousblockhash){
GetBlockTemplate(function(error, result){