Ton

Форк
0
/
wallet-v3.fif 
79 строк · 3.3 Кб
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> <seqno> <amount> [-x <extra-amount>*<extra-currency-id>] [-n|-b] [-t<timeout>] [-B <body-boc>] [-C <comment>] [<savefile>]" +cr +tab
17
    +"Creates a request to advanced wallet created by new-wallet-v3.fif, with private key loaded from file <filename-base>.pk "
18
    +"and address from <filename-base>.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 5 < swap 6 > or ' usage if
40
6 :$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 parse-int =: seqno
47
$5 $>cc extra-cc+! extra-currencies @ 2=: amount
48
$6 "wallet-query" replace-if-null =: savefile
49
subwallet_id (.) 1 ' $+ does : +subwallet
50

51
file-base +subwallet +".addr" dup file-exists? { drop file-base +".addr" } ifnot
52
load-address
53
2dup 2constant wallet_addr
54
."Source wallet address = " 2dup .addr cr 6 .Addr cr
55
file-base +".pk" load-keypair nip constant wallet_pk
56

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

60
."Transferring " amount .GR+cc ."to account "
61
dest_addr 2dup bounce 7 + .Addr ." = " .addr 
62
."subwallet_id=0x" subwallet_id x.
63
."seqno=0x" seqno x. ."bounce=" bounce . cr
64
."Body of transfer message is " body-cell <s csr. cr
65
  
66
// create a message
67
<b b{01} s, bounce 1 i, b{000} s, dest_addr Addr, amount Gram+cc, 0 9 64 32 + + u,
68
  body-cell <s 2dup 1 s-fits-with? not rot over 1 i, -rot { drop body-cell ref, } { s, } cond
69
b>
70
<b subwallet_id 32 u, now timeout + 32 u, seqno 32 u, send-mode 8 u, swap ref, b>
71
dup ."signing message: " <s csr. cr
72
dup hashu wallet_pk ed25519_sign_uint
73
<b b{1000100} s, wallet_addr addr, 0 Gram, b{00} s,
74
   swap B, swap <s s, b>
75
dup ."resulting external message: " <s csr. cr
76
2 boc+>B dup Bx. cr
77
savefile +".boc" tuck B>file
78
."Query expires in " timeout . ."seconds" cr
79
."(Saved to file " type .")" cr
80

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

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

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

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