Skip to content

Commit

Permalink
[ADDED] getrealbalance wrapper for payouts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MPOS123 committed Feb 14, 2014
1 parent 8f4af5b commit 6f1f56a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cronjobs/payouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,7 +113,7 @@
}
}

if (!$dWalletBalance = $bitcoin->getbalance())
if (!$dWalletBalance = $bitcoin->getrealbalance())
$dWalletBalance = 0;

// Fetch outstanding auto-payouts
Expand Down
21 changes: 15 additions & 6 deletions public/include/classes/bitcoinwrapper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6f1f56a

Please sign in to comment.