#!/usr/bin/php can_connect() !== true ) { $log->logFatal("Failed to connect to RPC server\n"); exit(1); } // Fetch all unconfirmed blocks $aAllBlocks = $block->getAllUnconfirmed($config['confirmations']); $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['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)) { $log->logInfo(" Block marked as orphan"); } else { $log->logError(" Block became orphaned but unable to update database entries"); } continue; } if ($aBlock['confirmations'] == $aBlockInfo['confirmations']) { $log->logDebug(' No update needed'); } else if (!$block->setConfirmations($aBlock['id'], $aBlockInfo['confirmations'])) { $log->logError(' Failed to update block confirmations'); } }