1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-15 04:32:21 +00:00
ton/crypto/smartcont/wallet.fif

61 lines
2.2 KiB
Text
Raw Normal View History

2019-10-09 16:00:54 +00:00
#!/usr/bin/fift -s
2019-09-07 10:03:22 +00:00
"TonUtil.fif" include
{ ."usage: " @' $0 type ." <filename-base> <dest-addr> <seqno> <amount> [-n] [-B <body-boc>] [-C <transfer-comment>] [<savefile>]" cr
2019-09-07 10:03:22 +00:00
."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)" cr 1 halt
} : usage
"" =: comment // comment for simple transfers
true =: allow-bounce
def? $5 { @' $5 "-n" $= { false =: allow-bounce [forget] $5
def? $6 { @' $6 =: $5 [forget] $6 } if
def? $7 { @' $7 =: $6 [forget] $7 } if
@' $# 1- =: $#
} if
} if
def? $6 { @' $5 dup "-B" $= swap "-C" $= tuck or
{ @' $6 swap { =: comment } { =: body-boc-file } cond [forget] $6
def? $7 { @' $7 =: $5 [forget] $7 } { [forget] $5 } cond
@' $# 2- =: $#
} if
} if
2019-09-24 10:20:26 +00:00
$# dup 4 < swap 5 > or ' usage if
2019-09-07 10:03:22 +00:00
true constant bounce
$1 =: file-base
$2 bounce parse-load-address allow-bounce and =: bounce 2=: dest_addr
$3 parse-int =: seqno
$4 $>GR =: amount
2019-09-07 10:03:22 +00:00
def? $5 { @' $5 } { "wallet-query" } cond constant savefile
3 constant send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
// "" 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
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>
<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
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