Ton

Форк
0
/
highload-wallet-v2-one.fif 
112 строк · 4.4 Кб
1
#!/usr/bin/fift -s
2
"TonUtil.fif" include
3
"GetOpt.fif" include
4

5
{ show-options-help 1 halt } : usage
6

7
"" =: comment  // comment for simple transfers
8
true =: allow-bounce
9
false =: force-bounce
10
3 =: send-mode  // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
11
60 =: timeout   // external message expires in 60 seconds
12
variable extra-currencies
13
{ extra-currencies @ cc+ extra-currencies ! } : extra-cc+!
14

15
begin-options
16
     " <filename-base> <dest-addr> <subwallet-id> <amount> [-x <extra-amount>*<extra-currency-id>] [-n|-b] [-t<timeout>] [-B <body-boc>] [-C <comment>] [<savefile>]" +cr +tab
17
    +"Creates one request to highload wallet created by new-highload-wallet-v2.fif, with private key loaded from file <filename-base>.pk "
18
    +"and address from <filename-base><subwallet-id>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)"
19
    disable-digit-options generic-help-setopt
20
  "n" "--no-bounce" { false =: allow-bounce } short-long-option
21
    "Clears bounce flag" option-help
22
  "b" "--force-bounce" { true =: force-bounce } short-long-option
23
    "Forces bounce flag" option-help
24
  "x" "--extra" { $>xcc extra-cc+! } short-long-option-arg
25
    "Indicates the amount of extra currencies to be transfered" option-help
26
  "t" "--timeout" { parse-int =: timeout } short-long-option-arg
27
    "Sets expiration timeout in seconds (" timeout (.) $+ +" by default)" option-help
28
  "B" "--body" { =: body-boc-file } short-long-option-arg
29
    "Sets the payload of the transfer message" option-help
30
  "C" "--comment" { =: comment } short-long-option-arg
31
    "Sets the comment to be sent in the transfer message" option-help
32
  "m" "--mode" { parse-int =: send-mode } short-long-option-arg
33
    "Sets transfer mode (0..255) for SENDRAWMSG (" send-mode (.) $+ +" by default)"
34
    option-help
35
  "h" "--help" { usage } short-long-option
36
    "Shows a help message" option-help
37
parse-options
38

39
$# dup 4 < swap 5 > or ' usage if
40
5 :$1..n
41

42
true constant bounce
43
$1 =: file-base
44
$2 bounce parse-load-address force-bounce or allow-bounce and =: bounce 2=: dest_addr
45
$3 parse-int =: subwallet-id
46
$4 $>cc extra-cc+! extra-currencies @ 2=: amount
47
$5 "wallet-query" replace-if-null =: savefile
48
{ subwallet-id (.) $+ } : +subwallet
49

50
file-base +subwallet +".addr" load-address
51
2dup 2constant wallet_addr
52
."Source wallet address = " 2dup .addr cr 6 .Addr cr
53
file-base +".pk" load-keypair nip constant wallet_pk
54

55
def? body-boc-file { @' body-boc-file file>B B>boc } { comment simple-transfer-body } cond
56
constant body-cell
57

58
."Transferring " amount .GR+cc ."to account "
59
dest_addr 2dup bounce 7 + .Addr ." = " .addr 
60
."subwallet-id=0x" subwallet-id x.
61
."timeout=" timeout . ."bounce=" bounce . cr
62
."Body of transfer message is " body-cell <s csr. cr
63

64
variable orders   dictnew orders !
65
variable order#   order# 0!
66
// c --
67
{ <s order# @ dup 254 >= abort"more than 254 orders"
68
  orders @ 16 udict!+ not abort"cannot add order to dictionary"
69
  orders ! order# 1+!
70
} : add-order
71
// b body -- b'
72
{ tuck <s 2dup 1 s-fits-with? not rot over 1 i, -rot
73
  { drop swap ref, } { s, nip } cond
74
} : append-msg-body
75
// ng wc addr bounce body -- c
76
{ <b b{01} s, rot 1 i, b{000100} s, 2swap addr, rot Gram,
77
  0 9 64 32 + + 1+ u, swap append-msg-body b>
78
} : create-int-msg
79
// ng wc addr bnc --
80
{ ."Transferring " 3 roll .GR ."to account " 
81
  -rot 2dup 4 pick 7 + .Addr ." = " .addr ." bounce=" . cr
82
} : .transfer
83
// addr$ ng -- c
84
{ swap parse-smc-addr force-bounce or allow-bounce and  // ng wc addr bnc 
85
  2over 2over .transfer
86
  <b 0 32 u, b> create-int-msg
87
} : create-simple-transfer
88
// c m -- c'
89
{ <b swap 8 u, swap ref, b> } : create-order
90

91
// addr$ ng --
92
{ create-simple-transfer send-mode create-order add-order } : send
93
{ bl word bl word $>GR send } : SEND
94

95
// create internal message
96
<b b{01} s, bounce 1 i, b{000} s, dest_addr Addr, amount Gram+cc, 0 9 64 32 + + u,
97
  body-cell <s 2dup 1 s-fits-with? not rot over 1 i, -rot { drop body-cell ref, } { s, } cond
98
b>
99
send-mode create-order add-order
100

101
// create external message
102
now timeout + 32 << <b orders @ dict, b> hashu 32 1<<1- and + =: query_id
103
<b subwallet-id 32 i, query_id 64 u, orders @ dict, b>
104
dup ."signing message: " <s csr. cr
105
dup hashu wallet_pk ed25519_sign_uint
106
<b b{1000100} s, wallet_addr addr, 0 Gram, b{00} s,
107
   swap B, swap <s s, b>
108
dup ."resulting external message: " <s csr. cr
109
2 boc+>B dup Bx. cr
110
."Query_id is " query_id dup . ."= 0x" X. cr
111
savefile +".boc" tuck B>file
112
."(Saved to file " type .")" cr
113

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

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

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

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