-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt-bid.fif
executable file
·52 lines (40 loc) · 1.54 KB
/
decrypt-bid.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
50
51
52
#!/usr/bin/env fift -s
"auction-utils.fif" include
{ ."<contract-addr> <seqno> [-B <bid-filename>] [-O <output-boc>]" cr
."Loads a bid to a blind auction with address <contract-addr>"
." from <bid-filename> ('bid.boc' by default) and saves a decryption request with it "
."into <output-boc>.boc ('decrypt-query.boc' by default)." cr
} : usage()
// == Parsing command-line arguments
{
"-B" "--bid-filename" 1 { =: BidFile } option-long()
"-O" "--output-file" 1 { =: SaveFile } option-long()
1 { =: ContractAddrRaw } nth-argument()
2 { parse-int =: SeqNo } nth-argument()
} scan-args()
2 < { show-usage() } if // Checks that there's enough arguments
// == End of parsing command-line arguments
"bid" =:? BidFile
"decrypt-query" =:? SaveFile
true =: BounceFlag
ContractAddrRaw BounceFlag parse-load-address =: BounceFlag 2=: ContractAddr
."Contract address = " ContractAddr 2dup .addr cr 6 .Addr cr
BidFile +".boc" file>B 32 B| B>boc =: BidBody =: PrivateKey
PrivateKey priv>pub =: PublicKey
."Creating a decrypt request to an auction" cr
// Pack the internal message into a request data structure to be signed
<b
SeqNo 32 u, // seqno
-1 32 i, // valid_until
102 32 u, // op, 102 = decrypt a bid in a blind auction
PublicKey B,
BidBody ref,
b> =: MessageBody
."Signing message: " MessageBody <s csr. cr
ContractAddr null
MessageBody PrivateKey sign-message()
external-message() =: ExtMessage
."New external message: " ExtMessage <s csr. cr
ExtMessage 2 boc+>B dup Bx. cr
SaveFile +".boc" tuck B>file
."(Saved to file " type .")" cr