diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index 4ee9f6446..d425c4769 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -26,7 +26,7 @@ require_once('shared.inc.php'); // Fetch our last block found from the DB as a starting point -$aLastBlock = @$block->getLast(); +$aLastBlock = @$block->getLastValid(); $strLastBlockHash = $aLastBlock['blockhash']; if (!$strLastBlockHash) $strLastBlockHash = ''; diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index 76ccf43d5..cf0ea7eeb 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -15,6 +15,18 @@ public function getLast() { return $result->fetch_assoc(); return $this->sqlError(); } + + /** + * Specific method to fetch the latest block found that is VALID + * @param none + * @return data array Array with database fields as keys + **/ + public function getLastValid() { + $stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE confirmations > -1 ORDER BY height DESC LIMIT 1"); + if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_assoc(); + return $this->sqlError(); + } /** * Get a specific block, by block height