forked from elbereth/dashninja-ctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmnblockdegapper.script.inc.php
More file actions
executable file
·129 lines (114 loc) · 3.54 KB
/
dmnblockdegapper.script.inc.php
File metadata and controls
executable file
·129 lines (114 loc) · 3.54 KB
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
119
120
121
122
123
124
125
126
127
128
129
<?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 Foobar. 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.0.1');
xecho('dmnblockdegapper v'.DMN_VERSION."\n");
xecho('Retrieving nodes for this hub: ');
$result = dmn_cmd_get('/nodes',array(),$response);
if ($response['http_code'] == 200) {
echo "Fetched...";
$nodes = json_decode($result,true);
if ($nodes === false) {
echo " Failed to JSON decode!\n";
die(200);
}
elseif (!is_array($nodes) || !array_key_exists('data',$nodes) || !is_array($nodes['data'])) {
echo " Incorrect data!\n";
die(202);
}
$nodes = $nodes['data'];
echo " OK (".count($nodes)." 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('Retrieving last month block: ');
$result = dmn_api_get('/blocks',array("interval"=>"P1M"),$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']) || !array_key_exists('blocks',$blocks['data']) || !is_array($blocks['data']['blocks'])) {
echo " Incorrect data!\n";
die(202);
}
$blocks = $blocks['data']['blocks'];
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:\n");
$prevblock = -1;
$gaps = array();
foreach($blocks as $blockindex => $block) {
if ($prevblock == -1) {
}
elseif (($prevblock-1) != $block['BlockId']) {
if (($prevblock - $block['BlockId']) > 2) {
xecho("Gap found, missing blocks ".($block['BlockId']+1)." to ".($prevblock-1)."\n");
$gaps[] = ($block['BlockId']+1)." ".($prevblock-1);
}
else {
xecho("Gap found, missing block ".($prevblock-1)."\n");
$gaps[] = ($prevblock-1);
}
}
$prevblock = $block['BlockId'];
}
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(DMN_DIR."dashblockretrieve p2pool $gap",$output,$result);
if ($result == 0) {
echo "OK";
}
else {
echo "Error ($lastline)";
}
echo "\n";
}
}
?>