-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade-code.fif
executable file
·54 lines (41 loc) · 1.51 KB
/
upgrade-code.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
53
54
#!/usr/bin/env fift -s
"auction-utils.fif" include
{ ."<contract> <seqno> [-C <code-fif>] [-O <output-boc>]" cr
."Upgrades contract's code, with address loaded from file <contract>.addr "
."and private key from <contract>.pk, and saves it into <output-boc>.boc ('<contract>-query.boc' by default)." cr
} : usage()
// == Parsing command-line arguments
{
"-C" "--code-file" 1 { +".fif" =: ContractCodeName } option-long()
"-O" "--output-file" 1 { =: SaveFile } option-long()
1 { =: BaseFile } 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
"code-getters.fif" =:? ContractCodeName
BaseFile +"-query" =:? SaveFile
BaseFile +".addr" load-address
2dup 2constant ContractAddr
."Contract address = " 2dup .addr cr 6 .Addr cr
BaseFile +".pk" load-keypair
=: PrivateKey
=: PublicKey
."Loading new code from " ContractCodeName type cr
ContractCodeName include =: ContractCode
ContractCode <s csr. cr
// Pack the internal message into a request data structure to be signed
<b
SeqNo 32 u, // seqno
-1 32 i, // valid_until
4 32 u, // action, 4 = upgrade code
ContractCode ref, // code
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