Browse Source

added transaction signatures

master
Gene F. Savelli 4 years ago
committed by Brooke L. Rediker
parent
commit
6d62d11f3b
  1. 90
      bin/signtx.pl
  2. BIN
      bin/websocketd
  3. 5
      curltest.sh
  4. 2
      init.sh
  5. 2
      lib
  6. 1
      salts/Genesis.yml
  7. 13
      tx.yml
  8. 14
      txpool/ZtxqdiZ8wwpEN5dScJf1byU6hjfBLoSrFmCrUVNJmqPc.yml
  9. 11
      txpool/txgen.yml

90
bin/signtx.pl

@ -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 $?;

BIN
bin/websocketd

5
curltest.sh

@ -8,5 +8,8 @@ curl http://127.0.0.1:8089/api/0.0/getchain
echo ''
curl -s http://127.0.0.1:8089/api/0.0/getblock?n=30
echo ''
curl -s http://127.0.0.1:8089/api/0.0/gettx?txaddr=Z123
curl -s http://127.0.0.1:8089/api/0.0/gettx?txaddr=ZTxB1ritiikyhjTXg28V7AjfqwkDyD8woJoz1yjC1T75
echo ''
curl -s http://127.0.0.1:8089/api/0.0/gettx?txaddr=ZtxqdiZ8wwpEN5dScJf1byU6hjfBLoSrFmCrUVNJmqPc
echo ''
cat txpool/tx.yml | sed -e "s/$/%0a/g" | curl -s -X POST http://127.0.0.1:8089/api/0.0/settx -d @-

2
init.sh

@ -1,6 +1,6 @@
#
i="$1:-1"
i="${1:-1}"
top=$(git rev-parse --show-toplevel)
export SITE=$top

2
lib

@ -1 +1 @@
Subproject commit dd522659e0e9a66aef4c6b22105847df427f2dea
Subproject commit 108a4b5442111374e51ecdc66992520aad233724

1
salts/Genesis.yml

@ -0,0 +1 @@
salt: 8163726776410142252

13
tx.yml

@ -1,13 +0,0 @@
--- # transaction
timestamp: 1623683269225552702
inputs:
- pub1: 50
- pub2: 20
payload: "This is an example of transaction"
outputs:
- pub3: 60
- pubfee: 10
signatures:
- pub1: sig1
- pub2: sig2
- pubfee: sig3

14
txpool/ZtxqdiZ8wwpEN5dScJf1byU6hjfBLoSrFmCrUVNJmqPc.yml

@ -0,0 +1,14 @@
---
inputs:
-
coinbase: 50
nonce: '3976914969180171529'
outputs:
-
miner: 50
payload: This is a coinbase transaction of 50 coins for the genesis block
pow: '3976914969180292365'
signatures:
-
coinbase: Zan1RjVTw7GPVyd7aygjWSrGCtX3M8CVRu3NAyqLC8MToNPE93ju4RrFFjunnbeTYnudR2gSKCamK82xjEfWEtGzGvTRDw25MG
timestamp: '1623683269225552702'

11
txpool/txgen.yml

@ -0,0 +1,11 @@
---
timestamp: '1623683269225552702'
inputs:
- coinbase: 50
nonce: '3976914969180171529'
outputs:
- Z21GdiEggiGa7TPNaqGY8coBy97LoRNpPVu9fxig75nstq: 50
payload: This is a coinbase transaction of 50 coins for the genesis block
pow: '3976914969180292365'
signatures:
- coinbase: Zan1RjVTw7GPVyd7aygjWSrGCtX3M8CVRu3NAyqLC8MToNPE93ju4RrFFjunnbeTYnudR2gSKCamK82xjEfWEtGzGvTRDw25MG
Loading…
Cancel
Save