Ton

Форк
0
/
new-restricted-wallet3.fif 
116 строк · 4.4 Кб
1
#!/usr/bin/fift -s
2
"TonUtil.fif" include
3
"Asm.fif" include
4
"GetOpt.fif" include
5

6
{ show-options-help 1 halt } : usage
7
0 =: restrict-mode
8
-1 =: wc
9
null =: subwallet-id
10
86400 =: expires-in
11
now =: start-at
12
// 0x11EF55AA =: subwallet-base
13

14
begin-options
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
33
parse-options
34
    
35
$# dup 3 < swap 4 > or ' usage if
36
4 :$1..n
37

38
$1 =: filename-base
39
$2 parse-pubkey =: PubKey
40
$3 $>GR =: amount
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
44

45
"new-" savefile-base $+ +".boc" =: savefile
46
savefile-base +".addr" =: savefile-addr
47

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
54

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
59

60
// D x t -- D'
61
{ <b rot Gram, swap rot 32 b>idict! not abort"cannot add value"
62
} : rdict-entry
63
{ 86400 * } : days*
64
{ 365 * days* } : years*
65
// balance -- dict
66
{ dictnew
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
72
} : make-rdict1
73
{ dictnew
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
80
} : make-rdict2
81
{ dictnew
82
  swap 31 -1<< rdict-entry
83
  0 0 rdict-entry
84
} : make-rdict0
85

86
amount
87
restrict-mode ?dup {
88
  1 = { make-rdict1 } { make-rdict2 } cond 
89
} { make-rdict0 } cond  
90
=: rdict
91

92
."Restrictions start at " start-at ._ .": " cr
93
rdict 32 { swap . ."-> " Gram@ .GR cr true } idictforeach cr
94

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
98
null // no libraries
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
106

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
110

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
114
2 boc+>B dup Bx. cr
115
savefile tuck B>file
116
."(Saved wallet creating query to file " type .")" cr
117

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.