From 6f1f56abb6ed9a81dee4fe930ae97b0fbc877372 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 14 Feb 2014 17:21:52 +0100 Subject: [PATCH] [ADDED] getrealbalance wrapper for payouts During payouts, we must ensure our wallets main accounts has the funds to payout users. Hence we implement a wrapper method: * If account count == 1 we only have main account, return getbalance * Else return our main accounts balance - calculated unconfirmed This should keep getbalance untouched when used on other places but gives our payout processing a proper main account balance. It's mostly a wrapper for those wallets running multiple accounts in one wallet. They are warned on the front-end already but this ensure payouts process properly. Fixes #1755 once merged. --- cronjobs/payouts.php | 4 ++-- .../include/classes/bitcoinwrapper.class.php | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cronjobs/payouts.php b/cronjobs/payouts.php index c96af16c..24b2629a 100755 --- a/cronjobs/payouts.php +++ b/cronjobs/payouts.php @@ -41,7 +41,7 @@ $sendmanyAvailable = ((strpos($bitcoin->help('sendmany'), 'unknown') === FALSE) if ($sendmanyAvailable) $log->logDebug(' sendmany available in coind help command'); -if (!$dWalletBalance = $bitcoin->getbalance()) +if (!$dWalletBalance = $bitcoin->getrealbalance()) $dWalletBalance = 0; // Fetch outstanding manual-payouts @@ -113,7 +113,7 @@ if ($setting->getValue('disable_manual_payouts') != 1 && $aManualPayouts) { } } -if (!$dWalletBalance = $bitcoin->getbalance()) +if (!$dWalletBalance = $bitcoin->getrealbalance()) $dWalletBalance = 0; // Fetch outstanding auto-payouts diff --git a/public/include/classes/bitcoinwrapper.class.php b/public/include/classes/bitcoinwrapper.class.php index ebe1c470..010b455f 100644 --- a/public/include/classes/bitcoinwrapper.class.php +++ b/public/include/classes/bitcoinwrapper.class.php @@ -31,17 +31,26 @@ class BitcoinWrapper extends BitcoinClient { if ($data = $this->memcache->get(__FUNCTION__)) return $data; return $this->memcache->setCache(__FUNCTION__, parent::getmininginfo(), 30); } - // Wrapper to check our wallet balance from the DEFAULT account only - public function getbalance() { - $this->oDebug->append("STA " . __METHOD__, 4); - $aAccounts = parent::listaccounts(); - return $aAccounts['']; - } public function getblockcount() { $this->oDebug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__)) return $data; return $this->memcache->setCache(__FUNCTION__, parent::getblockcount(), 30); } + // Wrapper method to get the real main account balance + public function getrealbalance() { + $this->oDebug->append("STA " . __METHOD__, 4); + $aAccounts = parent::listaccounts(); + $dBalance = parent::getbalance(); + // Account checks + if (count($aAccounts) == 1) { + // We only have a single account so getbalance will be fine + return $dBalance; + } else { + $dMainBalance = $aAccounts['']; + $dUnconfirmed = $dMainBalance - $dBalance; + return $dMainBalance - $dUnconfirmed; + } + } public function getdifficulty() { $this->oDebug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__)) return $data;