forked from MPOS/php-mpos
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalidate_blocks.php
executable file
·47 lines (39 loc) · 1.21 KB
/
validate_blocks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/php
<?php
/* script to validate blocks */
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
if ( $bitcoin->can_connect() !== true )
die("Failed to connect to RPC server". PHP_EOL);
echo "Validating blocks in database against coind..". PHP_EOL;
$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)
{
try {
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($e->getMessage() == 'RPC call did not return 200: HTTP error: 500 - JSON Response: [-5] Block not found')
{
$status = 'INVALID';
}
else
{
$status = 'UNKNOWN';
}
}
printf($mask, $block['id'], $block['height'], $block['confirmations'], strftime("%Y-%m-%d %H:%M:%S", $block['time']), $status);
}
echo "Done..". PHP_EOL;