2019-10-09 16:00:54 +00:00
|
|
|
#!/usr/bin/fift -s
|
2019-09-07 10:03:22 +00:00
|
|
|
"TonUtil.fif" include
|
2019-11-28 14:44:14 +00:00
|
|
|
"GetOpt.fif" include
|
2019-09-07 10:03:22 +00:00
|
|
|
|
2019-12-05 12:51:51 +00:00
|
|
|
{ show-options-help 1 halt } : usage
|
2019-11-28 14:44:14 +00:00
|
|
|
|
2019-10-05 17:21:24 +00:00
|
|
|
"" =: comment // comment for simple transfers
|
2019-11-18 18:15:14 +00:00
|
|
|
true =: allow-bounce
|
2019-12-05 12:51:51 +00:00
|
|
|
false =: force-bounce
|
2019-11-28 14:44:14 +00:00
|
|
|
3 =: send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
|
2019-09-07 10:03:22 +00:00
|
|
|
|
2019-11-28 14:44:14 +00:00
|
|
|
begin-options
|
2019-12-05 12:51:51 +00:00
|
|
|
" <filename-base> <dest-addr> <seqno> <amount> [-n|-b] [-B <body-boc>] [-C <comment>] [<savefile>]" +cr +tab
|
|
|
|
+"Creates a request to simple wallet created by new-wallet.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)"
|
|
|
|
generic-help
|
2019-11-28 14:44:14 +00:00
|
|
|
"n" "--no-bounce" { false =: allow-bounce } short-long-option
|
2019-12-05 12:51:51 +00:00
|
|
|
"Clears bounce flag" option-help
|
|
|
|
"b" "--force-bounce" { true =: force-bounce } short-long-option
|
|
|
|
"Forces bounce flag" option-help
|
2019-11-28 14:44:14 +00:00
|
|
|
"B" "--body" { =: body-boc-file } short-long-option-arg
|
2019-12-05 12:51:51 +00:00
|
|
|
"Sets the payload of the transfer message" option-help
|
2019-11-28 14:44:14 +00:00
|
|
|
"C" "--comment" { =: comment } short-long-option-arg
|
2019-12-05 12:51:51 +00:00
|
|
|
"Sets the comment to be sent in the transfer message" option-help
|
2019-11-28 14:44:14 +00:00
|
|
|
"m" "--mode" { parse-int =: send-mode } short-long-option-arg
|
2019-12-05 12:51:51 +00:00
|
|
|
"Sets transfer mode (0..255) for SENDRAWMSG (" send-mode (.) $+ +" by default)"
|
|
|
|
option-help
|
2019-11-28 14:44:14 +00:00
|
|
|
"h" "--help" { usage } short-long-option
|
2019-12-05 12:51:51 +00:00
|
|
|
"Shows a help message" option-help
|
2019-11-28 14:44:14 +00:00
|
|
|
parse-options
|
2019-09-07 10:03:22 +00:00
|
|
|
|
2019-11-28 14:44:14 +00:00
|
|
|
$# dup 4 < swap 5 > or ' usage if
|
|
|
|
5 :$1..n
|
|
|
|
true =: bounce
|
2019-09-16 08:06:04 +00:00
|
|
|
$1 =: file-base
|
2019-12-05 12:51:51 +00:00
|
|
|
$2 bounce parse-load-address allow-bounce and force-bounce or =: bounce 2=: dest_addr
|
2019-09-16 08:06:04 +00:00
|
|
|
$3 parse-int =: seqno
|
|
|
|
$4 $>GR =: amount
|
2019-12-05 12:51:51 +00:00
|
|
|
$5 "wallet-query" replace-if-null =: savefile
|
|
|
|
allow-bounce not force-bounce and abort"cannot have bounce flag both set and cleared"
|
2019-10-05 17:21:24 +00:00
|
|
|
// "" 1 { 69091 * 1+ 65535 and tuck 2521 / 65 + hold swap } 1000 times drop =: comment
|
2019-09-07 10:03:22 +00:00
|
|
|
|
|
|
|
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-10-05 17:21:24 +00:00
|
|
|
def? body-boc-file { @' body-boc-file file>B B>boc } { comment simple-transfer-body } cond
|
2019-09-07 10:03:22 +00:00
|
|
|
constant body-cell
|
|
|
|
|
|
|
|
."Transferring " amount .GR ."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
|
|
|
|
<b b{01} s, bounce 1 i, b{000100} s, dest_addr addr, amount Gram, 0 9 64 32 + + 1+ u,
|
|
|
|
body-cell <s 2dup s-fits? not rot over 1 i, -rot { drop body-cell ref, } { s, } cond
|
|
|
|
b>
|
2019-09-25 13:50:58 +00:00
|
|
|
<b seqno 32 u, send-mode 8 u, swap ref, b>
|
2019-09-07 10:03:22 +00:00
|
|
|
dup ."signing message: " <s csr. cr
|
2019-09-30 12:49:45 +00:00
|
|
|
dup hashu wallet_pk ed25519_sign_uint
|
2019-09-07 10:03:22 +00:00
|
|
|
<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
|
|
|
|
."(Saved to file " type .")" cr
|