6
{ show-options-help 1 halt } : usage
12
// 0x11EF55AA =: subwallet-base
15
" <creator-filename-base> <public-key> <amount> [-w<workchain>][-r<restrict-mode>][-i<subwallet-id>][-t<start-at>] [<savefile>]" +cr +tab
16
+"Creates a restricted lockup wallet v3 in the masterchain initialized by key loaded from <init-filename-base> "
17
+"and controlled by the private key corresponding to <public-key>" +cr +tab
18
+"and saves its initialization query into new-<savefile>.boc and its address into <savefile>.addr ('rwallet.addr' by default)"
19
disable-digit-options generic-help-setopt
20
"r" "--restrict-mode" { parse-int =: restrict-mode } short-long-option-arg
21
"Selects a standard restriction mode: 1 for 18-month lockup, 2 for 4-year lockup" option-help
22
"w" "--workchain" { parse-int =: wc } short-long-option-arg
23
"Selects a workchain (" wc (.) $+ +" by default)" option-help
24
"i" "--subwallet-id" { parse-int =: subwallet-id } short-long-option-arg
25
"Sets 32-bit subwallet id (workchain plus " subwallet-base (.) $+ +" by default)" option-help
26
"x" "--expires-in" { parse-int =: expires-in } short-long-option-arg
27
"Expiration time of the initialization message (" expires-in (.) $+
28
+" seconds by default)" option-help
29
"t" "--start-at" { dup "now" $= { drop now } { parse-int } cond =: start-at } short-long-option-arg
30
"Restriction start Unixtime (`now` by default)" option-help
31
"h" "--help" { usage } short-long-option
32
"Shows a help message" option-help
35
$# dup 3 < swap 4 > or ' usage if
39
$2 parse-pubkey =: PubKey
41
$4 "rwallet" replace-if-null =: savefile-base
42
subwallet-id subwallet-base wc + replace-if-null =: subwallet-id
43
expires-in now + =: expires-at
45
"new-" savefile-base $+ +".boc" =: savefile
46
savefile-base +".addr" =: savefile-addr
48
wc 8 fits not abort"invalid workchain id"
49
subwallet-id 32 fits not abort"invalid subwallet-id"
50
expires-at 32 ufits not abort"invalid expiration time"
51
start-at 32 ufits not abort"invalid restriction start time"
52
restrict-mode dup 0 < swap 2 > or abort"unknown restriction mode"
53
filename-base +".pk" load-keypair =: init_pk =: init_pubkey
55
."Creating new restricted lockup wallet v3 in workchain " wc .
56
."with restriction mode " restrict-mode . ."and nominal amount " amount .GR cr
57
."controlled by public key " PubKey .pubkey ." and initialized by public key " init_pubkey 256 B>u@ .pubkey cr
58
."(subwallet id is " subwallet-id ._ .")" cr
61
{ <b rot Gram, swap rot 32 b>idict! not abort"cannot add value"
64
{ 365 * days* } : years*
67
over 31 -1<< rdict-entry
68
over 3/4 */ 91 days* rdict-entry
69
over 1/2 */ 183 days* rdict-entry
70
swap 1/4 */ 365 days* rdict-entry
71
0 548 days* rdict-entry
74
over 31 -1<< rdict-entry
75
over .9 */ 0 rdict-entry
76
over .6775 */ 1 years* rdict-entry
77
over .445 */ 2 years* rdict-entry
78
swap .2225 */ 3 years* rdict-entry
79
0 4 years* 86400 + rdict-entry
82
swap 31 -1<< rdict-entry
88
1 = { make-rdict1 } { make-rdict2 } cond
92
."Restrictions start at " start-at ._ .": " cr
93
rdict 32 { swap . ."-> " Gram@ .GR cr true } idictforeach cr
95
// Create new restricted wallet v3; code taken from `auto/restricted-wallet3-code.fif`
96
"auto/restricted-wallet3-code.fif" include // code
97
<b 0 32 u, subwallet-id 32 i, init_pubkey B, PubKey 256 u, b> // data
99
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
100
dup ."StateInit: " <s csr. cr
101
dup =: StateInit hashu wc swap 2dup 2constant wallet_addr
102
."new wallet address = " 2dup .addr cr
103
2dup savefile-addr save-address-verbose
104
."Non-bounceable address (for init): " 2dup 7 .Addr cr
105
."Bounceable address (for later access): " 6 .Addr cr
107
<b subwallet-id 32 u, expires-at 32 u, 0 32 u, start-at 32 u, rdict dict, b>
108
dup ."signing message: " <s csr. cr
109
dup hashu init_pk ed25519_sign_uint
111
<b b{1000100} s, wallet_addr addr, b{000010} s, StateInit <s s,
112
b{0} s, swap B, swap <s s, b>
113
dup ."External message for initialization is " <s csr. cr
116
."(Saved wallet creating query to file " type .")" cr