From dc51d874a74fd33231b30167ccd14bf6491c2fca Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 9 Jul 2013 21:26:06 +0200 Subject: [PATCH] Adding block height to blockupdate output This should make tracing block updates easier. --- cronjobs/blockupdate.php | 4 ++-- public/include/classes/block.class.php | 9 ++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cronjobs/blockupdate.php b/cronjobs/blockupdate.php index 89a27be1..d257a69d 100755 --- a/cronjobs/blockupdate.php +++ b/cronjobs/blockupdate.php @@ -30,12 +30,12 @@ if ( $bitcoin->can_connect() !== true ) { // Fetch all unconfirmed blocks $aAllBlocks = $block->getAllUnconfirmed($config['confirmations']); -$log->logInfo("ID\tBlockhash\tConfirmations"); +$log->logInfo("ID\tHeight\tBlockhash\tConfirmations"); foreach ($aAllBlocks as $iIndex => $aBlock) { $aBlockInfo = $bitcoin->query('getblock', $aBlock['blockhash']); // Fetch this blocks transaction details to find orphan blocks $aTxDetails = $bitcoin->query('gettransaction', $aBlockInfo['tx'][0]); - $log->logInfo($aBlock['id'] . "\t" . $aBlock['blockhash'] . "\t" . $aBlock['confirmations'] . " -> " . $aBlockInfo['confirmations']); + $log->logInfo($aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['blockhash'] . "\t" . $aBlock['confirmations'] . " -> " . $aBlockInfo['confirmations']); if ($aTxDetails['details'][0]['category'] == 'orphan') { // We have an orphaned block, we need to invalidate all transactions for this one if ($transaction->setOrphan($aBlock['id']) && $block->setConfirmations($aBlock['id'], -1)) { diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index 2fcbad09..81d1806a 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -85,14 +85,9 @@ class Block { * @return data array Array with database fields as keys **/ public function getAllUnconfirmed($confirmations='120') { - $stmt = $this->mysqli->prepare("SELECT id, 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(); - $stmt->close(); + $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()) return $result->fetch_all(MYSQLI_ASSOC); - } return false; }