Ton

Форк
0
/
wallet.fif 
78 строк · 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
variable extra-currencies
12
{ extra-currencies @ cc+ extra-currencies ! } : extra-cc+!
13

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

38
$# dup 4 < swap 5 > or ' usage if
39
5 :$1..n
40
true =: bounce
41
$1 =: file-base
42
$2 bounce parse-load-address allow-bounce and force-bounce or =: bounce 2=: dest_addr
43
$3 parse-int =: seqno
44
$4 $>cc extra-cc+! extra-currencies @ 2=: amount
45
$5 "wallet-query" replace-if-null =: savefile
46
allow-bounce not force-bounce and abort"cannot have bounce flag both set and cleared"
47
// "" 1 { 69091 * 1+ 65535 and tuck 2521 / 65 + hold swap } 1000 times drop =: comment
48

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

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

57
def? init-file { @' init-file file>B B>boc <s b{11} swap |_ } { b{0} } cond
58
=: state-init
59

60
."Transferring " amount .GR+cc ."to account "
61
dest_addr 2dup bounce 7 + .Addr ." = " .addr 
62
."seqno=0x" seqno x. ."bounce=" bounce . cr
63
."Body of transfer message is " body-cell <s csr. cr
64
."StateInit is " state-init 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 8 64 32 + + u, state-init s,
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 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
."(Saved to file " type .")" cr
79

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

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

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

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