-
Notifications
You must be signed in to change notification settings - Fork 23
/
dmnblockdegapper.script.inc.php
executable file
·118 lines (102 loc) · 3.13 KB
/
dmnblockdegapper.script.inc.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/*
This file is part of Dash Ninja.
https://github.com/elbereth/dashninja-ctl
Dash Ninja is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Dash Ninja is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dash Ninja. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('DMN_SCRIPT') || !defined('DMN_CONFIG') || (DMN_SCRIPT !== true) || (DMN_CONFIG !== true)) {
die('Not executable');
}
define('DMN_VERSION','1.3.0');
xecho('dmnblockdegapper v'.DMN_VERSION."\n");
if ($argc == 2) {
if ($argv[1] == "test") {
$display = "testnet";
$testnet = 1;
$uname = 'tp2pool';
}
else {
$display = "mainnet";
$testnet = 0;
$uname = 'dnmonblk';
}
}
else {
xecho("Usage: ".$argv[0]." main|test\n");
die(0);
}
xecho('Retrieving last month block for '.$display.': ');
$result = dmn_cmd_get('/blocksgaps',array("interval"=>"P1M",'testnet'=>$testnet),$response);
if ($response['http_code'] == 200) {
echo "Fetched...";
$blocks = json_decode($result,true);
if ($blocks=== false) {
echo " Failed to JSON decode!\n";
die(200);
}
elseif (!is_array($blocks) || !array_key_exists('data',$blocks) || !is_array($blocks['data'])) {
echo " Incorrect data!\n";
die(202);
}
$blocks = $blocks['data'];
echo " OK (".count($blocks)." entries)\n";
}
else {
echo "Failed [".$response['http_code']."]\n";
if ($response['http_code'] != 500) {
$result = json_decode($result,true);
if ($result !== false) {
foreach($result['messages'] as $num => $msg) {
xecho("Error #$num: $msg\n");
}
}
}
die(201);
}
xecho("Finding gaps on $display:\n");
$prevblock = -1;
$gaps = array();
foreach($blocks as $blockindex => $block) {
if ($prevblock == -1) {
}
elseif (($prevblock-1) != $block) {
if (($prevblock - $block) > 2) {
xecho("Gap found, missing blocks ".($block+1)." to ".($prevblock-1)."\n");
$gaps[] = ($block+1)." ".($prevblock-1);
}
else {
xecho("Gap found, missing block ".($prevblock-1)."\n");
$gaps[] = ($prevblock-1);
}
}
$prevblock = $block;
}
if (count($gaps) == 0) {
xecho('No gaps found! (Yeah \o/)'."\n");
}
else {
xecho("De-gapping (".count($gaps)." gaps):\n");
foreach($gaps as $id => $gap) {
xecho(sprintf("#%'.03d",$id+1)." ($gap): ");
$output = array();
$result = 0;
$lastline = exec("/usr/bin/timeout 60 ".DMN_DIR."/dashblockretrieve $uname $gap",$output,$result);
if ($result == 0) {
echo "OK";
}
else {
echo "Error ($lastline)";
}
echo "\n";
}
}
?>