Fixed a couple of bugs that were preventing the thing to start in case of POS

This commit is contained in:
Andrea Baccega 2014-02-13 22:23:51 +01:00
parent 863c8bbf5f
commit 4fdd4fcf51
2 changed files with 32 additions and 22 deletions

View File

@ -81,6 +81,10 @@ var pool = module.exports = function pool(options, authorizeFn){
_this.daemon.cmd('submitblock', _this.daemon.cmd('submitblock',
[blockHex], [blockHex],
function(error, result){ function(error, result){
console.log(JSON.stringify([error,result]));
emitLog('submitblock', JSON.stringify([error,result]));
if (error) if (error)
emitErrorLog('submitblock', 'rpc error when submitting block with submitblock') emitErrorLog('submitblock', 'rpc error when submitting block with submitblock')
else else
@ -92,6 +96,7 @@ var pool = module.exports = function pool(options, authorizeFn){
_this.daemon.cmd('getblocktemplate', _this.daemon.cmd('getblocktemplate',
[{'mode': 'submit', 'data': blockHex}], [{'mode': 'submit', 'data': blockHex}],
function(error, result){ function(error, result){
console.log(error, result);
if (error) if (error)
emitErrorLog('submitblock', 'rpc error when submitting block with getblocktemplate') emitErrorLog('submitblock', 'rpc error when submitting block with getblocktemplate')
else else
@ -182,7 +187,11 @@ var pool = module.exports = function pool(options, authorizeFn){
emitLog('system','Connected to daemon'); emitLog('system','Connected to daemon');
options.hasSubmitMethod = results.submitMethod; options.hasSubmitMethod = results.submitMethod;
if (options.reward === 'POS' && typeof(results.addressInfo.pubkey) == 'undefined') {
// address provided is not of the wallet.
emitErrorLog('system', 'The address provided is not from the daemon wallet.');
return;
} else {
publicKeyBuffer = options.reward === 'POW' ? publicKeyBuffer = options.reward === 'POW' ?
util.script_to_address(results.addressInfo.address) : util.script_to_address(results.addressInfo.address) :
util.script_to_pubkey(results.addressInfo.pubkey); util.script_to_pubkey(results.addressInfo.pubkey);
@ -208,6 +217,7 @@ var pool = module.exports = function pool(options, authorizeFn){
StartStratumServer(); StartStratumServer();
} }
}); });
}
}); });
}).on('startFailed', function(){ }).on('startFailed', function(){

View File

@ -210,7 +210,7 @@ exports.address_to_pubkeyhash = function(addr){
*/ */
exports.script_to_pubkey = function(key){ exports.script_to_pubkey = function(key){
if (key.length === 66) key = new Buffer(key, 'hex'); if (key.length === 66) key = new Buffer(key, 'hex');
if (key !== 33) throw 'Invalid address'; if (key.length !== 33) throw 'Invalid address';
var pubkey = new Buffer(35); var pubkey = new Buffer(35);
pubkey[0] = 0x21; pubkey[0] = 0x21;
pubkey[34] = 0xac; pubkey[34] = 0xac;