diff --git a/cronjobs/liquid_payout.php b/cronjobs/liquid_payout.php new file mode 100755 index 00000000..a0c9be13 --- /dev/null +++ b/cronjobs/liquid_payout.php @@ -0,0 +1,72 @@ +#!/usr/bin/php +logFatal('Missing config option: coldwallet'); + $monitoring->endCronjob($cron_name, 'E0075', 1, true); +} + +// Check RPC connection +if ($bitcoin->can_connect() !== true) { + $log->logFatal('Unable to connect to RPC server, exiting'); + $monitoring->endCronjob($cron_name, 'E0006', 1, true); +} else { + // Check Wallet Balance + $dBalance = $bitcoin->getbalance(); + $log->logDebug('The wallet balance is: ' .$dBalance); + + // Do we have anything available at all? + if (! ($dBalance > 0)) { + $log->logInfo('No coins available in wallet'); + $monitoring->endCronjob($cron_name, 'E0076', 0, true, false); + } + + // Check for POS Mint + $dGetInfo = $bitcoin->getinfo(); + if (is_array($dGetInfo) && array_key_exists('newmint', $dGetInfo)) { + $dNewmint = $dGetInfo['newmint']; + $log->logDebug('Current Mint is: ' . $dNewmint); + } else { + $dNewmint = -1; + } +} + +// Fetch locked balance from transactions +$dLockedBalance = $transaction->getLockedBalance(); +$log->logDebug('The locked wallet balance for users is: ' . $dLockedBalance); + +// Fetch Final Wallet Balance after Transfer +$dFloat = $dLockedBalance + $config['coldwallet']['reserve']; +$dThreshold = $config['coldwallet']['threshold']; +$log->logDebug('The locked wallet balance + reserves amounts to: ' . $dFloat); + +// Send Liquid Balance +$sendAddress = $config['coldwallet']['address']; +$send = $dBalance - $dFloat ; +$log->logDebug('Final Sending Amount is : ' . $send); + +if($send > $dThreshold) { + if (!empty($sendAddress)) { + try { + $bitcoin->sendtoaddress($sendAddress, $send); + } catch (Exception $e) { + $log->logFatal('Failed to send coins to address, skipping liquid assets payout:' . $e->getMessage()); + $monitoring->endCronjob($cron_name, 'E0077', 1, true); + } + $log->logInfo('Sent out ' . $send . ' liquid assets'); + } else { + $log->logDebug('No wallet address set'); + } +} else { + $log->logDebug('Final sending amount not exceeding threshold: ' . $send); +} + +// Cron cleanup and monitoring +require_once('cron_end.inc.php'); +?> diff --git a/cronjobs/run-crons.sh b/cronjobs/run-crons.sh index 759d1879..7dc1c262 100755 --- a/cronjobs/run-crons.sh +++ b/cronjobs/run-crons.sh @@ -10,7 +10,7 @@ PHP_BIN=$( which php ) # List of cruns to execute -CRONS="findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php tickerupdate.php notifications.php statistics.php token_cleanup.php archive_cleanup.php" +CRONS="liquid_payout.php findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php tickerupdate.php notifications.php statistics.php token_cleanup.php archive_cleanup.php" # Output additional runtime information VERBOSE="0" diff --git a/cronjobs/run-payout.sh b/cronjobs/run-payout.sh index d14a56bd..6fc26158 100755 --- a/cronjobs/run-payout.sh +++ b/cronjobs/run-payout.sh @@ -10,7 +10,7 @@ PHP_BIN=$( which php ) # List of cruns to execute -CRONS="findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php" +CRONS="liquid_payout.php findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php" # Output additional runtime information VERBOSE="0" diff --git a/public/include/config/error_codes.inc.php b/public/include/config/error_codes.inc.php index a157f14b..c57e9e3c 100644 --- a/public/include/config/error_codes.inc.php +++ b/public/include/config/error_codes.inc.php @@ -73,4 +73,6 @@ $aErrorCodes['E0072'] = 'Worker names must be alphanumeric'; $aErrorCodes['E0073'] = 'Worker name is too long; try entering a shorter name'; $aErrorCodes['E0074'] = 'Failed deleting expired tokens'; $aErrorCodes['E0075'] = 'Upgrade required'; +$aErrorCodes['E0076'] = 'No coins in wallet available'; +$aErrorCodes['E0077'] = 'RPC method or connection failed'; ?> diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index 704d01eb..ddabfca7 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -7,7 +7,7 @@ if (!defined('SECURITY')) die('Hacking attempt'); * This is used in the version check to ensure you run the latest version of the configuration file. * Once you upgraded your config, change the version here too. **/ -$config['version'] = '0.0.1'; +$config['version'] = '0.0.2'; // Our include directory for additional features define('INCLUDE_DIR', BASEPATH . 'include'); @@ -76,6 +76,29 @@ $config['wallet']['host'] = 'localhost:19334'; $config['wallet']['username'] = 'testnet'; $config['wallet']['password'] = 'testnet'; +/** + * Payout of liquid assets + * + * Explanation: + * Running pools, especially those with active fees, will build up a good + * amount of liquid assets that can be used by pool operators. If you wish + * to automaitcally send your assets to a offline wallet, set your account + * address, reserves and thresholds here. + * + * Options: + * address : The address of the wallet to the address you'd like to receive the coins in + * reserve : The amount you'd like to remain in the wallet. Recommended is at least 1 block value + * threshold : The amount of coins you'd like to send per batch minimum. Once exceeded, this is sent + * to the offline wallet address specified. + * Default: + * addresss : empty + * reserve : 50 + * threshold : 25 + **/ +$config['coldwallet']['address'] = ''; +$config['coldwallet']['reserve'] = 50; +$config['coldwallet']['threshold'] = 5; + /** * Lock account after maximum failed logins * diff --git a/public/include/pages/admin/monitoring.inc.php b/public/include/pages/admin/monitoring.inc.php index 9b8f795c..08efaee4 100644 --- a/public/include/pages/admin/monitoring.inc.php +++ b/public/include/pages/admin/monitoring.inc.php @@ -10,7 +10,7 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) { } // Default crons to monitor -$aCrons = array('statistics','payouts','token_cleanup','archive_cleanup','blockupdate','findblock','notifications','tickerupdate'); +$aCrons = array('statistics','payouts','token_cleanup','archive_cleanup','blockupdate','findblock','notifications','tickerupdate','liquid_payout'); // Special cases, only add them if activated switch ($config['payout_system']) { diff --git a/public/include/version.inc.php b/public/include/version.inc.php index 026707ea..e3f284f6 100644 --- a/public/include/version.inc.php +++ b/public/include/version.inc.php @@ -1,7 +1,7 @@