From 6f1f56abb6ed9a81dee4fe930ae97b0fbc877372 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 14 Feb 2014 17:21:52 +0100 Subject: [PATCH 1/4] [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 c96af16c4..24b2629a3 100755 --- a/cronjobs/payouts.php +++ b/cronjobs/payouts.php @@ -41,7 +41,7 @@ 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 (!$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 ebe1c4702..010b455f7 100644 --- a/public/include/classes/bitcoinwrapper.class.php +++ b/public/include/classes/bitcoinwrapper.class.php @@ -31,17 +31,26 @@ public function getmininginfo() { 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; From 691e1e60cb65d00e9ecb663510eb177c14fd3109 Mon Sep 17 00:00:00 2001 From: iAmShorty Date: Fri, 14 Feb 2014 20:49:42 +0100 Subject: [PATCH 2/4] Update bitcoinwrapper.class.php --- public/include/classes/bitcoinwrapper.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/include/classes/bitcoinwrapper.class.php b/public/include/classes/bitcoinwrapper.class.php index 010b455f7..126cbb2b6 100644 --- a/public/include/classes/bitcoinwrapper.class.php +++ b/public/include/classes/bitcoinwrapper.class.php @@ -48,7 +48,8 @@ public function getrealbalance() { } else { $dMainBalance = $aAccounts['']; $dUnconfirmed = $dMainBalance - $dBalance; - return $dMainBalance - $dUnconfirmed; + //return $dMainBalance - $dUnconfirmed; + return $dMainBalance - abs($dUnconfirmed) } } public function getdifficulty() { From b0baa29a1fdd184c72859337e211b2468963c66a Mon Sep 17 00:00:00 2001 From: iAmShorty Date: Fri, 14 Feb 2014 21:03:30 +0100 Subject: [PATCH 3/4] [FIX] fix for negative balance using php abs() should do the trick with negative balance --- public/include/classes/bitcoinwrapper.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/include/classes/bitcoinwrapper.class.php b/public/include/classes/bitcoinwrapper.class.php index 126cbb2b6..a09c30e43 100644 --- a/public/include/classes/bitcoinwrapper.class.php +++ b/public/include/classes/bitcoinwrapper.class.php @@ -47,7 +47,8 @@ public function getrealbalance() { return $dBalance; } else { $dMainBalance = $aAccounts['']; - $dUnconfirmed = $dMainBalance - $dBalance; + //$dUnconfirmed = $dMainBalance - $dBalance; + $dUnconfirmed = $dMainBalance - abs($dBalance); //return $dMainBalance - $dUnconfirmed; return $dMainBalance - abs($dUnconfirmed) } From d1f3f5d01d781de1bb554516b82eb365b3cdf476 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 15 Feb 2014 19:17:12 +0100 Subject: [PATCH 4/4] [UPDATE] Return negative balance if main is negative --- public/include/classes/bitcoinwrapper.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/public/include/classes/bitcoinwrapper.class.php b/public/include/classes/bitcoinwrapper.class.php index a09c30e43..f72f3933c 100644 --- a/public/include/classes/bitcoinwrapper.class.php +++ b/public/include/classes/bitcoinwrapper.class.php @@ -47,10 +47,9 @@ public function getrealbalance() { return $dBalance; } else { $dMainBalance = $aAccounts['']; - //$dUnconfirmed = $dMainBalance - $dBalance; + if ($dMainBalance < 0) return $dMainBalance; $dUnconfirmed = $dMainBalance - abs($dBalance); - //return $dMainBalance - $dUnconfirmed; - return $dMainBalance - abs($dUnconfirmed) + return $dMainBalance - abs($dUnconfirmed); } } public function getdifficulty() {