1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-13 19:52:18 +00:00
ton/crypto/smartcont/wallet-v2.fif

75 lines
3.1 KiB
Text
Raw Normal View History

2019-10-09 16:00:54 +00:00
#!/usr/bin/fift -s
"TonUtil.fif" include
2019-12-05 12:51:51 +00:00
"GetOpt.fif" include
2019-12-05 12:51:51 +00:00
{ show-options-help 1 halt } : usage
2019-12-05 12:51:51 +00:00
"" =: comment // comment for simple transfers
true =: allow-bounce
false =: force-bounce
3 =: send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
60 =: timeout // external message expires in 60 seconds
2020-03-02 13:52:55 +00:00
variable extra-currencies
{ extra-currencies @ cc+ extra-currencies ! } : extra-cc+!
2019-12-05 12:51:51 +00:00
begin-options
2020-03-02 13:52:55 +00:00
" <filename-base> <dest-addr> <seqno> <amount> [-x <extra-amount>*<extra-currency-id>] [-n|-b] [-t<timeout>] [-B <body-boc>] [-C <comment>] [<savefile>]" +cr +tab
2019-12-05 12:51:51 +00:00
+"Creates a request to advanced wallet created by new-wallet-v2.fif, with private key loaded from file <filename-base>.pk "
+"and address from <filename-base>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)"
2019-12-12 15:16:25 +00:00
disable-digit-options generic-help-setopt
2019-12-05 12:51:51 +00:00
"n" "--no-bounce" { false =: allow-bounce } short-long-option
"Clears bounce flag" option-help
"b" "--force-bounce" { true =: force-bounce } short-long-option
"Forces bounce flag" option-help
2020-03-02 13:52:55 +00:00
"x" "--extra" { $>xcc extra-cc+! } short-long-option-arg
"Indicates the amount of extra currencies to be transfered" option-help
2019-12-05 12:51:51 +00:00
"t" "--timeout" { parse-int =: timeout } short-long-option-arg
"Sets expiration timeout in seconds (" timeout (.) $+ +" by default)" option-help
"B" "--body" { =: body-boc-file } short-long-option-arg
"Sets the payload of the transfer message" option-help
"C" "--comment" { =: comment } short-long-option-arg
"Sets the comment to be sent in the transfer message" option-help
"m" "--mode" { parse-int =: send-mode } short-long-option-arg
"Sets transfer mode (0..255) for SENDRAWMSG (" send-mode (.) $+ +" by default)"
option-help
"h" "--help" { usage } short-long-option
"Shows a help message" option-help
parse-options
2019-12-05 12:51:51 +00:00
$# dup 4 < swap 5 > or ' usage if
5 :$1..n
true constant bounce
$1 =: file-base
2019-12-05 12:51:51 +00:00
$2 bounce parse-load-address force-bounce or allow-bounce and =: bounce 2=: dest_addr
$3 parse-int =: seqno
2020-03-02 13:52:55 +00:00
$4 $>cc extra-cc+! extra-currencies @ 2=: amount
2019-12-05 12:51:51 +00:00
$5 "wallet-query" replace-if-null =: savefile
file-base +".addr" load-address
2dup 2constant wallet_addr
."Source wallet address = " 2dup .addr cr 6 .Addr cr
file-base +".pk" load-keypair nip constant wallet_pk
2019-12-05 12:51:51 +00:00
def? body-boc-file { @' body-boc-file file>B B>boc } { comment simple-transfer-body } cond
constant body-cell
2020-03-02 13:52:55 +00:00
."Transferring " amount .GR+cc ."to account "
dest_addr 2dup bounce 7 + .Addr ." = " .addr
."seqno=0x" seqno x. ."bounce=" bounce . cr
."Body of transfer message is " body-cell <s csr. cr
// create a message
2020-03-02 13:52:55 +00:00
<b b{01} s, bounce 1 i, b{000} s, dest_addr Addr, amount Gram+cc, 0 9 64 32 + + u,
body-cell <s 2dup 1 s-fits-with? not rot over 1 i, -rot { drop body-cell ref, } { s, } cond
b>
<b seqno 32 u, now timeout + 32 u, send-mode 8 u, swap ref, b>
dup ."signing message: " <s csr. cr
dup hashu wallet_pk ed25519_sign_uint
<b b{1000100} s, wallet_addr addr, 0 Gram, b{00} s,
swap B, swap <s s, b>
dup ."resulting external message: " <s csr. cr
2 boc+>B dup Bx. cr
savefile +".boc" tuck B>file
."Query expires in " timeout . ."seconds" cr
."(Saved to file " type .")" cr