|
|
@ -0,0 +1,90 @@ |
|
|
|
#!/usr/bin/perl |
|
|
|
|
|
|
|
BEGIN { if (-e $ENV{SITE}.'/lib') { use lib $ENV{SITE}.'/lib'; } } |
|
|
|
|
|
|
|
|
|
|
|
use config; |
|
|
|
use TXPOOL qw(saveTxPool); |
|
|
|
use CAStore qw(CASWrite); |
|
|
|
use ECKeys qw(ecsign ecverif getPeerid loadKeys); |
|
|
|
use YAML::Syck qw(LoadFile Dump DumpFile); |
|
|
|
|
|
|
|
my $keys = loadKeys(); |
|
|
|
foreach my $id (keys %{$keys}) { |
|
|
|
my $pub = $keys->{$id}{public}; |
|
|
|
$keys->{$pub}{id} = $id; |
|
|
|
} |
|
|
|
#printf "--- keys %s...\n",Dump($keys); |
|
|
|
|
|
|
|
my $txf = shift; |
|
|
|
|
|
|
|
|
|
|
|
my $tx = LoadFile($txf); |
|
|
|
|
|
|
|
my %signatures = (); |
|
|
|
my %delta = (); |
|
|
|
foreach my $sign (@{$tx->{signatures}}) { |
|
|
|
my ($pub) = keys %{$sign}; |
|
|
|
$signatures{$pub} = $sign->{$pub}; |
|
|
|
$delta{$pub} = 0; |
|
|
|
} |
|
|
|
printf "--- signatures %s...\n",Dump(\%signatures); |
|
|
|
foreach my $in (@{$tx->{inputs}}) { |
|
|
|
my ($pub) = keys %{$in}; |
|
|
|
my $value = $in->{$pub}; |
|
|
|
$valuein += $value; |
|
|
|
$delta{$pub} -= $value; |
|
|
|
printf "in: %s from %s (%s)\n",$value,$pub,$keys->{$pub}{id}; |
|
|
|
} |
|
|
|
foreach my $out (@{$tx->{outputs}}) { |
|
|
|
my ($pub) = keys %{$out}; |
|
|
|
my $value = $out->{$pub}; |
|
|
|
$valueout += $value; |
|
|
|
$delta{$pub} += $value; |
|
|
|
printf "out: %s to %s (%s)\n",$value,$pub,$keys->{$pub}{id}; |
|
|
|
} |
|
|
|
if ($valuein != $valueout) { |
|
|
|
printf "error: i:%s != o:%s\n",$valuein,$valueout; |
|
|
|
} |
|
|
|
|
|
|
|
foreach my $pub (keys %delta) { |
|
|
|
my $value = -$delta{$pub}; |
|
|
|
if (exists $signatures{$pub}) { |
|
|
|
my $id = (exists $keys->{$pub}{id}) ? $keys->{$pub}{id} : $pub; |
|
|
|
my $key58 = (exists $keys->{$id}{public}) ? $keys->{$id}{public} : $pub; |
|
|
|
my $msg = qq'["$pub","$value","$tx->{payload}"]'; |
|
|
|
printf "msg: %s\n",$msg; |
|
|
|
if (defined $signatures{$pub}) { |
|
|
|
my $sig = $signatures{$pub}; |
|
|
|
my $sigok = &ecverif($key58,$sig,$msg); |
|
|
|
printf "signature for %s (%s) ? %s\n",$id,$key58,($sigok)?'ok':'invalid'; |
|
|
|
if (! $sigok) { |
|
|
|
my $sig = &ecsign($id,$msg); |
|
|
|
printf "sig: %s: %s (corrected)\n",$id,$sig; |
|
|
|
$signatures{$pub} = $sig; |
|
|
|
} |
|
|
|
} else { |
|
|
|
my $sig = &ecsign($id,$msg); |
|
|
|
printf "sig: %s: %s\n",$id,$sig; |
|
|
|
$signatures{$pub} = $sig; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach my $sign (@{$tx->{signatures}}) { |
|
|
|
my ($pub) = keys %{$sign}; |
|
|
|
$sign->{$pub} = $signatures{$pub}; |
|
|
|
} |
|
|
|
|
|
|
|
printf "--- %s.sig: %s...\n",$txf,Dump($tx); |
|
|
|
DumpFile("$txf.sig",$tx); |
|
|
|
|
|
|
|
$tx->{nonce} = 3976914969180171529, |
|
|
|
my $txaddr = CASWrite('txpool',$tx,$tx->{nonce},'txpool',5); |
|
|
|
|
|
|
|
push @{$TXPOOL},$txaddr; |
|
|
|
&saveTxPool($TXPOOL); |
|
|
|
|
|
|
|
exit $?; |
|
|
|
|
|
|
|
|