add fees withdrawal
This commit is contained in:
parent
add62039db
commit
df68d33983
@ -257,7 +257,7 @@ function SetupForPool(logger, poolOptions){
|
|||||||
//number of satoshis in a single coin unit - this can be different for coins so we calculate it :)
|
//number of satoshis in a single coin unit - this can be different for coins so we calculate it :)
|
||||||
|
|
||||||
|
|
||||||
daemon.cmd('getbalance', [], function(results){
|
daemon.cmd('getbalance', [''], function(results){
|
||||||
|
|
||||||
var totalBalance = results[0].response * magnitude;
|
var totalBalance = results[0].response * magnitude;
|
||||||
var toBePaid = 0;
|
var toBePaid = 0;
|
||||||
@ -365,10 +365,11 @@ function SetupForPool(logger, poolOptions){
|
|||||||
var addressAmounts = {};
|
var addressAmounts = {};
|
||||||
var totalAmountUnits = 0;
|
var totalAmountUnits = 0;
|
||||||
for (var address in workerPayments){
|
for (var address in workerPayments){
|
||||||
var coinUnits = parseFloat((workerPayments[address] / magnitude).toFixed(coinPrecision));;
|
var coinUnits = parseFloat((workerPayments[address] / magnitude).toFixed(coinPrecision));
|
||||||
addressAmounts[address] = coinUnits;
|
addressAmounts[address] = coinUnits;
|
||||||
totalAmountUnits += coinUnits;
|
totalAmountUnits += coinUnits;
|
||||||
}
|
}
|
||||||
|
var feeAmountUnits = parseFloat((totalAmountUnits / (1 - processingConfig.feePercent) * processingConfig.feePercent).toFixed(coinPrecision));
|
||||||
|
|
||||||
logger.debug(logSystem, logComponent, 'Payments about to be sent to: ' + JSON.stringify(addressAmounts));
|
logger.debug(logSystem, logComponent, 'Payments about to be sent to: ' + JSON.stringify(addressAmounts));
|
||||||
daemon.cmd('sendmany', ['', addressAmounts], function(results){
|
daemon.cmd('sendmany', ['', addressAmounts], function(results){
|
||||||
@ -380,9 +381,16 @@ function SetupForPool(logger, poolOptions){
|
|||||||
var totalWorkers = Object.keys(workerPayments).length;
|
var totalWorkers = Object.keys(workerPayments).length;
|
||||||
logger.debug(logSystem, logComponent, 'Payments sent, a total of ' + totalAmountUnits +
|
logger.debug(logSystem, logComponent, 'Payments sent, a total of ' + totalAmountUnits +
|
||||||
' was sent to ' + totalWorkers + ' miners');
|
' was sent to ' + totalWorkers + ' miners');
|
||||||
|
daemon.cmd('move', ['', processingConfig.feeCollectAccount, feeAmountUnits], function(results){
|
||||||
|
if (results[0].error){
|
||||||
|
callback('Check finished - error with move ' + JSON.stringify(results[0].error));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var totalWorkers = Object.keys(workerPayments).length;
|
||||||
|
logger.debug(logSystem, logComponent, feeAmountUnits + ' collected as fee');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
], function(error, result){
|
], function(error, result){
|
||||||
if (error)
|
if (error)
|
||||||
@ -400,19 +408,26 @@ function SetupForPool(logger, poolOptions){
|
|||||||
|
|
||||||
if (!processingConfig.feeWithdrawalThreshold) return;
|
if (!processingConfig.feeWithdrawalThreshold) return;
|
||||||
|
|
||||||
daemon.cmd('getbalance', [], function(results){
|
daemon.cmd('getbalance', [processingConfig.feeCollectAccount], function(results){
|
||||||
|
|
||||||
var totalBalance = results[0].response;
|
var withdrawalAmount = results[0].response;
|
||||||
var withdrawalAmount = totalBalance - processingConfig.minimumReserve;
|
|
||||||
var leftOverBalance = totalBalance - withdrawalAmount;
|
|
||||||
|
|
||||||
|
if (withdrawalAmount < processingConfig.feeWithdrawalThreshold){
|
||||||
if (leftOverBalance < processingConfig.minimumReserve || withdrawalAmount < processingConfig.feeWithdrawalThreshold){
|
|
||||||
logger.debug(logSystem, logComponent, 'Not enough profit to withdrawal yet');
|
logger.debug(logSystem, logComponent, 'Not enough profit to withdrawal yet');
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//Need to figure out how much of the balance is profit... ???
|
|
||||||
logger.debug(logSystem, logComponent, 'Can send profit');
|
var withdrawal = {};
|
||||||
|
withdrawal[processingConfig.feeReceiveAddress] = withdrawalAmount;
|
||||||
|
|
||||||
|
daemon.cmd('sendmany', [processingConfig.feeCollectAccount, withdrawal], function(results){
|
||||||
|
if (results[0].error){
|
||||||
|
logger.debug(logSystem, logComponent, 'Withdrawal profit finished - error with sendmany ' + JSON.stringify(results[0].error));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.debug(logSystem, logComponent, 'Profit sent, a total of ' + withdrawalAmount +
|
||||||
|
' was sent to ' + processingConfig.feeReceiveAddress);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
"minimumPayment": 100.001,
|
"minimumPayment": 100.001,
|
||||||
"minimumReserve": 10,
|
"minimumReserve": 10,
|
||||||
"feePercent": 0.02,
|
"feePercent": 0.02,
|
||||||
|
"feeCollectAccount": "feesCollected",
|
||||||
"feeReceiveAddress": "LZz44iyF4zLCXJTU8RxztyyJZBntdS6fvv",
|
"feeReceiveAddress": "LZz44iyF4zLCXJTU8RxztyyJZBntdS6fvv",
|
||||||
"feeWithdrawalThreshold": 5,
|
"feeWithdrawalThreshold": 5,
|
||||||
"daemon": {
|
"daemon": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user