From f6ceace3868d83099824a30bfa9b3c8678e838d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20Uslu?= Date: Fri, 28 Feb 2014 23:40:08 +0200 Subject: [PATCH] fixed orphan detection --- scripts/validate_blocks.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/validate_blocks.php b/scripts/validate_blocks.php index 57895295..e1d0af9f 100644 --- a/scripts/validate_blocks.php +++ b/scripts/validate_blocks.php @@ -13,25 +13,25 @@ echo "Validating blocks in database against coind..". PHP_EOL; - $mask = "| %6s | %8s | %13s | %20s | %10s | \n"; + $mask = "| %6s | %8s | %13s | %20s | %10s |". PHP_EOL;; printf($mask, 'DB-ID', 'Height', 'Confirmations', 'Time', 'Status'); // fetch all blocks $allBlocks = $block->getAll(); foreach ($allBlocks as $block) - { - $status = 'VALID'; - + { try { - $blockInfo = $bitcoin->getblock($block['blockhash']); + if($block['confirmations']== -1) // mark orphan blocks. + $status = 'ORPHAN'; + else + { + $blockInfo = $bitcoin->getblock($block['blockhash']); + $status = 'VALID'; // if the getblock() call didn't throw an exception, it's a valid block then. + } } catch(Exception $e) { - if($block['confirmations']== -1) - { - $status = 'ORPHAN'; - } - else if($e->getMessage() == 'RPC call did not return 200: HTTP error: 500 - JSON Response: [-5] Block not found') + if($e->getMessage() == 'RPC call did not return 200: HTTP error: 500 - JSON Response: [-5] Block not found') { $status = 'INVALID'; }