mirror of https://github.com/BTCPrivate/z-nomp.git
Bugfix: #5 Route coinbase rewards to z_address then to t_address
This commit is contained in:
parent
9a3454fca5
commit
965a2f4c82
|
@ -117,6 +117,92 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
|||
|
||||
async.parallel([validateAddress, getBalance], asyncComplete);
|
||||
|
||||
//get t_address coinbalance
|
||||
function listUnspent (addr, callback) {
|
||||
daemon.cmd('listunspent', [100, 99999999999, [addr]], function (result) {
|
||||
//Check if payments failed because wallet doesn't have enough coins to pay for tx fees
|
||||
if (result.error) {
|
||||
logger.error(logSystem, logComponent, 'Error trying to get coin balance with RPC listunspent.'
|
||||
+ JSON.stringify(result.error));
|
||||
callback(true);
|
||||
}
|
||||
else {
|
||||
var tBalance = 0;
|
||||
for (var i = 0, len = result[0].response.length; i < len; i++) {
|
||||
tBalance = tBalance + (result[0].response[i].amount * 100000000);
|
||||
}
|
||||
logger.debug(logSystem, logComponent, 'T_address contains a balance of: ' + (tBalance / magnitude));
|
||||
callback(null, tBalance);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// get z_address coinbalance
|
||||
function listUnspentZ (addr, callback) {
|
||||
daemon.cmd('z_getbalance', [addr, 3], function (result) {
|
||||
//Check if payments failed because wallet doesn't have enough coins to pay for tx fees
|
||||
if (result.error) {
|
||||
logger.error(logSystem, logComponent, 'Error trying to get coin balance with RPC z_getbalance.'
|
||||
+ JSON.stringify(result.error));
|
||||
callback(true);
|
||||
}
|
||||
else {
|
||||
var zBalance = result[0].response;
|
||||
logger.debug(logSystem, logComponent, 'Z_address contains a balance of: ' + (zBalance));
|
||||
callback(null, zBalance);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//send t_address balance to z_address
|
||||
function sendTToZ (callback, tBalance) {
|
||||
daemon.cmd('z_sendmany', [poolOptions.address,
|
||||
[{'address': poolOptions.zAddress, 'amount': (tBalance - 10000) / magnitude}]],
|
||||
function (result) {
|
||||
//Check if payments failed because wallet doesn't have enough coins to pay for tx fees
|
||||
if (result.error) {
|
||||
logger.error(logSystem, logComponent, 'Error trying to send t_address coin balance to z_address.'
|
||||
+ JSON.stringify(result.error));
|
||||
callback = function (){};
|
||||
callback(true);
|
||||
}
|
||||
else {
|
||||
logger.debug(logSystem, logComponent, 'Sent t_address balance to z_address: ' + (tBalance - 10000) / magnitude);
|
||||
callback = function (){};
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// send z_address balance to t_address
|
||||
function sendZToT (callback, zBalance) {
|
||||
daemon.cmd('z_sendmany', [poolOptions.zAddress,
|
||||
[{'address': poolOptions.tAddress, 'amount': (zBalance ) - (10000 / magnitude)}]],
|
||||
function (result) {
|
||||
//Check if payments failed because wallet doesn't have enough coins to pay for tx fees
|
||||
if (result.error) {
|
||||
logger.error(logSystem, logComponent, 'Error trying to send z_address coin balance to t_address.'
|
||||
+ JSON.stringify(result.error));
|
||||
callback = function (){};
|
||||
callback(true);
|
||||
}
|
||||
else {
|
||||
logger.debug(logSystem, logComponent, 'Sent z_address balance to t_address: ' + (zBalance ) - (10000 / magnitude));
|
||||
callback = function (){};
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// run coinbase coin transfers every x minutes
|
||||
var interval = poolOptions.walletInterval * 60 * 1000; // run every x minutes
|
||||
setInterval(function() {
|
||||
listUnspent(poolOptions.address, sendTToZ(tBalance));
|
||||
listUnspentZ(poolOptions.zAddress, sendZToT(zBalance));
|
||||
}, interval);
|
||||
|
||||
|
||||
var satoshisToCoins = function(satoshis){
|
||||
return parseFloat((satoshis / magnitude).toFixed(coinPrecision));
|
||||
|
@ -327,6 +413,7 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
|||
/* We found a confirmed block! Now get the reward for it and calculate how much
|
||||
we owe each miner based on the shares they submitted during that block round. */
|
||||
var reward = parseInt(round.reward * magnitude);
|
||||
// Send from t_address to z_address
|
||||
|
||||
var totalShares = Object.keys(workerShares).reduce(function(p, c){
|
||||
return p + parseFloat(workerShares[c])
|
||||
|
|
Loading…
Reference in New Issue