Merge pull request #1342 from TheSerapher/issue-1315

Issue 1315
This commit is contained in:
Sebastian Grewe 2014-01-10 10:38:01 -08:00
commit aa716c274c
7 changed files with 102 additions and 5 deletions

72
cronjobs/liquid_payout.php Executable file
View File

@ -0,0 +1,72 @@
#!/usr/bin/php
<?php
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Simple configuration check
if (!is_array($config['coldwallet'])) {
$log->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');
?>

View File

@ -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"

View File

@ -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"

View File

@ -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';
?>

View File

@ -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
*

View File

@ -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']) {

View File

@ -1,7 +1,7 @@
<?php
define('DB_VERSION', '0.0.1');
define('CONFIG_VERSION', '0.0.1');
define('CONFIG_VERSION', '0.0.2');
define('MPOS_VERSION', '0.0.1');
// Fetch installed database version