Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafeCash (Testnet) Support Added #12

Merged
merged 8 commits into from
Sep 22, 2018
20 changes: 17 additions & 3 deletions lib/blockTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ var BlockTemplate = module.exports = function BlockTemplate(
this.difficulty = parseFloat((diff1 / this.target.toNumber()).toFixed(9));

// generate the fees and coinbase tx
var blockReward = (this.rpcData.miner) * 100000000;
var blockReward = {
"total": (this.rpcData.miner) * 100000000
};

var masternodeReward;
var masternodePayee;
Expand All @@ -39,8 +41,20 @@ var BlockTemplate = module.exports = function BlockTemplate(
if (coin.payFoundersReward === true) {
if (!this.rpcData.founders || this.rpcData.founders.length <= 0) {
console.log('Error, founders reward missing for block template!');
} else if (this.rpcData.infrastructure && this.rpcData.infrastructure > 0){
// SafeCash
blockReward = {
"miner": (this.rpcData.miner),
"infrastructure": (this.rpcData.infrastructure),
"giveaways": (this.rpcData.giveaways),
"founderSplit": (this.rpcData.loki),
"total": (this.rpcData.miner + this.rpcData.founders + this.rpcData.infrastructure + this.rpcData.giveaways)
};
//console.log(`SafeCash: ${this.rpcData.miner}`);
} else {
blockReward = (this.rpcData.miner + this.rpcData.founders + this.rpcData.securenodes + this.rpcData.supernodes) * 100000000;
blockReward = {
"total": (this.rpcData.miner + this.rpcData.founders + this.rpcData.securenodes + this.rpcData.supernodes) * 100000000
};
}
}

Expand All @@ -57,7 +71,7 @@ var BlockTemplate = module.exports = function BlockTemplate(

if (typeof this.genTx === 'undefined') {
this.genTx = transactions.createGeneration(
rpcData.height,
rpcData,
blockReward,
this.rewardFees,
recipients,
Expand Down
2 changes: 1 addition & 1 deletion lib/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function DaemonInterface(daemons, logger) {
}

function isOnline(callback) {
cmd('getinfo', [], function (results) {
cmd('getpeerinfo', [], function (results) {
var allOnline = results.every(function (result) {
return !results.error;
});
Expand Down
7 changes: 6 additions & 1 deletion lib/merkleTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ function calcRoot(hashes) {
exports.getRoot = function (rpcData, generateTxRaw) {
hashes = [util.reverseBuffer(new Buffer(generateTxRaw, 'hex')).toString('hex')];
rpcData.transactions.forEach(function (value) {
hashes.push(value.hash);
// Segwit support
if (value.txid !== undefined) {
hashes.push(value.txid);
} else {
hashes.push(value.hash);
}
});
if (hashes.length === 1) {
return hashes[0];
Expand Down
75 changes: 60 additions & 15 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,22 @@ var pool = module.exports = function pool(options, authorizeFn) {


function OnBlockchainSynced(syncedCallback) {
var callConfig = {
"capabilities": [
"coinbasetxn",
"workid",
"coinbase/append"
]
};

// Segwit support
if (options.coin.supportsSegwit)
{
callConfig.rules = ["segwit"];
}

var checkSynced = function (displayNotSynced) {
_this.daemon.cmd('getblocktemplate', [], function (results) {
_this.daemon.cmd('getblocktemplate', callConfig, function (results) {
var synced = results.every(function (r) {
return !r.error || r.error.code !== -10;
});
Expand All @@ -150,8 +163,8 @@ var pool = module.exports = function pool(options, authorizeFn) {


var generateProgress = function () {

_this.daemon.cmd('getinfo', [], function (results) {
var cmd = options.coin.hasGetInfo ? 'getinfo' : 'getblockchaininfo';
_this.daemon.cmd(cmd, [], function (results) {
var blockCount = results.sort(function (a, b) {
return b.response.blocks - a.response.blocks;
})[0].response.blocks;
Expand Down Expand Up @@ -374,11 +387,16 @@ var pool = module.exports = function pool(options, authorizeFn) {
var batchRpcCalls = [
['validateaddress', [options.address]],
['getdifficulty', []],
['getinfo', []],
['getmininginfo', []],
['submitblock', []]
];

if (options.coin.hasGetInfo) {
batchRpcCalls.push(['getinfo', []]);
} else {
batchRpcCalls.push(['getblockchaininfo', []], ['getnetworkinfo', []]);
}

_this.daemon.batchCmd(batchRpcCalls, function (error, results) {
if (error || !results) {
emitErrorLog('Could not start pool, error with init batch RPC call: ' + JSON.stringify(error));
Expand All @@ -403,10 +421,10 @@ var pool = module.exports = function pool(options, authorizeFn) {
return;
}

if (isNaN(rpcResults.getdifficulty) && 'proof-of-stake' in rpcResults.getdifficulty)
options.coin.reward = 'POS';
else
options.coin.reward = 'POW';
if (isNaN(rpcResults.getdifficulty) && 'proof-of-stake' in rpcResults.getdifficulty)
options.coin.reward = 'POS';
else
options.coin.reward = 'POW';


/* POS coins must use the pubkey in coinbase transaction, and pubkey is
Expand All @@ -420,12 +438,17 @@ var pool = module.exports = function pool(options, authorizeFn) {
return util.addressToScript(rpcResults.validateaddress.address);
})();

options.testnet = rpcResults.getinfo.testnet;
options.protocolVersion = rpcResults.getinfo.protocolversion;
options.testnet = options.coin.hasGetInfo ? rpcResults.getblockchaininfo.chain === "test" : rpcResults.getinfo.testnet;
options.protocolVersion = options.coin.hasGetInfo ? rpcResults.getinfo.protocolversion : rpcResults.getnetworkinfo.protocolversion;

var tempDifficulty = options.coin.hasGetInfo ? rpcResults.getinfo.difficulty : rpcResults.getblockchaininfo.difficulty;
if (typeof(tempDifficulty) == 'object') {
tempDifficulty = tempDifficulty['proof-of-work'];
}

options.initStats = {
connections: rpcResults.getinfo.connections,
difficulty: rpcResults.getinfo.difficulty * algos[options.coin.algorithm].multiplier,
connections: (options.coin.hasGetInfo ? rpcResults.getinfo.connections : rpcResults.getnetworkinfo.connections),
difficulty: tempDifficulty * algos[options.coin.algorithm].multiplier,
networkHashRate: rpcResults.getmininginfo.networkhashps
};

Expand Down Expand Up @@ -572,17 +595,30 @@ var pool = module.exports = function pool(options, authorizeFn) {


function getBlockTemplate(subsidy) {
var callConfig = {
"capabilities": [
"coinbasetxn",
"workid",
"coinbase/append"
]
};

// Segwit support
if (options.coin.supportsSegwit)
{
callConfig.rules = ["segwit"];
}

_this.daemon.cmd('getblocktemplate',
[{"capabilities": ["coinbasetxn", "workid", "coinbase/append"]}],
function (result) {
[callConfig],
function (result) {
if (result.error) {
emitErrorLog('getblocktemplate call failed for daemon instance ' +
result.instance.index + ' with error ' + JSON.stringify(result.error));
callback(result.error);
} else {
result.response.miner = subsidy.miner;
result.response.founders = (subsidy.founders || subsidy.community);
result.response.founders = (subsidy.founders || subsidy.community || (subsidy['founders-chris'] + subsidy['founders-jimmy'] + subsidy['founders-scott'] + subsidy['founders-shelby'] + subsidy['founders-loki'] ));

// I hate to do this but vision coin doesn't send the
// correct response for getblocksubsidy so this allows
Expand All @@ -598,6 +634,15 @@ var pool = module.exports = function pool(options, authorizeFn) {
result.response.securenodes = (subsidy.securenodes || 0);
result.response.supernodes = (subsidy.supernodes || 0);

// SafeCash
result.response.infrastructure = (subsidy.infrastructure || 0);
result.response.giveaways = (subsidy.giveaways || 0);
result.response.chris = (subsidy['founders-chris'] || 0);
result.response.jimmy = (subsidy['founders-jimmy'] || 0);
result.response.scott = (subsidy['founders-scott'] || 0);
result.response.shelby = (subsidy['founders-shelby'] || 0);
result.response.loki = (subsidy['founders-loki'] || 0);

var processedNewBlock = _this.jobManager.processTemplate(result.response);
callback(null, result.response, processedNewBlock);
callback = () => {}
Expand Down
Loading