5
{ ."usage: " $0 type ." <workchain-id> <giver-id> <amount> <interval> <min-complexity> <init-complexity> <max-complexity> [<filename-base>]" cr
6
."Creates a new proof-of-work testgiver with unique 32-bit identifier <giver-id> designed to deliver <amount> every <interval> seconds, with SHA256 hash complexity between 2**<min-complexity> and 2**<max-complexity>, with private key saved to or loaded from <filename-base>.pk" cr
7
."('pow-giver.pk' by default)" cr 1 halt
9
$# 7 - -2 and ' usage if
12
$1 parse-workchain-id =: wc // set workchain id from command line argument
13
$2 parse-int dup =: subwallet-id
14
0= abort"giver-id must be non-zero"
16
$4 parse-int dup =: interval
17
dup 24 ufits and 0= abort"invalid interval"
18
$5 parse-int dup =: min-cpl
19
1- 8 ufits not abort"invalid minimal log-complexity (must be 1..256)"
20
$6 parse-int dup =: init-cpl
21
1- 8 ufits not abort"invalid initial log-complexity (must be 1..256)"
22
$7 parse-int dup =: max-cpl
23
1- 8 ufits not abort"invalid maximal log-complexity (must be 1..256)"
24
$8 "pow-giver" replace-if-null =: file-base
26
min-cpl init-cpl > abort"initial complexity cannot be below minimal complexity"
27
max-cpl init-cpl < abort"initial complexity cannot exceed maximal complexity"
28
subwallet-id (.) 1 ' $+ does : +subwallet
30
."Creating new proof-of-work testgiver in workchain " wc .
31
."with unique giver id " subwallet-id . cr
32
."Designed to give " amount .GR ."approximately every " interval . ."seconds" cr
33
."Complexity (in SHA256 hashes): min=" min-cpl 1<< . ."init=" init-cpl 1<< . ."max=" max-cpl 1<< . cr
35
"auto/pow-testgiver-code.fif" include // code
36
{ 256 swap - 8 u, } : cpl,
37
<b 0 32 u, subwallet-id 32 u, // seqno wallet-id
38
file-base +".pk" load-generate-keypair constant wallet_pk B, // pubkey
39
newkeypair nip 16 B| drop B, // seed
40
256 init-cpl - 1<< 256 u, // pow_complexity
41
-1 32 i, // last_success
42
<b amount Gram, interval 32 u, max-cpl cpl, min-cpl cpl, b> ref,
45
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
46
dup ."StateInit: " <s csr. cr
47
dup hashu wc swap 2dup 2constant wallet_addr
48
."new PoW testgiver address = " 2dup .addr cr
49
2dup file-base +subwallet +".addr" save-address-verbose
50
."Non-bounceable address (for init): " 2dup 7 .Addr cr
51
."Bounceable address (for later access): " 6 .Addr cr
52
<b subwallet-id 32 u, -1 32 i, 0 32 u, b>
53
dup ."signing message: " <s csr. cr
54
dup hashu wallet_pk ed25519_sign_uint rot
55
<b b{1000100} s, wallet_addr addr, b{000010} s, swap <s s, b{0} s, swap B, swap <s s, b>
56
dup ."External message for initialization is " <s csr. cr
58
file-base +subwallet +"-query.boc" tuck B>file
59
."(Saved proof-of-work testgiver creating query to file " type .")" cr