forked from HugoByte/DIVE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.star
266 lines (151 loc) · 8.39 KB
/
main.star
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
icon_setup_node = import_module("github.com/hugobyte/chain-package/services/jvm/icon/src/node-setup/setup_icon_node.star")
eth_contract_service = import_module("github.com/hugobyte/chain-package/services/evm/eth/src/node-setup/contract-service.star")
eth_relay_setup = import_module("github.com/hugobyte/chain-package/services/evm/eth/src/relay-setup/contract_configuration.star")
eth_node = import_module("github.com/hugobyte/chain-package/services/evm/eth/eth.star")
icon_relay_setup = import_module("github.com/hugobyte/chain-package/services/jvm/icon/src/relay-setup/contract_configuration.star")
icon_service = import_module("github.com/hugobyte/chain-package/services/jvm/icon/icon.star")
btp_relay = import_module("github.com/hugobyte/chain-package/services/relay/btp_relay.star")
def run(plan,args):
plan.print("Starting")
return parse_input_and_start(plan,args)
# Parse Input based on actions
def parse_input_and_start(plan,args):
# Run a Single Node
if args["action"] == "start_node":
node_name = args["node_name"]
run_node(plan,node_name,args)
# Run two different Node
if args["action"] == "start_nodes":
nodes = args["nodes"]
if len(nodes) == 1:
if nodes[0] == "icon":
data = icon_service.start_node_service_icon_to_icon(plan)
return data
else:
plan.print("For now only Icon Node support for multi run")
return
if len(nodes) > 2:
plan.print("Maximum allowed node count is two")
return
if nodes[0] == "icon" and nodes[1] == "icon":
data = icon_service.start_node_service_icon_to_icon(plan)
return data
else:
node_0 = run_node(plan,nodes[0],args)
node_1 = run_node(plan,nodes[1],args)
return node_0,node_1
# Run nodes and setup relay
if args["action"] == "setup_relay":
if args["relay"]["name"] == "btp":
data = run_btp_setup(plan,args["relay"])
return data
else:
plan.print("More Relay Support will be added soon")
return
# Runs node based on node type
def run_node(plan,node_name,args):
if node_name == "icon":
return icon_service.start_node_service(plan)
elif node_name == "eth":
return eth_node.start_eth_node_serivce(plan,args)
else :
plan.print("Unknown Chain Type. Expected ['icon','eth']")
return
# Starts btp relay setup
def run_btp_setup(plan,args):
links = args["links"]
source_chain = links["src"]
destination_chain = links["dst"]
if destination_chain == "icon":
destination_chain = "icon-1"
bridge = args["bridge"]
config_data = {
"links": links,
"chains" : {
"%s" % source_chain : {},
"%s" % destination_chain : {}
},
"contracts" : {
"%s" % source_chain : {},
"%s" % destination_chain : {}
},
"bridge" : bridge
}
if destination_chain == "icon-1":
data = icon_service.start_node_service_icon_to_icon(plan)
config_data["chains"][source_chain] = data.src_config
config_data["chains"][destination_chain] = data.dst_config
icon_service.configure_icon_to_icon_node(plan,config_data["chains"][source_chain],config_data["chains"][destination_chain])
src_bmc_address , dst_bmc_address = icon_service.deploy_bmc_icon(plan,source_chain,destination_chain,config_data)
response = icon_service.deploy_bmv_icon_to_icon(plan,source_chain,destination_chain,src_bmc_address,dst_bmc_address,config_data)
src_xcall_address , dst_xcall_address = icon_service.deploy_xcall_icon(plan,source_chain,destination_chain,src_bmc_address,dst_bmc_address,config_data)
src_dapp_address , dst_dapp_address = icon_service.deploy_dapp_icon(plan,source_chain,destination_chain,src_xcall_address,dst_xcall_address,config_data)
src_block_height = icon_setup_node.hex_to_int(plan,data.src_config["service_name"],response.src_block_height)
dst_block_height = icon_setup_node.hex_to_int(plan,data.src_config["service_name"],response.dst_block_height)
src_contract_addresses = {
"bmc": response.src_bmc,
"bmv": response.src_bmv,
"xcall": src_xcall_address,
"dapp": src_dapp_address,
"block_number" : src_block_height
}
dst_contract_addresses = {
"bmc": response.dst_bmc,
"bmv": response.dst_bmv,
"xcall": dst_xcall_address,
"dapp": dst_dapp_address,
"block_number" : dst_block_height
}
config_data["chains"][source_chain]["networkTypeId"] = response.src_network_type_id
config_data["chains"][source_chain]["networkId"] = response.src_network_id
config_data["chains"][destination_chain]["networkTypeId"] = response.dst_network_type_id
config_data["chains"][destination_chain]["networkId"] = response.dst_network_id
config_data["contracts"][source_chain] = src_contract_addresses
config_data["contracts"][destination_chain] = dst_contract_addresses
if destination_chain == "eth":
src_chain_config = icon_service.start_node_service(plan)
dst_chain_config = eth_node.start_eth_node_serivce(plan,args)
config_data["chains"][source_chain] = src_chain_config
config_data["chains"][destination_chain] = dst_chain_config
icon_service.configure_icon_node(plan,src_chain_config)
eth_contract_service.start_deploy_service(plan,dst_chain_config)
src_bmc_address , empty = icon_service.deploy_bmc_icon(plan,source_chain,destination_chain,config_data)
dst_bmc_deploy_response = eth_relay_setup.deploy_bmc(plan,config_data)
dst_bmc_address = dst_bmc_deploy_response.bmc
dst_last_block_height_number = eth_contract_service.get_latest_block(plan,destination_chain,"localnet")
dst_last_block_height_hex = icon_setup_node.int_to_hex(plan,src_chain_config["service_name"],dst_last_block_height_number)
src_response = icon_service.deploy_bmv_icon(plan,source_chain,destination_chain,src_bmc_address ,dst_bmc_address,dst_last_block_height_hex,config_data)
dst_bmv_address = eth_node.deploy_bmv_eth(plan,bridge,src_response,config_data)
src_xcall_address , nil = icon_service.deploy_xcall_icon(plan,source_chain,destination_chain,src_bmc_address,dst_bmc_address,config_data)
dst_xcall_address = eth_relay_setup.deploy_xcall(plan,config_data)
src_dapp_address , nil = icon_service.deploy_dapp_icon(plan,source_chain,destination_chain,src_xcall_address,dst_xcall_address,config_data)
dst_dapp_address = eth_relay_setup.deploy_dapp(plan,config_data)
src_block_height = icon_setup_node.hex_to_int(plan,src_chain_config["service_name"],src_response.block_height)
src_contract_addresses = {
"bmc": src_response.bmc,
"bmv": src_response.bmvbridge,
"xcall": src_xcall_address,
"dapp": src_dapp_address,
"block_number" : src_block_height
}
dst_contract_addresses = {
"bmc": dst_bmc_address,
"bmcm" : dst_bmc_deploy_response.bmcm,
"bmcs" : dst_bmc_deploy_response.bmcs,
"bmv": dst_bmv_address,
"xcall": dst_xcall_address,
"dapp": dst_dapp_address,
"block_number" : dst_last_block_height_number
}
config_data["contracts"][source_chain] = src_contract_addresses
config_data["contracts"][destination_chain] = dst_contract_addresses
config_data["chains"][source_chain]["networkTypeId"] = src_response.network_type_id
config_data["chains"][source_chain]["networkId"] = src_response.network_id
src_network = config_data["chains"][source_chain]["network"]
src_bmc = config_data["contracts"][source_chain]["bmc"]
dst_network = config_data["chains"][destination_chain]["network"]
dst_bmc = config_data["contracts"][destination_chain]["bmc"]
src_btp_address = 'btp://{0}/{1}'.format(src_network,src_bmc)
dst_btp_address = 'btp://{0}/{1}'.format(dst_network,dst_bmc)
btp_relay.start_relayer(plan,source_chain,destination_chain,config_data,src_btp_address,dst_btp_address,bridge)
return config_data