forked from onryo/siona
Extremely Private HUSH and HAC explorer
https://explorer.hush.is
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.8 KiB
86 lines
2.8 KiB
#!/usr/bin/env perl
|
|
use strict;
|
|
use warnings;
|
|
use 5.014;
|
|
use JSON::Any;
|
|
$|=1;
|
|
|
|
# While Siona swims, we pave with bricks on the road she will run on...
|
|
my $STATS = {};
|
|
my $acname = $ENV{SIONA_ACNAME} || 'HUSH';
|
|
my $ticker = $acname == 'HUSH3' ? 'HUSH' : $acname;
|
|
my $domain = $ENV{SIONA_DOMAIN} || '$domain';
|
|
my $dir = shift || "/var/www/$domain/var/www/$domain/api";
|
|
my $getinfo = readfile("$dir/getinfo.json");
|
|
my $noprivacy = readfile("$dir/snapshots/snapshot.json");
|
|
my $template = readfile("/var/www/$domain/var/www/$domain/addresses/template.html");
|
|
my @symbols = qw/ BLOCKS CONNECTIONS TLS_CONNECTIONS TXCOUNT
|
|
PROTOCOLVERSION LONGESTCHAIN TIPTIME NOTARIZEDHASH
|
|
ADDRESS_DATA TOTAL_ADDRESSES TOTAL AVG UTXOS
|
|
/;
|
|
|
|
$STATS->{ADDRESS_DATA} = <<TABLE;
|
|
<table>
|
|
<tr>
|
|
<td style="font-size: 14px">Transparent Address</td>
|
|
<td style="font-size: 14px">Amount</td>
|
|
</tr>
|
|
TABLE
|
|
|
|
|
|
if ($noprivacy) {
|
|
my $j = JSON::Any->new;
|
|
my $o = $j->decode($noprivacy);
|
|
|
|
my $addresses = $o->{addresses};
|
|
$STATS->{AVG} = $o->{average};
|
|
$STATS->{TOTAL_ADDRESSES} = $o->{total_addresses};
|
|
$STATS->{UTXOS} = $o->{utxos};
|
|
$STATS->{TOTAL} = $o->{total};
|
|
|
|
for my $a (@$addresses) {
|
|
my ($addr,$amount) = ($a->{addr}, $a->{amount});
|
|
$STATS->{ADDRESS_DATA} .= <<ROW;
|
|
<tr>
|
|
<td style="font-size: 14px">$addr</td>
|
|
<td style="font-size: 14px">$amount $ticker</td>
|
|
</tr>
|
|
ROW
|
|
}
|
|
$STATS->{ADDRESS_DATA} .= "</table>";
|
|
|
|
for my $s (@symbols) {
|
|
if($s && $STATS->{$s}) { $template =~ s/#$s#/$STATS->{$s}/ge }
|
|
}
|
|
say $template;
|
|
}
|
|
|
|
sub readfile {
|
|
my $file = shift;
|
|
my $data = "";
|
|
open(my $fh, '<', $file) or die $!;
|
|
while(<$fh>){
|
|
$data.=$_;
|
|
# getinfo
|
|
if(m/"tls_connections": (\d+)/){ $STATS->{TLS_CONNECTIONS} ||= $1; }
|
|
if(m/"connections": (\d+)/){ $STATS->{CONNECTIONS} ||= $1; }
|
|
if(m/"blocks": (\d+)/){ $STATS->{BLOCKS} ||= $1; }
|
|
if(m/"notarized": (\d+)/){ $STATS->{NOTARIZED} ||= $1; }
|
|
if(m/"protocolversion": (\d+)/){ $STATS->{PROTOCOLVERSION} ||= $1; }
|
|
if(m/"longestchain": (\d+)/){ $STATS->{LONGESTCHAIN} ||= $1; }
|
|
if(m/"notarizedhash": "([a-z0-9]+)"/){ $STATS->{NOTARIZEDHASH} ||= $1; }
|
|
if(m/"tiptime": (\d+)/){ $STATS->{TIPTIME} ||= localtime($1) . "<!-- $1 -->"; }
|
|
# coinsupply
|
|
if(m/"zfunds": (\d+\.\d+)/){ $STATS->{ZFUNDS} ||= $1; }
|
|
if(m/"total": (\d+\.\d+)/){ $STATS->{SUPPLY} ||= $1; }
|
|
# getmininginfo
|
|
if(m/"difficulty": (\d+)/){ $STATS->{DIFFICULTY} ||= $1; }
|
|
if(m/"networksolps": (\d+)/){ $STATS->{NETWORKSOLPS} ||= sprintf("%.2f", $1 / 1_000_000); }
|
|
# getchaintxstats
|
|
if(m/"txcount": (\d+)/){ $STATS->{TXCOUNT} ||= $1; }
|
|
if(m/"txrate": (\d+\.\d+)/){ $STATS->{TXRATE} ||= sprintf("%.4f",$1*60); }
|
|
if(m/"window_final_block_hash": "([a-z0-9]+)"/){ $STATS->{BLOCKHASH} ||= $1; }
|
|
}
|
|
close($fh);
|
|
return $data;
|
|
}
|
|
|