Adding unconfirmed blocks to wallet

First attempt addressing #610, still missing a detection for the actual
confirmation limit required for each block in case one lowers it in the
config.
This commit is contained in:
Sebastian Grewe 2013-08-19 09:31:53 +02:00
parent b5b40620f0
commit 7e4c5dab4e
3 changed files with 18 additions and 5 deletions

View File

@ -10,9 +10,10 @@ class Block {
// This defines each block
public $height, $blockhash, $confirmations, $time, $accounted;
public function __construct($debug, $mysqli, $salt) {
public function __construct($debug, $mysqli, $config) {
$this->debug = $debug;
$this->mysqli = $mysqli;
$this->config = $config;
$this->debug->append("Instantiated Block class", 2);
}
@ -120,9 +121,9 @@ class Block {
* @param confirmations int Required confirmations to consider block confirmed
* @return data array Array with database fields as keys
**/
public function getAllUnconfirmed($confirmations='120') {
$stmt = $this->mysqli->prepare("SELECT id, height, blockhash, confirmations FROM $this->table WHERE confirmations < ? AND confirmations > -1");
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $confirmations) && $stmt->execute() && $result = $stmt->get_result())
public function getAllUnconfirmed() {
$stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE confirmations < ? AND confirmations > -1");
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $this->config['confirmations']) && $stmt->execute() && $result = $stmt->get_result())
return $result->fetch_all(MYSQLI_ASSOC);
return false;
}
@ -267,4 +268,4 @@ class Block {
}
// Automatically load our class for furhter usage
$block = new Block($debug, $mysqli, SALT);
$block = new Block($debug, $mysqli, $config);

View File

@ -24,16 +24,24 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$dNewmint = -1;
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
}
// Fetch unconfirmed amount from blocks table
$aBlocksUnconfirmed = $block->getAllUnconfirmed();
$dBlocksUnconfirmedBalance = 0;
if (!empty($aBlocksUnconfirmed))
foreach ($aBlocksUnconfirmed as $aData) $dBlocksUnconfirmedBalance += $aData['amount'];
// Fetch locked balance from transactions
$dLockedBalance = $transaction->getLockedBalance();
} else {
$debug->append('Using cached page', 3);
}
$smarty->assign("UNCONFIRMED", $dBlocksUnconfirmedBalance);
$smarty->assign("BALANCE", $dBalance);
$smarty->assign("LOCKED", $dLockedBalance);
$smarty->assign("NEWMINT", $dNewmint);
// Tempalte specifics
$smarty->assign("CONTENT", "default.tpl");
?>

View File

@ -8,6 +8,10 @@
<th>Locked for users</th>
<td class="right">{$LOCKED|number_format:"8"}</td>
</tr>
<tr>
<th>Unconfirmed</th>
<td class="right">{$UNCONFIRMED|number_format:"8"}</td>
</tr>
<tr>
<th>Liquid Assets</th>
<td class="right">{($BALANCE - $LOCKED)|number_format:"8"}</td>