Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0af3101931 | ||
|
|
9b4b7dfac5 | ||
|
|
6f43936a76 | ||
|
|
eec9fc9d67 |
@ -9,7 +9,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, poolAddressScript, extraNoncePlaceholder, reward, txMessages, recipients){
|
||||
var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, poolAddressScript, extraNoncePlaceholder, reward, txMessages, recipients, network){
|
||||
|
||||
//private members
|
||||
|
||||
@ -71,7 +71,8 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool
|
||||
extraNoncePlaceholder,
|
||||
reward,
|
||||
txMessages,
|
||||
recipients
|
||||
recipients,
|
||||
network
|
||||
);
|
||||
|
||||
this.serializeCoinbase = function(extraNonce1, extraNonce2){
|
||||
|
||||
@ -123,7 +123,8 @@ var JobManager = module.exports = function JobManager(options){
|
||||
_this.extraNoncePlaceholder,
|
||||
options.coin.reward,
|
||||
options.coin.txMessages,
|
||||
options.recipients
|
||||
options.recipients,
|
||||
options.network
|
||||
);
|
||||
|
||||
_this.currentJob = tmpBlockTemplate;
|
||||
@ -158,7 +159,8 @@ var JobManager = module.exports = function JobManager(options){
|
||||
_this.extraNoncePlaceholder,
|
||||
options.coin.reward,
|
||||
options.coin.txMessages,
|
||||
options.recipients
|
||||
options.recipients,
|
||||
options.network
|
||||
);
|
||||
|
||||
this.currentJob = tmpBlockTemplate;
|
||||
|
||||
30
lib/pool.js
30
lib/pool.js
@ -20,6 +20,9 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
var _this = this;
|
||||
var blockPollingIntervalId;
|
||||
|
||||
if (!(options.address)) {
|
||||
_this.newAddressOnNewBlock = true;
|
||||
}
|
||||
|
||||
var emitLog = function(text) { _this.emit('log', 'debug' , text); };
|
||||
var emitWarningLog = function(text) { _this.emit('log', 'warning', text); };
|
||||
@ -223,7 +226,6 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
Coin daemons either use submitblock or getblocktemplate for submitting new blocks
|
||||
*/
|
||||
function SubmitBlock(blockHex, callback){
|
||||
|
||||
var rpcCommand, rpcArgs;
|
||||
if (options.hasSubmitMethod){
|
||||
rpcCommand = 'submitblock';
|
||||
@ -234,6 +236,16 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
rpcArgs = [{'mode': 'submit', 'data': blockHex}];
|
||||
}
|
||||
|
||||
if (_this.newAddressOnNewBlock) {
|
||||
_this.daemon.cmd('getnewaddress', [], function(results) {
|
||||
|
||||
options.poolAddressScript = (function(){
|
||||
return util.addressToScript(options.network, results[0].response);
|
||||
})();
|
||||
|
||||
options.address = results[0].response;
|
||||
});
|
||||
}
|
||||
|
||||
_this.daemon.cmd(rpcCommand,
|
||||
rpcArgs,
|
||||
@ -273,7 +285,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
if (r.length === 40)
|
||||
rObj.script = util.miningKeyToScript(r);
|
||||
else
|
||||
rObj.script = util.addressToScript(r);
|
||||
rObj.script = util.addressToScript(options.network, r);
|
||||
recipients.push(rObj);
|
||||
options.feePercent += percent;
|
||||
}
|
||||
@ -350,6 +362,12 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
});
|
||||
|
||||
_this.daemon.once('online', function(){
|
||||
if (options.address == false) {
|
||||
_this.daemon.cmd('getnewaddress', [], function(results) {
|
||||
options.address = results[0].response;
|
||||
finishedCallback();
|
||||
})
|
||||
}
|
||||
finishedCallback();
|
||||
|
||||
}).on('connectionFailed', function(error){
|
||||
@ -414,17 +432,19 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
return;
|
||||
}
|
||||
|
||||
options.testnet = (rpcResults.getblockchaininfo.chain === 'test') ? true : false;
|
||||
|
||||
options.network = (options.testnet ? options.coin.testnet : options.coin.mainnet);
|
||||
|
||||
options.poolAddressScript = (function(){
|
||||
switch(options.coin.reward){
|
||||
case 'POS':
|
||||
return util.pubkeyToScript(rpcResults.validateaddress.pubkey);
|
||||
case 'POW':
|
||||
return util.addressToScript(rpcResults.validateaddress.address);
|
||||
return util.addressToScript(options.network, rpcResults.validateaddress.address);
|
||||
}
|
||||
})();
|
||||
|
||||
options.testnet = (rpcResults.getblockchaininfo.chain === 'test') ? true : false;
|
||||
|
||||
options.protocolVersion = rpcResults.getnetworkinfo.protocolversion;
|
||||
|
||||
options.initStats = {
|
||||
|
||||
@ -123,7 +123,7 @@ For some (probably outdated and incorrect) documentation about whats kinda going
|
||||
see: https://en.bitcoin.it/wiki/Protocol_specification#tx
|
||||
*/
|
||||
|
||||
var generateOutputTransactions = function(poolRecipient, recipients, rpcData){
|
||||
var generateOutputTransactions = function(poolRecipient, recipients, rpcData, network){
|
||||
|
||||
var reward = rpcData.coinbasevalue;
|
||||
var rewardToPool = reward;
|
||||
@ -141,7 +141,7 @@ if (rpcData.masternode && rpcData.superblock) {
|
||||
reward -= payeeReward;
|
||||
rewardToPool -= payeeReward;
|
||||
|
||||
var payeeScript = util.addressToScript(rpcData.masternode.payee);
|
||||
var payeeScript = util.addressToScript(network, rpcData.masternode.payee);
|
||||
txOutputBuffers.push(Buffer.concat([
|
||||
util.packInt64LE(payeeReward),
|
||||
util.varIntBuffer(payeeScript.length),
|
||||
@ -155,7 +155,7 @@ if (rpcData.masternode && rpcData.superblock) {
|
||||
reward -= payeeReward;
|
||||
rewardToPool -= payeeReward;
|
||||
|
||||
var payeeScript = util.addressToScript(rpcData.superblock[i].payee);
|
||||
var payeeScript = util.addressToScript(network, rpcData.superblock[i].payee);
|
||||
txOutputBuffers.push(Buffer.concat([
|
||||
util.packInt64LE(payeeReward),
|
||||
util.varIntBuffer(payeeScript.length),
|
||||
@ -177,7 +177,7 @@ if (rpcData.payee) {
|
||||
reward -= payeeReward;
|
||||
rewardToPool -= payeeReward;
|
||||
|
||||
var payeeScript = util.addressToScript(rpcData.payee);
|
||||
var payeeScript = util.addressToScript(network, rpcData.payee);
|
||||
txOutputBuffers.push(Buffer.concat([
|
||||
util.packInt64LE(payeeReward),
|
||||
util.varIntBuffer(payeeScript.length),
|
||||
@ -222,7 +222,7 @@ if (rpcData.payee) {
|
||||
};
|
||||
|
||||
|
||||
exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, reward, txMessages, recipients){
|
||||
exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, reward, txMessages, recipients, network){
|
||||
|
||||
var txInputsCount = 1;
|
||||
var txOutputsCount = 1;
|
||||
@ -272,7 +272,7 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, r
|
||||
*/
|
||||
|
||||
|
||||
var outputTransactions = generateOutputTransactions(publicKey, recipients, rpcData);
|
||||
var outputTransactions = generateOutputTransactions(publicKey, recipients, rpcData, network);
|
||||
|
||||
var p2 = Buffer.concat([
|
||||
scriptSigPart2,
|
||||
|
||||
21
lib/util.js
21
lib/util.js
@ -2,6 +2,7 @@ var crypto = require('crypto');
|
||||
|
||||
var base58 = require('base58-native');
|
||||
var bignum = require('bignum');
|
||||
var bitcoin = require('bitcoinjs-lib');
|
||||
|
||||
|
||||
exports.addressFromEx = function(exAddress, ripdm160Key){
|
||||
@ -261,26 +262,16 @@ exports.miningKeyToScript = function(key){
|
||||
/*
|
||||
For POW coins - used to format wallet address for use in generation transaction's output
|
||||
*/
|
||||
exports.addressToScript = function(addr){
|
||||
exports.addressToScript = function(network, addr){
|
||||
|
||||
var decoded = base58.decode(addr);
|
||||
|
||||
if (decoded.length != 25){
|
||||
console.error('invalid address length for ' + addr);
|
||||
throw new Error();
|
||||
if (typeof network !== 'undefined' && network !== null){
|
||||
return bitcoin.address.toOutputScript(addr, network);
|
||||
} else {
|
||||
return Buffer.concat([new Buffer([0x76, 0xa9, 0x14]), bitcoin.address.fromBase58Check(addr).hash, new Buffer([0x88, 0xac])]);
|
||||
}
|
||||
|
||||
if (!decoded){
|
||||
console.error('base58 decode failed for ' + addr);
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
var pubkey = decoded.slice(1,-4);
|
||||
|
||||
return Buffer.concat([new Buffer([0x76, 0xa9, 0x14]), pubkey, new Buffer([0x88, 0xac])]);
|
||||
};
|
||||
|
||||
|
||||
exports.getReadableHashRateString = function(hashrate){
|
||||
var i = -1;
|
||||
var byteUnits = [ ' KH', ' MH', ' GH', ' TH', ' PH' ];
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"multi-hashing": "git://github.com/zone117x/node-multi-hashing.git",
|
||||
"bitcoinjs-lib": "*",
|
||||
"bignum": "*",
|
||||
"base58-native": "*",
|
||||
"async": "*"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user