@ -15,17 +15,14 @@ my $j = JSON::Any->new;
#sleep 10;
# While Siona swims, we pave with bricks on the road she will run on...
my $ acname = $ ENV { SIONA_ACNAME } || 'HUSH' ;
my $ ticker = $ acname eq 'HUSH3' ? 'HUSH' : $ acname ;
my $ domain = $ ENV { SIONA_DOMAIN } || 'explorer.hush.land' ;
my $ root = "/var/www/$domain" ;
my $ basedir = "/var/www/$domain/var/www/$domain" ;
my $ dir = shift || "$basedir/api" ;
my $ cli = $ ENV { SIONA_CLI } || "/home/hush/git/hush3/src/hush-cli" ;
my $ domain = $ ENV { DOMAIN } ;
my $ cli = $ ENV { CLI } ;
my $ arrakis = $ ENV { ARRAKIS } ;
my $ dir = $ ENV { DIR } ;
my $ getinfo = readfile ( "$dir/getinfo.json" ) ;
my $ mining = readfile ( "$dir/getmininginfo.json" ) ;
my $ blocksdir = "$basedir/blocks" ;
my $ template = readfile ( "$blocksdir/template.html" ) ;
my $ template = readfile ( "/var/www/$domain/blocks/template.html" ) ;
my $ blocksdir = "/var/www/$domain/blocks/" ;
if ( $ getinfo =~ m/"blocks": (\d+)/ ) { $ STATS - > { BLOCKS } || = $ 1 ; }
if ( $ getinfo =~ m/"tls_connections": (\d+)/ ) { $ STATS - > { TLS_CONNECTIONS } || = $ 1 ; }
if ( $ getinfo =~ m/"connections": (\d+)/ ) { $ STATS - > { CONNECTIONS } || = $ 1 ; }
@ -40,13 +37,12 @@ $STATS->{BLOCKS_TABLE} = "";
$ STATS - > { TX_TABLE } = "" ;
my $ mineraddress = "" ;
for my $ h ( $ height - 8 0 .. $ height ) {
for my $ h ( $ height - 5 0 .. $ height ) {
#for my $h (910265 .. 910270) {
#last if($h < 0);
my $ thisminer = "" ;
# TODO: actually look at the block reward for this height via
# the tx data from the very first txid in this block
my $ reward = $ h > 340000 ? "3.125 $ticker" : "12.5 $ticker" ;
# TODO: fix this garbage
my $ reward = $ h > 340000 ? "3.125 HUSH" : "12.5 HUSH" ;
my $ block = get_block ( $ h ) ;
#die Dumper $block;
my $ time = $ block - > { time } ;
@ -54,13 +50,14 @@ for my $h ($height-80 .. $height) {
my @ txs = @ { $ block - > { tx } } ;
my $ numtx = @ txs ;
# TODO: look on filesystem first? redis cache?
my $ hash = qx!$cli getblockhash $h! ;
my $ hash = qx!$cli -ac_name=$arrakis getblockhash $h! ;
chomp $ hash ;
my $ blockdir = "$root/var/www/$domain/block/$hash" ;
my $ root = "/var/www/$domain" ;
my $ blockdir = "$root/block/$hash" ;
if ( ! - e "$root/block/$h" ) {
# make /block/HEIGHT work
my $ cmd = "ln -s $blockdir $root/var/www/$domain/ block/$h" ;
my $ cmd = "ln -s $blockdir $root/block/$h" ;
qx{ $cmd } ;
warn $ cmd ;
}
@ -69,8 +66,8 @@ for my $h ($height-80 .. $height) {
my $ cmd = "mkdir -p $blockdir" ;
qx{ $cmd } ;
warn $ cmd ;
my $ block_template_file = "$basedir /block/template.html" ;
my $ new_block_file = "$blockdir /index.html" ;
my $ block_template_file = "/var/www/$domain /block/template.html" ;
my $ new_block_file = "/var/www/$domain/block/$hash /index.html" ;
# TODO: process template with block details
my $ block_template = readfile ( $ block_template_file ) ;
$ block_template =~ s/#BLOCKS#/$h/g ;
@ -84,9 +81,8 @@ for my $h ($height-80 .. $height) {
$ block_template =~ s/#CHAINWORK#/$block->{chainwork}/ge ;
$ block_template =~ s/#MERKLEROOT#/$block->{merkleroot}/ge ;
$ block_template =~ s/#FINALSAPLINGROOT#/$block->{finalsaplingroot}/ge ;
# TODO: fix block reward
my $ blockreward = "3.125 $ticker" ;
$ block_template =~ s/#BLOCKREWARD#/$blockreward/g ;
# TODO
$ block_template =~ s/#BLOCKREWARD#/3.125 HUSH/g ;
$ block_template =~ s/#BLOCKNONCE#/$block->{nonce}/ge ;
$ block_template =~ s/#DIFFICULTY#/$block->{difficulty}/ge ;
$ block_template =~ s/#NUM_TXS#/$numtx/g ;
@ -100,7 +96,7 @@ HTML
my $ txi = 0 ;
for my $ tx ( @ txs ) {
my $ json = qx!$cli getrawtransaction $tx 1! ;
my $ json = qx!$cli -ac_name=$arrakis getrawtransaction $tx 1! ;
# "vout": 0,
# "address": "RBHHGTQoULWb8gPD6Nj4fix6ov46hzzQMj",
# address is duplicated in the JSON of getrawtransaction !! fuck.
@ -122,9 +118,9 @@ HTML
next if $@ ;
$ TX - > { $ tx } = $ o ;
my $ tx_dir = "$root/var/www/$domain/ tx/$tx" ;
my $ tx_file = "$root/var/www/$domain/ tx/$tx/index.html" ;
my $ tx_template_file = "$root/var/www/$domain/ tx/template.html" ;
my $ tx_dir = "$root/tx/$tx" ;
my $ tx_file = "$root/tx/$tx/index.html" ;
my $ tx_template_file = "$root/tx/template.html" ;
my $ tx_template = readfile ( $ tx_template_file ) ;
my $ txtime = localtime ( $ o - > { time } ) ;
#my $txsize = $o->{size} . " bytes";
@ -242,7 +238,7 @@ STUFF
} elsif ( $ txtype eq "Shielding" ) {
$ stuff = << STUFF ;
$ from ( $ valueBalanceThird $ ticker ) = > zs1 ? ? ? ( shielding )
$ from ( $ valueBalanceThird HUSH ) = > zs1 ? ? ? ( shielding )
STUFF
} elsif ( $ txtype eq "Notary" ) {
@ -279,7 +275,7 @@ STUFF
<tr>
< td style = "font-size: 14px" > $ stuff </td>
< td style = "font-size: 14px" > $ txtime </td>
< td style = "font-size: 14px" > $ valueBalance $ ticker </td>
< td style = "font-size: 14px" > $ valueBalance HUSH </td>
</tr>
</table>
HTML
@ -318,9 +314,48 @@ HTML
;
}
my $ total_block_duration = 0 ;
for my $ duration ( @ block_durations ) {
if ( $ duration ne '--' ) {
$ total_block_duration += $ duration ;
}
}
$ avg_block_duration = $ total_block_duration / $ NUM_BLOCKS_TO_SHOW ;
if ( $ avg_block_duration > 0 ) {
$ avg_block_duration = sprintf "%.2f" , $ avg_block_duration ;
my $ blocktime = 75 ; # please Satoshi let this never change again
my $ deviation = 100 * ( $ avg_block_duration / $ blocktime ) ;
my $ word = ( $ avg_block_duration > $ blocktime ) ? "above" : "below" ;
if ( $ word eq 'above' ) { $ deviation -= 100 ; }
if ( $ word eq 'below' ) { $ deviation -= 100 ; }
$ word . = "!" if ( $ deviation >= 20 ) ;
my $ num_miners = keys % unique_miners ;
my $ longblock_multiplier = sprintf "%.2f" , $ longest_blocktime / $ avg_block_duration ;
$ deviation = sprintf "%.2f" , $ deviation ;
my $ tx_per_block = sprintf ( "%.2f" , $ total_txs / $ NUM_BLOCKS_TO_SHOW ) ;
$ STATS - > { BLOCKS_STATS } = << STATS ;
< table border = 1 >
<tr> < th colspan = 2 > Block Stats in the last $ NUM_BLOCKS_TO_SHOW blocks </th> </tr>
<tr> <td> Average Blocktime </td> < td align = center > $ avg_block_duration sec </td> </tr>
<tr> <td> Blocktime Deviation </td> < td align = center > $ deviation % $ word 75 sec </td> </tr>
<tr> <td> Longest Blocktime </td> < td align = center > $ longest_blocktime sec ( $ { longblock_multiplier } X average ) </td> </tr>
<tr> <td> Total Transactions </td> < td align = center > $ total_txs </td> </tr>
<tr> <td> Transactions Per Block </td> < td align = center > $ tx_per_block </td> </tr>
<tr> <td> Unique Miner Addresses </td> < td align = center > $ num_miners </td> </tr>
</table>
<br/>
STATS
}
sub get_raw {
my $ tx = shift ;
my $ cmd = "$cli getrawtransaction $tx 1" ;
my $ cmd = "$cli -ac_name=$arrakis getrawtransaction $tx 1" ;
warn $ cmd ;
my $ json = qx!$cmd! ;
# "vout": 0,
@ -383,7 +418,7 @@ sub get_block {
# create data if it's not there
if ( $ block =~ m/^HASH/ || length ( $ block ) == 0 ) {
my $ cmd = "$cli getblock $height" ;
my $ cmd = "$cli -ac_name=$arrakis getblock $height" ;
warn $ cmd ;
$ block = qx/$cmd/ ;
}
@ -411,4 +446,4 @@ sub readfile {
}
close ( $ fh ) ;
return $ data ;
}
}