-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplorer.php
276 lines (260 loc) · 8.94 KB
/
explorer.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?php
// include required files
require_once __DIR__.'/modules/includes.php';
require_once __DIR__.'/modules/api-nodes.php';
include 'modules/header.php';
$ADDRESSIDENT = array("ban_");
$UNIT = "Banano";
?>
<?php
$is_addr = false;
$is_block = false;
$search = "";
if (isset($_GET["s"]) && $_GET["s"] !== "") {
$search = $_GET["s"];
foreach ($ADDRESSIDENT as $key => $val) {
if (substr($search, 0, strlen($val)) === $val) {
$is_addr = true;
}
}
if (!$is_addr) {
$is_block = true;
}
}
?>
<h2>Explorer</h2>
<form action="explorer.php" method="get">
<div class="row">
<div class="col-lg-8">
<input type="text" value="<?php echo $search?>" name="s" class="form-control" id="explore" aria-describedby="" placeholder="Search for...">
<small id="exploreHelp" class="form-text text-muted">Input an address or a transaction hash.</small>
</div>
<div class="col-lg-2">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</div>
</form>
<?php
// get curl handle
$ch = curl_init();
if (!$ch) {
myError('Could not initialize curl!');
}
// we have a valid curl handle here
// set some curl options
curl_setopt($ch, CURLOPT_URL, 'https://'.$nanoNodeRPCIP.':'.$nanoNodeRPCPort.$nanoNodeRPCPath);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
?>
<?php if($is_addr) : ?>
<?php
$history = getAddrHistory($ch, $search, 25);
$pending = getPendingBlocks($ch, $search, 10);
$dbconn = pg_connect("host=$pg_host dbname=$pg_dbname user=$pg_user password=$pg_password")
or die('Could not connect: ' . pg_last_error());
?>
<?php if($pending->blocks != "") : ?>
<table class="table table-dark table-hover">
<thead>
<tr>
<th scope="col">Pending Blocks</th>
</tr>
</thead>
<tbody>
<?php foreach($pending->blocks as $block): ?>
<tr><td><div class="truncatehash"><a href="?s=<?php echo $block; ?>"><?php echo $block; ?></a></div></td></tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<div class="table-responsive">
<table class="table table-dark table-hover">
<thead class="">
<tr>
<th scope="col" >Type</th>
<th scope="col" >Account</th>
<th scope="col" >Amount</th>
<th scope="col" >UTC Time</th>
<th scope="col" >Hash</th>
</tr>
</thead>
<tbody>
<?php foreach($history->history as $block): ?>
<?php
$timestamp = getTimestamp($block->hash);
if ($timestamp != 0) {
$date = date('H:i d-m-Y', $timestamp/1000);
} else {
$date = "N/A";
}
if ($block->type === "send") {
$account = "to " . $block->destination;
$accountLink = $block->destination;
$amount = "-" . rawToMnano($block->amount) . " " . $UNIT;
$colorclass = "red";
}
if ($block->type === "receive") {
$account = "from " . $block->account;
$accountLink = $block->account;
$amount = "+" . rawToMnano($block->amount) . " " . $UNIT;
$colorclass = "green";
}
if ($block->type === "change") {
$account = "to " . $block->representative;
$accountLink = $block->representative;
$amount = "N/A";
$colorclass = "blue";
}
if ($block->type === "open") {
$account = "from " . $block->account;
$accountLink = $block->account;
$amount = "+" . rawToMnano($block->amount) . " " . $UNIT;
$colorclass = "green";
}
if ($block->type === "state") {
if ($block->subtype === "send") {
$complete = reset(getBlock($ch, $block->hash)->blocks);
$destination = json_decode($complete->contents)->link_as_account;
$account = "to " . $destination;
$accountLink = $destination;
$amount = "-" . rawToMnano($block->amount) . " " . $UNIT;
$colorclass = "red";
}
if ($block->subtype === "open") {
$sender = getBlockAccount($block->link, $ch);
$account = "from " . $sender;
$accountLink = $sender;
$amount = "+" . rawToMnano($block->amount) . " " . $UNIT;
$colorclass = "green";
}
if ($block->subtype === "receive") {
$sender = getBlockAccount($block->link, $ch);
$account = "from " . $sender;
$accountLink = $sender;
$amount = "+" . rawToMnano($block->amount) . " " . $UNIT;
$colorclass = "green";
}
if ($block->subtype === "change") {
$account = "to " . $block->representative;
$accountLink = $block->representative;
$amount = "N/A";
$colorclass = "blue";
}
$block->type = "state (".$block->subtype.")";
}
?>
<tr>
<td class="no-wrap <?php echo $colorclass; ?>"><?php echo $block->type; ?></td>
<td class="no-wrap"><a href="?s=<?php echo $accountLink; ?>"><?php echo $account; ?></a></td>
<td class="no-wrap <?php echo $colorclass; ?>"><?php echo $amount; ?></td>
<td class="no-wrap"><?php echo $date?></td>
<td><div class="truncatehash"><a href="?s=<?php echo $block->hash; ?>"><?php echo $block->hash; ?></a></div></td>
</tr>
<?php endforeach; ?>
<?php
pg_close($dbconn);
?>
</tbody>
</table>
</div>
<?php endif; ?>
<?php if($is_block) : ?>
<?php
$fullblock = reset(getBlock($ch, $search)->blocks);
?>
<?php endif ?>
<?php if($fullblock) : ?>
<?php
$block = json_decode($fullblock->contents);
$dbconn = pg_connect("host=$pg_host dbname=$pg_dbname user=$pg_user password=$pg_password")
or die('Could not connect: ' . pg_last_error());
$timestamp = getTimestamp($search);
pg_close($dbconn);
if ($block->type === "state") {
$block->type = "state (" .blockSubType($block, $fullblock) . ")";
}
if ($block->type === "state (receive)" or $block->type === "state (open)") {
$block->source = $block->link;
}
if ($block->type === "state (send)") {
$block->destination = $block->link_as_account;
}
if (strpos($block->type, 'send') !== false) {
$colorclass = "red";
}
if (strpos($block->type, 'receive') !== false) {
$colorclass = "green";
}
if (strpos($block->type, 'change') !== false) {
$colorclass = "blue";
}
?>
<ul class="list-group col-lg-8">
<h3>Block Information</h3>
<li class="list-group-item">
Type
<span class="float-right <?php echo $colorclass; ?>"><?php echo $block->type; ?></span>
</li>
<?php if($block->type === "change" or $block->type === "state (change)") : ?>
<li class="list-group-item">
Changed Account
<span class="float-right truncate"><a href="?s=<?php echo $fullblock->block_account; ?>"><?php echo $fullblock->block_account; ?></a></span>
</li>
<li class="list-group-item">
To
<span class="float-right truncate"><a href="?s=<?php echo $block->representative; ?>"><?php echo $block->representative; ?></a></span>
</li>
<?php endif ?>
<?php if($block->type === "send" or $block->type === "state (send)") : ?>
<li class="list-group-item">
Amount
<span class="float-right <?php echo $colorclass; ?>">-<?php echo rawToMnano($fullblock->amount) . " " . $UNIT; ?></span>
</li>
<li class="list-group-item">
From
<span class="float-right truncate"><a href="?s=<?php echo $fullblock->block_account; ?>"><?php echo $fullblock->block_account; ?></a></span>
</li>
<li class="list-group-item">
To
<span class="float-right truncate"><a href="?s=<?php echo $block->destination; ?>"><?php echo $block->destination; ?></a></span>
</li>
<?php endif ?>
<?php if($block->type === "receive" or $block->type === "open" or $block->type === "state (receive)" or $block->type === "state (open)") : ?>
<li class="list-group-item">
Amount
<span class="float-right <?php echo $colorclass; ?>">+<?php echo rawToMnano($fullblock->amount) . " " . $UNIT; ?></span>
</li>
<li class="list-group-item">
From
<span class="float-right truncate"><a href="?s=<?php echo $fullblock->source_account; ?>"><?php echo $fullblock->source_account; ?></a></span>
</li>
<li class="list-group-item">
To
<span class="float-right truncate"><a href="?s=<?php echo $fullblock->block_account; ?>"><?php echo $fullblock->block_account; ?></a></span>
</li>
<li class="list-group-item">
Source
<span class="float-right truncate"><a href="?s=<?php echo $block->source; ?>"><?php echo $block->source; ?></a></span>
</li>
<?php endif ?>
<?php if($block->type !== "open" && $block->type !== "state (open)") : ?>
<li class="list-group-item">
Previous
<span class="float-right truncate"><a href="?s=<?php echo $block->previous; ?>"><?php echo $block->previous; ?></a></span>
</li>
<?php endif ?>
<li class="list-group-item">
Work
<span class="float-right"><?php echo $block->work; ?></span>
</li>
<li class="list-group-item">
Signature
<span class="float-right truncate"><?php echo $block->signature; ?></span>
</li>
<li class="list-group-item">
UTC Time
<span class="float-right truncate"><?php echo date('H:i d-m-Y', $timestamp/1000); ?></span>
</li>
</ul>
<?php endif;; ?>
<?php include 'modules/footer.php'; ?>