[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.
This commit is contained in:
Sebastian Grewe 2014-02-14 17:21:52 +01:00
parent 8f4af5b038
commit 6f1f56abb6
2 changed files with 17 additions and 8 deletions

View File

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

View File

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