#!/usr/bin/env fift -s "TonUtil.fif" include { ."usage: " @' $0 type ." []" cr ."Creates a request with up to 254 orders loaded from to high-load (sub)wallet created by new-highload-wallet.fif, with private key loaded from file .pk " ."and address from .addr, and saves it into .boc ('wallet-query.boc' by default)" cr ." is a text file with lines `SEND `" cr 1 halt } : usage $# dup 4 < swap 5 > or ' usage if $1 =: file-base $2 parse-int dup 32 fits ' usage ifnot =: subwallet-id // parse subwallet-id { subwallet-id (.) $+ } : +subwallet $3 parse-int =: seqno $4 =: order-file def? $5 { @' $5 } { "wallet-query" } cond constant savefile 3 constant send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors 60 constant timeout // external message expires in 60 seconds file-base +subwallet +".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 variable orders dictnew orders ! variable order# order# 0! // c -- { = abort"more than 254 orders" orders @ 16 udict!+ not abort"cannot add order to dictionary" orders ! order# 1+! } : add-order // b body -- b' { tuck } : create-int-msg // ng wc addr bnc -- { ."Transferring " 3 roll .GR ."to account " -rot 2dup 4 pick 7 + .Addr ." = " .addr ." bounce=" . cr } : .transfer // addr$ ng -- c { swap parse-smc-addr // ng wc addr bnc 2over 2over .transfer create-int-msg } : create-simple-transfer // c m -- c' { } : create-order // addr$ ng -- { create-simple-transfer send-mode create-order add-order } : send { bl word bl word $>GR send } : SEND // parse order file order-file include // create external message dup ."signing message: " dup ."resulting external message: " B dup Bx. cr savefile +".boc" tuck B>file ."(Saved to file " type .")" cr