Counts shielded outputs in hush v3 blocks
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.

84 lines
1.9 KiB

#!/usr/bin/perl
#
# Copright (c) 2021 Jahway603 & The Hush Developers under GPLv3 License
#
# forked from https://github.com/ChileBob/ShieldedOutputs
# Copyright (c) 2021 ChileBob under MIT License
#
package common;
use strict;
use warnings;
use Data::Dumper;
use JSON;
use Getopt::Long;
my $node_client = 'hush-cli'; # hush-cli client
my $block_height = 699000; # start block unless changed with --block
my $version = "0.1";
my $print_version;
# Command line options
GetOptions ("block=i" => \$block_height,
"version" => \$print_version);
if($print_version) {
print "ShieldedOutputs - Hush Remix Version $version\n";
exit();
}
my $blockchaininfo = node_cli('getblockchaininfo');
print "Block\tEpoch\tShieldedOutputs\n";
while ( $block_height < $blockchaininfo->{'blocks'} ) {
my $block = node_cli("getblock $block_height 2");
my $shielded_outputs = 0;
foreach my $txn ( @{ $block->{'tx'} } ) {
if ($txn->{'vShieldedOutput'}) { # shielded outputs
$shielded_outputs += scalar @{$txn->{'vShieldedOutput'}};
}
}
print "$block_height\t$block->{'time'}\t$shielded_outputs\n";
$block_height++;
}
#######################################################################################################################################
#
# Safely parse JSON string
#
sub read_json {
my ($raw) = @_;
eval { decode_json($raw) }; # eval first, bad JSON kills puppies
if (!$@) {
return(decode_json($raw));
}
}
#############################################################################################################################################################################
#
# query node client, return JSON
#
sub node_cli {
my ($command, $data) = @_;
my $response = qx{$node_client $command 2>/dev/null};
my $json = read_json($response);
if ($json) {
return($json);
}
}