forked from Zilliqa/zilliqa-contracts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ZilCrossChainManagerProxy.scilla
145 lines (124 loc) · 4.7 KB
/
ZilCrossChainManagerProxy.scilla
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
scilla_version 0
import Polynetwork
library ZilCrossChainManagerProxy
let zero = Uint128 0
let one_msg =
fun (m: Message) =>
let e = Nil {Message} in
Cons {Message} m e
contract ZilCrossChainManagerProxy(
init_crosschain_manager : ByStr20,
init_admin: ByStr20
)
(* Mutable fields *)
field crosschain_manager: ByStr20 = init_crosschain_manager
field admin: ByStr20 = init_admin
field stagingadmin: Option ByStr20 = None {ByStr20}
(***************************************************)
(* Transition *)
(***************************************************)
(***************************************************)
(* Proxy Transition *)
(***************************************************)
transition UpgradeTo(new_crosschain_manager: ByStr20)
currentAdmin <- admin;
isAdmin = builtin eq currentAdmin _sender;
match isAdmin with
| True =>
crosschain_manager := new_crosschain_manager;
e = {_eventname: "Upgraded"; new_crosschain_manager: new_crosschain_manager};
event e
| False =>
e = {_eventname: "upgradeTo FailedNotAdmin"; new_crosschain_manager: new_crosschain_manager};
event e
end
end
transition ChangeProxyAdmin(newAdmin: ByStr20)
currentAdmin <- admin;
isAdmin = builtin eq currentAdmin _sender;
match isAdmin with
| True =>
new_staging_admin = Some {ByStr20} newAdmin;
stagingadmin := new_staging_admin;
e = {_eventname: "ChangeProxyAdmin"; oldAdmin: currentAdmin; newAdmin: newAdmin};
event e
| False =>
e = {_eventname: "ChangeProxyAdmin FailedNotAdmin"; newAdmin: newAdmin};
event e
end
end
transition ClaimProxyAdmin()
staging_admin_o <- stagingadmin;
match staging_admin_o with
| Some staging_admin =>
is_stagingadmin = builtin eq staging_admin _sender;
match is_stagingadmin with
| True =>
admin := _sender;
tmp_staging_admin = None {ByStr20};
stagingadmin := tmp_staging_admin;
e = {_eventname: "ClaimProxyAdmin"; newAdmin: _sender};
event e
| False =>
e = {_eventname: "ClaimProxyAdmin FailedNotStagingadmin"; newAdmin: _sender};
event e
end
| None =>
e = {_eventname: "ClaimProxyAdmin FailedNoStagingadmin"};
event e
end
end
(***************************************************)
(* House keeping transition *)
(***************************************************)
transition Pause()
current_impl <- crosschain_manager;
msg = {_tag: "Pause"; _recipient: current_impl; _amount: zero; initiator: _sender};
msgs = one_msg msg;
send msgs
end
transition UnPause()
current_impl <- crosschain_manager;
msg = {_tag: "UnPause"; _recipient: current_impl; _amount: zero; initiator: _sender};
msgs = one_msg msg;
send msgs
end
transition UpdateAdmin(newAdmin: ByStr20)
current_impl <- crosschain_manager;
msg = {_tag: "UpdateAdmin"; _recipient: current_impl; _amount: zero; initiator: _sender; newAdmin: newAdmin};
msgs = one_msg msg;
send msgs
end
transition ClaimAdmin()
current_impl <- crosschain_manager;
msg = {_tag: "ClaimAdmin"; _recipient: current_impl; _amount: zero; initiator: _sender};
msgs = one_msg msg;
send msgs
end
(***************************************************)
(* Cross chain transition *)
(***************************************************)
transition InitGenesisBlock(rawHeader: ByStr, pubkeys: List Pubkey)
current_impl <- crosschain_manager;
msg = {_tag: "InitGenesisBlock"; _recipient: current_impl; _amount: zero; rawHeader: rawHeader; pubkeys: pubkeys};
msgs = one_msg msg;
send msgs
end
transition ChangeBookKeeper(rawHeader: ByStr, pubkeys: List Pubkey, sigList: List Signature)
current_impl <- crosschain_manager;
msg = {_tag: "ChangeBookKeeper"; _recipient: current_impl; _amount: zero; rawHeader: rawHeader; pubkeys: pubkeys; sigList: sigList};
msgs = one_msg msg;
send msgs
end
transition CrossChain(toChainId: Uint64, toContract: ByStr, method: ByStr, txData: ByStr)
current_impl <- crosschain_manager;
msg = {_tag: "CrossChain"; _recipient: current_impl; _amount: zero; toChainId: toChainId; toContract: toContract; method: method; txData: txData; originContractAddr: _sender};
msgs = one_msg msg;
send msgs
end
transition VerifyHeaderAndExecuteTx(proof: Proof, rawHeader: ByStr, headerProof: Proof, curRawHeader: ByStr, headerSig: List Signature)
current_impl <- crosschain_manager;
msg = {_tag: "VerifyHeaderAndExecuteTx"; _recipient: current_impl; _amount: zero; proof: proof; rawHeader: rawHeader; headerProof: headerProof; curRawHeader: curRawHeader; headerSig: headerSig};
msgs = one_msg msg;
send msgs
end