-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-order.fif
49 lines (40 loc) · 1.81 KB
/
create-order.fif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/fift -s
"TonUtil.fif" include
"GetOpt.fif" include
{ show-options-help 1 halt } : usage
7200 =: timeout // order expires in 2 hours
0 =: seqno // in case several order expire at the same time
"order" =: savefile
begin-options
"<wallet-id> [-t<timeout>] [-s<seqno>] [-o<savefile>] msg1 ... msgN" +cr +tab
+"Creates an order to send messages from msg1.boc, ..., msgN.boc (1 <= N <= 3) created by create-msg.fif, "
+"and saves it into <savefile>.boc (" savefile $+ +".boc by default)"
disable-digit-options generic-help-setopt
"t" "--timeout" { parse-int =: timeout } short-long-option-arg
"Sets expiration timeout in seconds (" timeout (.) $+ +" by default)" option-help
"s" "--seqno" { parse-int =: seqno } short-long-option-arg
"Sets seqno useful in case there are several orders which expire at the same time (" seqno (.) $+ +" by default)" option-help
"o" "--output" { =: savefile } short-long-option-arg
"Save result into specified file" option-help
"h" "--help" { usage } short-long-option
"Shows a help message" option-help
parse-options
$# 1 < ' usage if
$# 1- constant N
$1 parse-int constant wallet-id
N 1 < N 3 > or { ."N must be in range 1..3" cr 1 halt } if
wallet-id 32 ufits { ."wallet-id must fit to 32-bit unsigned integer type" cr 1 halt } ifnot
now timeout + 32 ufits { ."timeout is too big" cr 1 halt } ifnot
seqno 32 ufits { ."seqno must fit to 32-bit unsigned integer type" cr 1 halt } ifnot
now timeout + 32 << seqno + constant query-id
<b 0 1 i, // no signatures
wallet-id 32 u, query-id 64 u, 2 {
dup $() +".boc" file>B B>boc <s
rot swap s, swap 1+
} N times
2 - . ."message(s) were added" cr
b> constant order
."Order expires in " timeout . ."seconds" cr
order 2 boc+>B
savefile +".boc" tuck B>file
."(Saved to file " type .")" cr