Browse Source

Merge pull request 'Make block script more general and controlled by env vars' (#2) from hush/siona:dev into master

Reviewed-on: onryo/siona#2
pull/1/head
onryo 2 years ago
parent
commit
ec3fc123f3
  1. 41
      var/www/explorer.hush.land/bin/update_blocks_redis.pl

41
var/www/explorer.hush.land/bin/update_blocks_redis.pl

@ -15,12 +15,16 @@ my $j = JSON::Any->new;
#sleep 10; #sleep 10;
# While Siona swims, we pave with bricks on the road she will run on... # While Siona swims, we pave with bricks on the road she will run on...
my $dir = shift || '/var/www/explorer.hush.land/var/www/explorer.hush.land/api'; my $acname = $ENV{SIONA_ACNAME} || 'HUSH';
my $cli = "/home/hush/git/hush3/src/hush-cli"; 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 $getinfo = readfile("$dir/getinfo.json"); my $getinfo = readfile("$dir/getinfo.json");
my $mining = readfile("$dir/getmininginfo.json"); my $mining = readfile("$dir/getmininginfo.json");
my $template = readfile("/var/www/explorer.hush.land/var/www/explorer.hush.land/blocks/template.html"); my $blocksdir = "$basedir/blocks";
my $blocksdir = "/var/www/explorer.hush.land/var/www/explorer.hush.land/blocks/"; my $template = readfile("$blocksdir/template.html");
if($getinfo =~ m/"blocks": (\d+)/){ $STATS->{BLOCKS} ||= $1; } if($getinfo =~ m/"blocks": (\d+)/){ $STATS->{BLOCKS} ||= $1; }
if($getinfo =~ m/"tls_connections": (\d+)/){ $STATS->{TLS_CONNECTIONS} ||= $1; } if($getinfo =~ m/"tls_connections": (\d+)/){ $STATS->{TLS_CONNECTIONS} ||= $1; }
if($getinfo =~ m/"connections": (\d+)/){ $STATS->{CONNECTIONS} ||= $1; } if($getinfo =~ m/"connections": (\d+)/){ $STATS->{CONNECTIONS} ||= $1; }
@ -39,8 +43,9 @@ for my $h ($height-80 .. $height) {
#for my $h (910265 .. 910270) { #for my $h (910265 .. 910270) {
#last if($h < 0); #last if($h < 0);
my $thisminer = ""; my $thisminer = "";
# TODO: fix this garbage # TODO: actually look at the block reward for this height via
my $reward = $h > 340000 ? "3.125 HUSH" : "12.5 HUSH"; # the tx data from the very first txid in this block
my $reward = $h > 340000 ? "3.125 $acname" : "12.5 $acname";
my $block = get_block($h); my $block = get_block($h);
#die Dumper $block; #die Dumper $block;
my $time = $block->{time}; my $time = $block->{time};
@ -51,11 +56,10 @@ for my $h ($height-80 .. $height) {
my $hash = qx!$cli getblockhash $h!; my $hash = qx!$cli getblockhash $h!;
chomp $hash; chomp $hash;
my $root = "/var/www/explorer.hush.land"; my $blockdir = "$root/var/www/$domain/block/$hash";
my $blockdir = "$root/var/www/explorer.hush.land/block/$hash";
if (!-e "$root/block/$h") { if (!-e "$root/block/$h") {
# make /block/HEIGHT work # make /block/HEIGHT work
my $cmd = "ln -s $blockdir $root/var/www/explorer.hush.land/block/$h"; my $cmd = "ln -s $blockdir $root/var/www/$domain/block/$h";
qx{$cmd}; qx{$cmd};
warn $cmd; warn $cmd;
} }
@ -64,8 +68,8 @@ for my $h ($height-80 .. $height) {
my $cmd = "mkdir -p $blockdir"; my $cmd = "mkdir -p $blockdir";
qx{$cmd}; qx{$cmd};
warn $cmd; warn $cmd;
my $block_template_file = "/var/www/explorer.hush.land/var/www/explorer.hush.land/block/template.html"; my $block_template_file = "$basedir/block/template.html";
my $new_block_file = "/var/www/explorer.hush.land/var/www/explorer.hush.land/block/$hash/index.html"; my $new_block_file = "$blockdir/index.html";
# TODO: process template with block details # TODO: process template with block details
my $block_template = readfile($block_template_file); my $block_template = readfile($block_template_file);
$block_template =~ s/#BLOCKS#/$h/g; $block_template =~ s/#BLOCKS#/$h/g;
@ -79,8 +83,9 @@ for my $h ($height-80 .. $height) {
$block_template =~ s/#CHAINWORK#/$block->{chainwork}/ge; $block_template =~ s/#CHAINWORK#/$block->{chainwork}/ge;
$block_template =~ s/#MERKLEROOT#/$block->{merkleroot}/ge; $block_template =~ s/#MERKLEROOT#/$block->{merkleroot}/ge;
$block_template =~ s/#FINALSAPLINGROOT#/$block->{finalsaplingroot}/ge; $block_template =~ s/#FINALSAPLINGROOT#/$block->{finalsaplingroot}/ge;
# TODO # TODO: fix block reward
$block_template =~ s/#BLOCKREWARD#/3.125 HUSH/g; my $blockreward = "3.125 $acname";
$block_template =~ s/#BLOCKREWARD#/$blockreward/g;
$block_template =~ s/#BLOCKNONCE#/$block->{nonce}/ge; $block_template =~ s/#BLOCKNONCE#/$block->{nonce}/ge;
$block_template =~ s/#DIFFICULTY#/$block->{difficulty}/ge; $block_template =~ s/#DIFFICULTY#/$block->{difficulty}/ge;
$block_template =~ s/#NUM_TXS#/$numtx/g; $block_template =~ s/#NUM_TXS#/$numtx/g;
@ -116,9 +121,9 @@ HTML
next if $@; next if $@;
$TX->{$tx} = $o; $TX->{$tx} = $o;
my $tx_dir = "$root/var/www/explorer.hush.land/tx/$tx"; my $tx_dir = "$root/var/www/$domain/tx/$tx";
my $tx_file = "$root/var/www/explorer.hush.land/tx/$tx/index.html"; my $tx_file = "$root/var/www/$domain/tx/$tx/index.html";
my $tx_template_file = "$root/var/www/explorer.hush.land/tx/template.html"; my $tx_template_file = "$root/var/www/$domain/tx/template.html";
my $tx_template = readfile($tx_template_file); my $tx_template = readfile($tx_template_file);
my $txtime = localtime($o->{time}); my $txtime = localtime($o->{time});
#my $txsize = $o->{size} . " bytes"; #my $txsize = $o->{size} . " bytes";
@ -236,7 +241,7 @@ STUFF
} elsif ($txtype eq "Shielding") { } elsif ($txtype eq "Shielding") {
$stuff =<<STUFF; $stuff =<<STUFF;
$from ($valueBalanceThird HUSH) => zs1??? (shielding) $from ($valueBalanceThird $acname) => zs1??? (shielding)
STUFF STUFF
} elsif ($txtype eq "Notary") { } elsif ($txtype eq "Notary") {
@ -273,7 +278,7 @@ STUFF
<tr> <tr>
<td style="font-size: 14px">$stuff</td> <td style="font-size: 14px">$stuff</td>
<td style="font-size: 14px">$txtime</td> <td style="font-size: 14px">$txtime</td>
<td style="font-size: 14px">$valueBalance HUSH</td> <td style="font-size: 14px">$valueBalance $acname</td>
</tr> </tr>
</table> </table>
HTML HTML

Loading…
Cancel
Save