diff --git a/bin/walker.pl b/bin/walker.pl index 3065d77903e7d102d246fc5edd05b173a2a72383..038369fdf55d3385c9e287f385a137f09c4180ed 100755 --- a/bin/walker.pl +++ b/bin/walker.pl @@ -6,7 +6,6 @@ use IO::File; use Math::BigInt; use Carp; $Carp::Verbose = 1; -my $verbose = 0; die "\$BFAHOME not set. Did you source bfa/bin/env ?\n" unless exists $ENV{BFAHOME}; @@ -15,6 +14,11 @@ chdir "$ENV{BFAHOME}" or die $!; package tools; my $rpcport; my $ua = LWP::UserAgent->new; +our $CSI = "\x1b["; +our $clearEOS = "${CSI}J"; +our $up = "${CSI}A"; +our $red = "${CSI}41m"; +our $normal = "${CSI}m"; sub new { @@ -208,6 +212,12 @@ sub number return hex( $_[0]->result->{'number'} ); } +sub td +{ + return if not exists $_[0]->result->{'totalDifficulty'}; + return hex( $_[0]->result->{'totalDifficulty'} ); +} + sub timestamp { return if not exists $_[0]->result->{'timestamp'}; @@ -232,6 +242,18 @@ sub nonce return lc $_[0]->result->{'nonce'}; } +sub hash +{ + return if not exists $_[0]->result->{'hash'}; + return lc $_[0]->result->{'hash'}; +} + +sub parentHash +{ + return if not exists $_[0]->result->{'parentHash'}; + return lc $_[0]->result->{'parentHash'}; +} + sub extradata { return if not exists $_[0]->result->{'extraData'}; @@ -326,23 +348,66 @@ sub get($;$) return $block; } -package main; +sub delete_cache +{ + my ($self) = @_; + unlink sprintf('cache/block.0x%x', $self->number); +} + +sub print +{ + print scalar($_[0]->sprint),"\n"; +} my $nonce_xlate = { '0x0000000000000000' => 'SEALER_REM', '0xffffffffffffffff' => 'SEALER_ADD', }; -while ( defined $ARGV[0] and $ARGV[0] =~ m/^-/ ) +sub sprint { - my $arg = shift; - $verbose = 1 if $arg eq '-v'; + my ( $self ) = @_; + my $txt = ''; + my $lines = 1; + my @sealers = $self->sealers; + if ( @sealers ) + { + $txt = sprintf "\r${tools::clearEOS}"; + $txt = ''; + for my $sealer ( @sealers ) + { + $txt.= sprintf + "Confirming signer at epoch: 0x%s with an ETH balance of %s\n", + $sealer, + balance->new->get($sealer, $self->number); + $lines++; + } + } + $txt .= sprintf + '%s block:%s gaslimit:%s td:%d Vanity: %s', + tools::gmt($self->timestamp), + $self->number, + $self->gasLimit, + $self->td, + tools::hex2string($self->vanity); + if ( $self->miner !~ /^0x0{40}$/o ) + { + # we have auth or drop + my $nonce = $self->nonce; + $nonce = $nonce_xlate->{$nonce} if exists $nonce_xlate->{$nonce}; + $txt .= sprintf " %s %s", $nonce, $self->miner; + } + return wantarray ? ($txt, $lines) : $txt; } +package main; + $| = 1; mkdir 'cache'; -my $number = shift || tools::cat 'walker.block.last' || 'earliest'; -my $tools = tools->new; +my $number = shift || tools::cat 'walker.block.last' || 'earliest'; +my $tools = tools->new; +my @blks; +my $parent; while ( 1 ) { @@ -352,34 +417,17 @@ while ( 1 ) $tools->wait(); next; } - my $txt = sprintf - '%s block:%s gaslimit:%s Vanity: %s', - tools::gmt($block->timestamp), - $block->number, - $block->gasLimit, - tools::hex2string($block->vanity); - if ( $block->miner !~ /^0x0{40}$/ ) - { - # we have auth or drop - my $nonce = $block->nonce; - $nonce = $nonce_xlate->{$nonce} if exists $nonce_xlate->{$nonce}; - $txt .= sprintf " %s %s\n", $nonce, $block->miner; - } - else + $parent = block::get($block->number-1) if not defined $parent and $block->number > 1; + if ( defined $parent and $parent->hash ne $block->parentHash ) { - my @sealers = $block->sealers; - if ( @sealers ) - { - printf "\r%s%c[J\n", $txt, 27; - $txt = ''; - for my $sealer ( @sealers ) - { - printf "Confirming signer at epoch: 0x%s with an ETH balance of %s\n", $sealer, balance->new->get($sealer, $block->number); - } - } + printf "\r${tools::red}%s${tools::normal}\n", scalar($parent->sprint); + ($parent, $block, $number) = (undef, $parent, $number-1); + $block->delete_cache; + next; } - printf "\r%s%c[J", $txt, 27 if $txt ne ''; -#$block->signature; + shift @blks while scalar @blks > 32; + push @blks, $block; + $block->print; $number = $block->number + 1; - print "\n" if $verbose; + $parent = $block; }