From 181c6bc8e05a7f2c780c9eab640e3a974af5a046 Mon Sep 17 00:00:00 2001 From: Abhishek Harde <47945971+abhiyana@users.noreply.github.com> Date: Mon, 16 Oct 2023 10:56:31 +0530 Subject: [PATCH] refactor: refactor icon's, eth's, btp, ibc bridge kurtosis and go package of contract configuration, bridge btp (#197) * refactor: refactor argument passing in icon's starlark and Go packages * chore:change DiveRemotePackagePath in constant.go and RunStarlarkPackage to RunStarlarkRemotePackage in icon.go * refactor: refactor argument passing in icon's, eth's btp setup starklark package * refactor: refactor icon's, eth's, btp, ibc bridge kurtosis and go package of contract configuration, bridge btp --- cli/commands/bridge/relays/btp.go | 5 +- cli/commands/bridge/relays/ibc.go | 2 +- main.star | 224 +----- package_io/input_parser.star | 64 ++ services/bridges/btp/src/bridge.star | 296 +++++++- services/bridges/ibc/src/bridge.star | 49 +- .../neutron/src/node-setup/start_node.star | 6 +- services/evm/eth/eth.star | 19 +- .../eth/src/node-setup/contract-service.star | 11 +- .../eth/src/node-setup/start-eth-node.star | 4 +- .../relay-setup/contract_configuration.star | 125 ++- services/jvm/icon/icon.star | 364 ++++++--- .../icon/src/node-setup/contract_deploy.star | 86 ++- .../icon/src/node-setup/setup_icon_node.star | 712 +++++++++++++----- .../icon/src/node-setup/start_icon_node.star | 35 +- services/jvm/icon/src/node-setup/wallet.star | 65 +- .../relay-setup/contract_configuration.star | 101 +-- 17 files changed, 1425 insertions(+), 743 deletions(-) diff --git a/cli/commands/bridge/relays/btp.go b/cli/commands/bridge/relays/btp.go index 5f11ff09..106a54e8 100644 --- a/cli/commands/bridge/relays/btp.go +++ b/cli/commands/bridge/relays/btp.go @@ -213,10 +213,7 @@ func runBtpSetupByRunningNodes(diveContext *common.DiveContext, enclaveCtx *encl func runBtpSetupForAlreadyRunningNodes(diveContext *common.DiveContext, enclaveCtx *enclaves.EnclaveContext, mainFunctionName string, srcChain string, dstChain string, srcChainServiceName string, dstChainServiceName string, bridge bool, srcChainServiceResponse string, dstChainServiceResponse string) { - configData := fmt.Sprintf(`{"links": {"src":"%s","dst":"%s"},"chains" : { "%s" : %s,"%s" : %s},"contracts" : {"%s" : {},"%s" : {}},"bridge" : "%s"}`, srcChain, dstChain, srcChainServiceName, srcChainServiceResponse, dstChainServiceName, dstChainServiceResponse, srcChainServiceName, dstChainServiceName, strconv.FormatBool(bridge)) - - params := fmt.Sprintf(`{"src_chain":"%s", "dst_chain":"%s", "config_data":%s, "src_service_name":"%s", "dst_service_name":"%s"}`, srcChain, dstChain, configData, srcChainServiceName, dstChainServiceName) - + params := fmt.Sprintf(`{"src_chain":"%s","dst_chain":"%s", "src_chain_config":%s, "dst_chain_config":%s, "bridge":%s}`, chainA, chainB, srcChainServiceResponse, dstChainServiceResponse, strconv.FormatBool(bridge)) starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeScript, mainFunctionName) data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) diff --git a/cli/commands/bridge/relays/ibc.go b/cli/commands/bridge/relays/ibc.go index 55178c4b..d61520ff 100644 --- a/cli/commands/bridge/relays/ibc.go +++ b/cli/commands/bridge/relays/ibc.go @@ -126,7 +126,7 @@ func startCosmosChainsAndSetupIbcRelay(diveContext *common.DiveContext, enclaveC func setupIbcRelayforAlreadyRunningCosmosChain(diveContext *common.DiveContext, enclaveCtx *enclaves.EnclaveContext, chainA, chainB, chainAServiceResponse, chainBServiceResponse string) (string, error) { - params := fmt.Sprintf(`{"src_chain_config":%s,"dst_chain_config":%s, "args":{"links": {"src": "%s", "dst": "%s"}, "src_config":{"data":{}}, "dst_config":{"data":{}}}}`, chainAServiceResponse, chainBServiceResponse, chainA, chainB) + params := fmt.Sprintf(`{"src_chain":"%s","dst_chain":"%s", "src_chain_config":%s, "dst_chain_config":%s}`, chainA, chainB, chainAServiceResponse, chainBServiceResponse) executionResult, err := runStarlarkPackage(diveContext, enclaveCtx, params, "run_cosmos_ibc_relay_for_already_running_chains") diff --git a/main.star b/main.star index fbbd7f41..0ad47a1f 100644 --- a/main.star +++ b/main.star @@ -10,6 +10,7 @@ cosmvm_node = import_module("./services/cosmvm/cosmvm.star") cosmvm_relay = import_module("./services/bridges/ibc/src/bridge.star") cosmvm_relay_setup = import_module("./services/cosmvm/archway/src/relay-setup/contract-configuration.star") neutron_relay_setup = import_module("./services/cosmvm/neutron/src/relay-setup/contract-configuration.star") +btp_relay_setup = import_module("./services/bridges/btp/src/bridge.star") def run(plan, args): return parse_input(plan, args) @@ -46,7 +47,7 @@ def parse_input(plan, args): if args["action"] == "setup_relay": if args["relay"]["name"] == "btp": - data = run_btp_setup(plan, args["relay"]) + data = btp_relay_setup.run_btp_setup(plan, args["relay"]) return data @@ -67,186 +68,18 @@ def run_node(plan, node_name, args): return icon_service.start_node_service(plan) elif node_name == "eth" or node_name == "hardhat": - return eth_node.start_eth_node_serivce(plan, node_name) + return eth_node.start_eth_node_service(plan, node_name) elif node_name == "archway" or node_name == "neutron": - return cosmvm_node.start_cosmvm_chains(plan, node_name, args) + return cosmvm_node.start_cosmvm_chains(plan, node_name) else: fail("Unknown Chain Type. Expected ['icon','eth','hardhat','cosmwasm']") -def run_btp_setup(plan, args): - links = args["links"] - source_chain = links["src"] - destination_chain = links["dst"] - bridge = args["bridge"] - - if source_chain == "icon" and destination_chain == "icon": - data = icon_service.start_node_service_icon_to_icon(plan) - src_chain_service_name = data.src_config["service_name"] - dst_chain_service_name = data.dst_config["service_name"] - - config_data = input_parser.generate_new_config_data(links, src_chain_service_name, dst_chain_service_name, bridge) - config_data["chains"][src_chain_service_name] = data.src_config - config_data["chains"][dst_chain_service_name] = data.dst_config - - icon_service.configure_icon_to_icon_node(plan, data.src_config, data.dst_config) - - config = start_btp_for_already_running_icon_nodes(plan, source_chain, destination_chain, config_data, data.src_config["service_name"], data.dst_config["service_name"]) - - return config - else: - if (source_chain == "eth" or source_chain == "hardhat") and destination_chain == "icon": - destination_chain = source_chain - source_chain = "icon" - - if destination_chain == "eth" or destination_chain == "hardhat": - src_chain_config = icon_service.start_node_service(plan) - dst_chain_config = eth_node.start_eth_node_serivce(plan, destination_chain) - - src_chain_service_name = src_chain_config["service_name"] - dst_chain_service_name = dst_chain_config["service_name"] - - config_data = input_parser.generate_new_config_data(links, src_chain_service_name, dst_chain_service_name, bridge) - config_data["chains"][src_chain_service_name] = src_chain_config - config_data["chains"][dst_chain_service_name] = dst_chain_config - - icon_service.configure_icon_node(plan, src_chain_config) - config = start_btp_icon_to_eth_for_already_running_nodes(plan, source_chain, destination_chain, config_data, src_chain_service_name, dst_chain_service_name) - - return config - - else: - fail("unsupported chain {0} - {1}".format(source_chain, destination_chain)) - -def start_btp_for_already_running_icon_nodes(plan, src_chain, dst_chain, config_data, src_service_name, dst_service_name): - src_bmc_address, dst_bmc_address = icon_service.deploy_bmc_icon(plan, src_chain, dst_chain, src_service_name, dst_service_name, config_data) - - response = icon_service.deploy_bmv_icon_to_icon(plan, src_service_name, dst_service_name, src_bmc_address, dst_bmc_address, config_data) - - src_xcall_address, dst_xcall_address = icon_service.deploy_xcall_icon(plan, src_chain, dst_chain, src_bmc_address, dst_bmc_address, config_data, src_service_name, dst_service_name) - - src_dapp_address, dst_dapp_address = icon_service.deploy_dapp_icon(plan, src_chain, dst_chain, src_xcall_address, dst_xcall_address, config_data, src_service_name, dst_service_name) - - src_block_height = icon_setup_node.hex_to_int(plan, src_service_name, response.src_block_height) - dst_block_height = icon_setup_node.hex_to_int(plan, dst_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, - } - - dst_contract_addresses = { - "bmc": response.dst_bmc, - "bmv": response.dst_bmv, - "xcall": dst_xcall_address, - "dapp": dst_dapp_address, - } - - config_data["chains"][src_service_name]["networkTypeId"] = response.src_network_type_id - config_data["chains"][src_service_name]["networkId"] = response.src_network_id - config_data["chains"][dst_service_name]["networkTypeId"] = response.dst_network_type_id - config_data["chains"][dst_service_name]["networkId"] = response.dst_network_id - - config_data["contracts"][src_service_name] = src_contract_addresses - config_data["contracts"][dst_service_name] = dst_contract_addresses - config_data["chains"][src_service_name]["block_number"] = src_block_height - config_data["chains"][dst_service_name]["block_number"] = dst_block_height - - config_data = start_btp_relayer(plan, src_chain, dst_chain, config_data, src_service_name, dst_service_name) - - config_data["links"]["src"] = src_service_name - config_data["links"]["dst"] = dst_service_name - - return config_data - -def start_btp_icon_to_eth_for_already_running_nodes(plan, src_chain, dst_chain, config_data, src_service_name, dst_service_name): - dst_chain_config = config_data["chains"][dst_service_name] - src_chain_config = config_data["chains"][src_service_name] - - eth_contract_service.start_deploy_service(plan, dst_chain_config["endpoint"]) - - src_bmc_address = icon_service.deploy_bmc_icon(plan, src_chain, dst_chain, src_service_name, dst_service_name, config_data) - dst_bmc_deploy_response = eth_relay_setup.deploy_bmc(plan, config_data["chains"][dst_service_name]["network"], config_data["chains"][dst_service_name]["network_name"], dst_chain) - dst_bmc_address = dst_bmc_deploy_response.bmc - - dst_last_block_height_number = eth_contract_service.get_latest_block(plan, dst_chain, "localnet") - - dst_last_block_height_hex = icon_setup_node.int_to_hex(plan, src_service_name, dst_last_block_height_number) - - src_response = icon_service.deploy_bmv_icon(plan, src_service_name, dst_service_name, src_bmc_address, dst_bmc_address, dst_last_block_height_hex, config_data) - - dst_bmv_address = eth_node.deploy_bmv_eth(plan, config_data["bridge"], src_response, config_dataconfig_data["chains"][dst_service_name]["network_name"], config_data["chains"][dst_service_name]["network_name"], dst_chain) - - src_xcall_address = icon_service.deploy_xcall_icon(plan, src_chain, dst_chain, src_bmc_address, dst_bmc_address, config_data, src_service_name, dst_service_name) - - dst_xcall_address = eth_relay_setup.deploy_xcall(plan, config_data["chains"][dst_service_name]["network"], config_data["chains"][dst_service_name]["network_name"], dst_chain) - - src_dapp_address = icon_service.deploy_dapp_icon(plan, src_chain, dst_chain, src_xcall_address, dst_xcall_address, config_data, src_service_name, dst_service_name) - - dst_dapp_address = eth_relay_setup.deploy_dapp(plan, config_data["chains"][dst_service_name]["network"], config_data["chains"][dst_service_name]["network_name"], dst_chain) - - src_block_height = icon_setup_node.hex_to_int(plan, src_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, - } - - 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, - } - - config_data["contracts"][src_service_name] = src_contract_addresses - config_data["contracts"][dst_service_name] = dst_contract_addresses - config_data["chains"][src_service_name]["networkTypeId"] = src_response.network_type_id - config_data["chains"][src_service_name]["networkId"] = src_response.network_id - config_data["chains"][src_service_name]["block_number"] = src_block_height - config_data["chains"][dst_service_name]["block_number"] = dst_last_block_height_number - - config_data = start_btp_relayer(plan, src_chain, dst_chain, config_data, src_service_name, dst_service_name) - - config_data["links"]["src"] = src_service_name - config_data["links"]["dst"] = dst_service_name - - return config_data - -def start_btp_relayer(plan, src_chain, dst_chain, config_data, src_service_name, dst_service_name): - src_network = config_data["chains"][src_service_name]["network"] - src_bmc = config_data["contracts"][src_service_name]["bmc"] - - dst_network = config_data["chains"][dst_service_name]["network"] - dst_bmc = config_data["contracts"][dst_service_name]["bmc"] - - src_btp_address = "btp://{0}/{1}".format(src_network, src_bmc) - dst_btp_address = "btp://{0}/{1}".format(dst_network, dst_bmc) - - btp_bridge.start_relayer(plan, src_service_name, dst_service_name, config_data, src_btp_address, dst_btp_address, config_data["bridge"]) - - return config_data def run_cosmos_ibc_setup(plan, args): - """ - Start the Cosmos IBC relay setup process between chains. - - Args: - plan (plan): The execution plan. - args (dict): Arguments for configuring the setup. - - Returns: - dict: Configuration response data (will return data for dive.json) - """ links = args["links"] source_chain = links["src"] destination_chain = links["dst"] @@ -254,26 +87,26 @@ def run_cosmos_ibc_setup(plan, args): # Check if source and destination chains are both CosmVM-based chains (archway or neutron) if (source_chain in ["archway", "neutron"]) and (destination_chain in ["archway", "neutron"]): # Start IBC between two CosmVM chains - data = cosmvm_node.start_ibc_between_cosmvm_chains(plan, source_chain, destination_chain, args) - config_data = run_cosmos_ibc_relay_for_already_running_chains(plan, data.src_config, data.dst_config, args) + data = cosmvm_node.start_ibc_between_cosmvm_chains(plan, source_chain, destination_chain) + config_data = run_cosmos_ibc_relay_for_already_running_chains(plan, source_chain, destination_chain ,data.src_config, data.dst_config) return config_data - # Check if the destination chain is CosmVM-based and the source chain is ICON if destination_chain in ["archway", "neutron"] and source_chain == "icon": # Start ICON node service src_chain_config = icon_service.start_node_service(plan) # Start CosmVM node service - data = {"data": {}} - dst_chain_config = cosmvm_node.start_cosmvm_chains(plan, destination_chain, data) + dst_chain_config = cosmvm_node.start_cosmvm_chains(plan, destination_chain) dst_chain_config = input_parser.struct_to_dict(dst_chain_config) # Get service names and new generate configuration data - config_data = run_cosmos_ibc_relay_for_already_running_chains(plan, src_chain_config , dst_chain_config, args) + config_data = run_cosmos_ibc_relay_for_already_running_chains(plan,source_chain, destination_chain ,src_chain_config , dst_chain_config) return config_data -def run_cosmos_ibc_relay_for_already_running_chains(plan, src_chain_config, dst_chain_config, args): - source_chain = args["links"]["src"] - destination_chain = args["links"]["dst"] - if source_chain in ["archway", "neutron"] and destination_chain in ["archway", "neutron"]: + + +def run_cosmos_ibc_relay_for_already_running_chains(plan, src_chain, dst_chain, src_chain_config, dst_chain_config): + source_chain = src_chain + destination_chain = dst_chain + if src_chain in ["archway", "neutron"] and dst_chain in ["archway", "neutron"]: src_chain_service_name = src_chain_config["service_name"] dst_chain_service_name = dst_chain_config["service_name"] src_chain_id = src_chain_config["chain_id"] @@ -281,25 +114,25 @@ def run_cosmos_ibc_relay_for_already_running_chains(plan, src_chain_config, dst_ dst_chain_id = dst_chain_config["chain_id"] dst_chain_key = dst_chain_config["chain_key"] - config_data = input_parser.generate_new_config_data_cosmvm_cosmvm(args["links"], src_chain_service_name, dst_chain_service_name) + config_data = input_parser.generate_new_config_data_for_ibc(src_chain, dst_chain, src_chain_service_name, dst_chain_service_name) config_data["chains"][src_chain_service_name] = src_chain_config config_data["chains"][dst_chain_service_name] = dst_chain_config - cosmvm_relay.start_cosmos_relay(plan, src_chain_key, src_chain_id, dst_chain_key, dst_chain_id, src_chain_config, dst_chain_config, args["links"]) + cosmvm_relay.start_cosmos_relay(plan, src_chain, dst_chain, src_chain_config, dst_chain_config) - elif source_chain == "icon" and destination_chain in ["archway", "neutron"]: + elif src_chain == "icon" and dst_chain in ["archway", "neutron"]: src_chain_service_name = src_chain_config["service_name"] dst_chain_service_name = dst_chain_config["service_name"] - config_data = input_parser.generate_new_config_data(args["links"], src_chain_service_name, dst_chain_service_name, "") + config_data = input_parser.generate_new_config_data_for_ibc(src_chain,dst_chain, src_chain_service_name, dst_chain_service_name) # Add chain configurations to the configuration data config_data["chains"][src_chain_service_name] = src_chain_config config_data["chains"][dst_chain_service_name] = dst_chain_config # Setup ICON contracts for IBC - deploy_icon_contracts = icon_relay_setup.setup_contracts_for_ibc_java(plan, src_chain_config) + deploy_icon_contracts = icon_relay_setup.setup_contracts_for_ibc_java(plan, src_chain_config["service_name"], src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"], src_chain_config["network"]) icon_register_client = icon_relay_setup.registerClient(plan, src_chain_service_name, deploy_icon_contracts["light_client"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"], src_chain_config["endpoint"], deploy_icon_contracts["ibc_core"]) # Configure ICON node - icon_setup_node.configure_node(plan, src_chain_config) + icon_setup_node.configure_node(plan, src_chain_config["service_name"], src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) src_chain_last_block_height = icon_setup_node.get_last_block(plan, src_chain_service_name) @@ -318,12 +151,12 @@ def run_cosmos_ibc_relay_for_already_running_chains(plan, src_chain_config, dst_ icon_bind_port = icon_relay_setup.bindPort(plan, src_chain_service_name, deploy_icon_contracts["xcall_connection"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"], src_chain_config["endpoint"], deploy_icon_contracts["ibc_core"], "xcall") # Depending on the destination chain (archway or neutron), set up Cosmos contracts - if destination_chain == "archway": + if dst_chain == "archway": deploy_cosmos_contracts = cosmvm_relay_setup.setup_contracts_for_ibc_wasm(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], dst_chain_config["chain_id"], "stake", "xcall") cosmvm_relay_setup.registerClient(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["ibc_core"], deploy_cosmos_contracts["light_client"]) plan.wait(service_name = dst_chain_service_name, recipe = ExecRecipe(command = ["/bin/sh", "-c", "sleep 10s && echo 'success'"]), field = "code", assertion = "==", target_value = 0, timeout = "200s") cosmvm_relay_setup.bindPort(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["ibc_core"], deploy_cosmos_contracts["xcall_connection"]) - elif destination_chain == "neutron": + elif dst_chain == "neutron": deploy_cosmos_contracts = neutron_relay_setup.setup_contracts_for_ibc_wasm(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], dst_chain_config["chain_id"], "stake", "xcall") neutron_relay_setup.registerClient(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["ibc_core"], deploy_cosmos_contracts["light_client"]) plan.wait(service_name = dst_chain_service_name, recipe = ExecRecipe(command = ["/bin/sh", "-c", "sleep 10s && echo 'success'"]), field = "code", assertion = "==", target_value = 0, timeout = "200s") @@ -358,18 +191,18 @@ def run_cosmos_ibc_relay_for_already_running_chains(plan, src_chain_config, dst_ } # Start the Cosmos relay for ICON to Cosmos communication - relay_service_response = cosmvm_relay.start_cosmos_relay_for_icon_to_cosmos(plan, src_chain_data, dst_chain_data, args) + relay_service_response = cosmvm_relay.start_cosmos_relay_for_icon_to_cosmos(plan, src_chain, dst_chain ,src_chain_data, dst_chain_data) path_name = cosmvm_relay.setup_relay(plan, src_chain_data, dst_chain_data) relay_data = cosmvm_relay.get_relay_path_data(plan, relay_service_response.service_name, path_name) - dapp_result_java = icon_relay_setup.deploy_and_configure_dapp_java(plan, src_chain_config, deploy_icon_contracts["xcall"], dst_chain_config["chain_id"], deploy_icon_contracts["xcall_connection"], deploy_cosmos_contracts["xcall_connection"], src_chain_service_name, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) + dapp_result_java = icon_relay_setup.deploy_and_configure_dapp_java(plan, src_chain_config, deploy_icon_contracts["xcall"], dst_chain_config["chain_id"], deploy_icon_contracts["xcall_connection"], deploy_cosmos_contracts["xcall_connection"]) # Depending on the destination chain (archway or neutron), deploy and configure the DApp for Wasm - if destination_chain == "archway": + if dst_chain == "archway": dapp_result_wasm = cosmvm_relay_setup.deploy_and_configure_xcall_dapp(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["xcall"], deploy_cosmos_contracts["xcall_connection"], deploy_icon_contracts["xcall_connection"], src_chain_config["network"]) cosmvm_relay_setup.configure_connection_for_wasm(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["xcall_connection"], relay_data.dst_connection_id, "xcall", src_chain_config["network"], relay_data.dst_client_id, deploy_cosmos_contracts["xcall"]) - elif destination_chain == "neutron": + elif dst_chain == "neutron": dapp_result_wasm = neutron_relay_setup.deploy_and_configure_xcall_dapp(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["xcall"], deploy_cosmos_contracts["xcall_connection"], deploy_icon_contracts["xcall_connection"], src_chain_config["network"]) neutron_relay_setup.configure_connection_for_wasm(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["xcall_connection"], relay_data.dst_connection_id, "xcall", src_chain_config["network"], relay_data.dst_client_id, deploy_cosmos_contracts["xcall"]) @@ -383,8 +216,3 @@ def run_cosmos_ibc_relay_for_already_running_chains(plan, src_chain_config, dst_ return config_data - - - - - diff --git a/package_io/input_parser.star b/package_io/input_parser.star index 63812b90..7b1f077b 100644 --- a/package_io/input_parser.star +++ b/package_io/input_parser.star @@ -37,6 +37,9 @@ def get_args_data(args): bridge = bridge, ) + + + def generate_new_config_data(links, srcchain_service_name, dst_chain_service_name, bridge): config_data = "" if bridge == "": @@ -68,6 +71,67 @@ def generate_new_config_data(links, srcchain_service_name, dst_chain_service_nam return config_data + + +def generate_new_config_data_for_ibc(src_chain, dst_chain, srcchain_service_name, dst_chain_service_name): + + config_data = { + "links": { + "src": "%s" % src_chain, + "dst": "%s" % dst_chain + }, + "chains": { + "%s" % srcchain_service_name: {}, + "%s" % dst_chain_service_name: {}, + }, + "contracts": { + "%s" % srcchain_service_name: {}, + "%s" % dst_chain_service_name: {}, + }, + } + + return config_data + + +def generate_new_config_data_for_btp(src_chain, dst_chain, srcchain_service_name, dst_chain_service_name, bridge): + config_data = "" + if bridge == "": + config_data = { + "links": { + "src": "%s" % src_chain, + "dst": "%s" % dst_chain + }, + "chains": { + "%s" % srcchain_service_name: {}, + "%s" % dst_chain_service_name: {}, + }, + "contracts": { + "%s" % srcchain_service_name: {}, + "%s" % dst_chain_service_name: {}, + }, + } + else: + + config_data = { + "links": { + "src": "%s" % src_chain, + "dst": "%s" % dst_chain + }, + "chains": { + "%s" % srcchain_service_name: {}, + "%s" % dst_chain_service_name: {}, + }, + "contracts": { + "%s" % srcchain_service_name: {}, + "%s" % dst_chain_service_name: {}, + }, + "bridge": "%s" % bridge + } + + return config_data + + + def generate_new_config_data_cosmvm_cosmvm(links, srcchain_service_name, dst_chain_service_name): config_data = { "links": links, diff --git a/services/bridges/btp/src/bridge.star b/services/bridges/btp/src/bridge.star index fe843fdd..502b36c8 100644 --- a/services/bridges/btp/src/bridge.star +++ b/services/bridges/btp/src/bridge.star @@ -1,33 +1,293 @@ RELAY_SERVICE_IMAGE = 'hugobyte/btp-relay' RELAY_SERVICE_NAME = "btp-bridge" RELAY_KEYSTORE_FILES_PATH = "/relay/keystores/" -RELAY_KESYTORE_PATH = "../static-files/keystores/" +RELAY_KEYSTORE_PATH = "../static-files/keystores/" +icon_relay_setup = import_module("../../../jvm/icon/src/relay-setup/contract_configuration.star") +icon_service = import_module("../../../jvm/icon/icon.star") +icon_setup_node = import_module("../../../jvm/icon/src/node-setup/setup_icon_node.star") +eth_contract_service = import_module("../../../evm/eth/src/node-setup/contract-service.star") +eth_relay_setup = import_module("../../../evm/eth/src/relay-setup/contract_configuration.star") +eth_node = import_module("../../../evm/eth/eth.star") +input_parser = import_module("../../../../package_io/input_parser.star") -# Starts BTP relayer -def start_relayer(plan,src_chain,dst_chain,args,src_btp_address,dst_btp_address,bridge): - plan.print("Starting BTP Relay Service") - src_config = args["chains"][src_chain] - src_endpoint = src_config["endpoint"] - src_keystore = src_config["keystore_path"] - src_keypassword =src_config["keypassword"] - dst_config = args["chains"][dst_chain] - dst_endpoint = dst_config["endpoint"] - dst_keystore = dst_config["keystore_path"] - dst_keypassword =dst_config["keypassword"] +def run_btp_setup(plan, args): + links = args["links"] + source_chain = links["src"] + destination_chain = links["dst"] + bridge = args["bridge"] + + if source_chain == "icon" and destination_chain == "icon": + data = icon_service.start_node_service_icon_to_icon(plan) + src_chain_service_name = data.src_config["service_name"] + dst_chain_service_name = data.dst_config["service_name"] + + config_data = input_parser.generate_new_config_data(links, src_chain_service_name, dst_chain_service_name, bridge) + config_data["chains"][src_chain_service_name] = data.src_config + config_data["chains"][dst_chain_service_name] = data.dst_config + + icon_service.configure_icon_to_icon_node(plan, data.src_config, data.dst_config) + + config = start_btp_for_already_running_icon_nodes(plan, source_chain, destination_chain, data.src_config, data.dst_config, bridge) + + return config + else: + if (source_chain == "eth" or source_chain == "hardhat") and destination_chain == "icon": + destination_chain = source_chain + source_chain = "icon" + + if destination_chain == "eth" or destination_chain == "hardhat": + src_chain_config = icon_service.start_node_service(plan) + dst_chain_config = eth_node.start_eth_node_service(plan, destination_chain) + + src_chain_service_name = src_chain_config["service_name"] + dst_chain_service_name = dst_chain_config["service_name"] + + config_data = input_parser.generate_new_config_data(links, src_chain_service_name, dst_chain_service_name, bridge) + config_data["chains"][src_chain_service_name] = src_chain_config + config_data["chains"][dst_chain_service_name] = dst_chain_config + + icon_service.configure_icon_node(plan, src_chain_service_name, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) + + config = start_btp_icon_to_eth_for_already_running_nodes(plan, source_chain, destination_chain, src_chain_config, dst_chain_config, bridge) + + return config + + else: + fail("unsupported chain {0} - {1}".format(source_chain, destination_chain)) + + + + + +def start_btp_for_already_running_icon_nodes(plan, src_chain, dst_chain, src_chain_config, dst_chain_config, bridge): + """ + Starts BTP for already running ICON nodes. + + Args: + plan (str): plan. + src_chain (str): The source ICON chain name. + dst_chain (str): The destination ICON chain name. + src_chain_config (dict): Configuration for the source ICON chain. + dst_chain_config (dict): Configuration for the destination ICON chain. + bridge (bool): BMV bridge if true or false. + + Returns: + dict: New configuration data for BTP. + """ + # Deploy BMC ICON nodes + src_bmc_address, dst_bmc_address = icon_service.deploy_bmc_icon(plan, src_chain, dst_chain, src_chain_config, dst_chain_config) + + # Deploy BMV ICON nodes + response = icon_service.deploy_bmv_icon_to_icon( + plan, + src_chain_config, + dst_chain_config, + src_bmc_address, + dst_bmc_address + ) + + # Deploy XCALL ICON nodes + src_xcall_address, dst_xcall_address = icon_service.deploy_xcall_icon( + plan, + src_chain, + dst_chain, + src_chain_config, + dst_chain_config, + src_bmc_address, + dst_bmc_address, + ) + + # Deploy DAPP ICON nodes + src_dapp_address, dst_dapp_address = icon_service.deploy_dapp_icon( + plan, + src_chain, + dst_chain, + src_chain_config, + dst_chain_config, + src_xcall_address, + dst_xcall_address + ) + + # Convert hexadecimal block heights to integers + src_block_height = icon_setup_node.hex_to_int(plan, src_chain_config["service_name"], response.src_block_height) + dst_block_height = icon_setup_node.hex_to_int(plan, dst_chain_config["service_name"], response.dst_block_height) + + # Create dictionaries for contract addresses + src_contract_addresses = { + "bmc": response.src_bmc, + "bmv": response.src_bmv, + "xcall": src_xcall_address, + "dapp": src_dapp_address, + } + + dst_contract_addresses = { + "bmc": response.dst_bmc, + "bmv": response.dst_bmv, + "xcall": dst_xcall_address, + "dapp": dst_dapp_address, + } + + # Generate new configuration data for BTP + config_data = input_parser.generate_new_config_data_for_btp(src_chain, dst_chain, src_chain_config["service_name"], dst_chain_config["service_name"], bridge) + + # Update network and contract information in the configuration data + config_data["chains"][src_chain_config["service_name"]]["networkTypeId"] = response.src_network_type_id + config_data["chains"][src_chain_config["service_name"]]["networkId"] = response.src_network_id + config_data["chains"][dst_chain_config["service_name"]]["networkTypeId"] = response.dst_network_type_id + config_data["chains"][dst_chain_config["service_name"]]["networkId"] = response.dst_network_id + config_data["contracts"][src_chain_config["service_name"]] = src_contract_addresses + config_data["contracts"][dst_chain_config["service_name"]] = dst_contract_addresses + config_data["chains"][src_chain_config["service_name"]]["block_number"] = src_block_height + config_data["chains"][dst_chain_config["service_name"]]["block_number"] = dst_block_height + + # Start BTP relayer + start_btp_relayer(plan, response.src_bmc, response.dst_bmc, src_chain_config, dst_chain_config, bridge) + + # Set source and destination chain names in the configuration data + config_data["links"]["src"] = src_chain_config["service_name"] + config_data["links"]["dst"] = dst_chain_config["service_name"] + + return config_data - plan.upload_files(src=RELAY_KESYTORE_PATH,name="keystores") + + +# Function to start the BTP from ICON to Ethereum for already running nodes. +def start_btp_icon_to_eth_for_already_running_nodes(plan, src_chain, dst_chain, src_chain_config, dst_chain_config, bridge): + """ + Starts BTP from ICON to Ethereum for already running nodes. + + Args: + plan (str): plan. + src_chain (str): The source ICON chain name. + dst_chain (str): The destination Ethereum chain name. + src_chain_config (dict): Configuration for the source ICON chain. + dst_chain_config (dict): Configuration for the destination Ethereum chain. + bridge (str): The bridge configuration. + + Returns: + dict: New configuration data for BTP. + """ + # Start the Ethereum contract service + eth_contract_service.start_deploy_service(plan, dst_chain_config["endpoint"]) + + # Deploy BMC ICON node on the source ICON chain + src_bmc_address = icon_service.deploy_bmc_icon(plan, src_chain, dst_chain, src_chain_config, dst_chain_config) + + # Deploy BMC Ethereum node on the destination Ethereum chain + dst_bmc_deploy_response = eth_relay_setup.deploy_bmc(plan, dst_chain, dst_chain_config["network"], dst_chain_config["network_name"]) + dst_bmc_address = dst_bmc_deploy_response.bmc + + # Get the latest block height on the destination Ethereum chain + dst_last_block_height_number = eth_contract_service.get_latest_block(plan, dst_chain, "localnet") + dst_last_block_height_hex = icon_setup_node.int_to_hex(plan, src_chain_config["service_name"], dst_last_block_height_number) + + # Deploy BMV ICON node on the source ICON chain + src_response = icon_service.deploy_bmv_icon(plan, src_bmc_address, dst_bmc_address, src_chain_config, dst_chain_config, dst_last_block_height_hex) + + # Deploy BMV Ethereum node on the destination Ethereum chain + dst_bmv_address = eth_node.deploy_bmv_eth(plan, bridge, src_response, dst_chain_config["network"], dst_chain_config["network_name"], dst_chain) + + # Deploy XCALL ICON node on the source ICON chain + src_xcall_address = icon_service.deploy_xcall_icon( + plan, + src_chain, + dst_chain, + src_chain_config, + dst_chain_config, + src_bmc_address, + dst_bmc_address + ) + + # Deploy XCALL Ethereum node on the destination Ethereum chain + dst_xcall_address = eth_relay_setup.deploy_xcall(plan, dst_chain, dst_chain_config["network"], dst_chain_config["network_name"]) + + # Deploy DAPP ICON node on the source ICON chain + src_dapp_address = icon_service.deploy_dapp_icon(plan, src_chain, dst_chain, src_chain_config, dst_chain_config, src_xcall_address, dst_xcall_address) + + # Deploy DAPP Ethereum node on the destination Ethereum chain + dst_dapp_address = eth_relay_setup.deploy_dapp(plan, dst_chain, dst_chain_config["network"], dst_chain_config["network_name"]) + + # Convert hexadecimal block height to integer + src_block_height = icon_setup_node.hex_to_int(plan, src_chain_config["service_name"], src_response.block_height) + + # Create dictionaries for contract addresses + src_contract_addresses = { + "bmc": src_response.bmc, + "bmv": src_response.bmvbridge, + "xcall": src_xcall_address, + "dapp": src_dapp_address, + } + + 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, + } + + # Generate new configuration data for BTP + config_data = input_parser.generate_new_config_data_for_btp(src_chain, dst_chain, src_chain_config["service_name"], dst_chain_config["service_name"], bridge) + config_data["contracts"][src_chain_config["service_name"]] = src_contract_addresses + config_data["contracts"][dst_chain_config["service_name"]] = dst_contract_addresses + config_data["chains"][src_chain_config["service_name"]]["networkTypeId"] = src_response.network_type_id + config_data["chains"][src_chain_config["service_name"]]["networkId"] = src_response.network_id + config_data["chains"][src_chain_config["service_name"]]["block_number"] = src_block_height + config_data["chains"][dst_chain_config["service_name"]]["block_number"] = dst_last_block_height_number + + # Start BTP relayer + start_btp_relayer(plan, src_response.bmc, dst_bmc_address, src_chain_config, dst_chain_config, bridge) + + # Set source and destination chain names in the configuration data + config_data["links"]["src"] = src_chain_config["service_name"] + config_data["links"]["dst"] = dst_chain_config["service_name"] + + return config_data + + + +def start_btp_relayer(plan, src_bmc, dst_bmc, src_chain_config, dst_chain_config ,bridge): + + src_btp_address = "btp://{0}/{1}".format(src_chain_config["network"], src_bmc) + dst_btp_address = "btp://{0}/{1}".format(dst_chain_config["network"], dst_bmc) + start_relayer(plan, src_btp_address, dst_btp_address, src_chain_config, dst_chain_config ,bridge) + + + +def start_relayer(plan, src_btp_address, dst_btp_address, src_chain_config, dst_chain_config, bridge): + """ + Start a BTP Relay Service. + + Args: + plan (Plan): The kurtosi plan for starting the relay service. + src_btp_address (str): The source BTP address. + dst_btp_address (str): The destination BTP address. + src_chain_config (dict): Configuration for the source chain. + dst_chain_config (dict): Configuration for the destination chain. + bridge (str): The bridge mode. + + Note: + This function starts a BTP Relay Service to relay messages between two blockchain networks. + It uploads keystore files, configures the service, and starts the relay with the provided parameters. + """ + plan.print("Starting BTP Relay Service") + + plan.upload_files(src=RELAY_KEYSTORE_PATH, name="keystores") + relay_service = ServiceConfig( image=RELAY_SERVICE_IMAGE, files={ RELAY_KEYSTORE_FILES_PATH: "keystores" }, - cmd=["/bin/sh","-c","./bin/relay --direction both --log_writer.filename log/relay.log --src.address %s --src.endpoint %s --src.key_store %s --src.key_password %s --src.bridge_mode=%s --dst.address %s --dst.endpoint %s --dst.key_store %s --dst.key_password %s start " % (src_btp_address,src_endpoint,src_keystore,src_keypassword,bridge, dst_btp_address, dst_endpoint, dst_keystore, dst_keypassword)] - + cmd=[ + "/bin/sh", + "-c", + "./bin/relay --direction both --log_writer.filename log/relay.log --src.address %s --src.endpoint %s --src.key_store %s --src.key_password %s --src.bridge_mode=%s --dst.address %s --dst.endpoint %s --dst.key_store %s --dst.key_password %s start " % (src_btp_address, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], bridge, dst_btp_address, dst_chain_config["endpoint"], dst_chain_config["keystore_path"], dst_chain_config["keypassword"]) + ] ) - plan.add_service(name=RELAY_SERVICE_NAME,config=relay_service) - - + plan.add_service(name=RELAY_SERVICE_NAME, config=relay_service) diff --git a/services/bridges/ibc/src/bridge.star b/services/bridges/ibc/src/bridge.star index 7156c7b9..eb92aca4 100644 --- a/services/bridges/ibc/src/bridge.star +++ b/services/bridges/ibc/src/bridge.star @@ -2,7 +2,7 @@ constants = import_module("../../../../package_io/constants.star") ibc_relay_config = constants.IBC_RELAYER_SERVICE -def start_cosmos_relay(plan, src_key, src_chain_id, dst_key, dst_chain_id, src_config, dst_config, links): +def start_cosmos_relay(plan, src_chain, dst_chain, src_config, dst_config): """ Start a Cosmos relay service with given source and destination chains configuration. @@ -27,48 +27,48 @@ def start_cosmos_relay(plan, src_key, src_chain_id, dst_key, dst_chain_id, src_c cosmos_config = read_file(ibc_relay_config.ibc_relay_config_file_template) cfg_template_data = { - "KEY": src_key, - "CHAINID": src_chain_id, - "CHAIN": links["src"], + "KEY": src_config["chain_key"], + "CHAINID": src_config["chain_id"], + "CHAIN": src_chain, } plan.render_templates( config = { - "cosmos-%s.json" % src_chain_id: struct( + "cosmos-%s.json" % src_config["chain_id"]: struct( template = cosmos_config, data = cfg_template_data, ), }, - name = "config-%s" % src_chain_id, + name = "config-%s" % src_config["chain_id"], ) cfg_template_data = { - "KEY": dst_key, - "CHAINID": dst_chain_id, - "CHAIN": links["dst"], + "KEY": dst_config["chain_key"], + "CHAINID": dst_config["chain_id"], + "CHAIN": dst_chain, } plan.render_templates( config = { - "cosmos-%s.json" % dst_chain_id: struct( + "cosmos-%s.json" % dst_config["chain_id"]: struct( template = cosmos_config, data = cfg_template_data, ), }, - name = "config-%s" % dst_chain_id, + name = "config-%s" % dst_config["chain_id"], ) # Install 'jq' based on the type of chain (neutron or archway) for the source - if links["src"] == "neutron": + if src_chain == "neutron": plan.exec(service_name = src_config["service_name"], recipe = ExecRecipe(command = ["/bin/sh", "-c", "apt install jq"])) - elif links["src"] == "archway": + elif src_chain == "archway": plan.exec(service_name = src_config["service_name"], recipe = ExecRecipe(command = ["/bin/sh", "-c", "apk add jq"])) # Retrieve the seed for the source chain src_chain_seed = plan.exec(service_name = src_config["service_name"], recipe = ExecRecipe(command = ["/bin/sh", "-c", "jq -r '.mnemonic' ../../start-scripts/key_seed.json | tr -d '\n\r'"])) # Install 'jq' based on the type of chain (neutron or archway) for the destination - if links["dst"] == "neutron": + if dst_chain == "neutron": plan.exec(service_name = dst_config["service_name"], recipe = ExecRecipe(command = ["/bin/sh", "-c", "apt install jq"])) - elif links["src"] == "archway": + elif dst_chain == "archway": plan.exec(service_name = dst_config["service_name"], recipe = ExecRecipe(command = ["/bin/sh", "-c", "apk add jq"])) # Retrieve the seed for the destination chain @@ -78,11 +78,11 @@ def start_cosmos_relay(plan, src_key, src_chain_id, dst_key, dst_chain_id, src_c relay_service = ServiceConfig( image = ibc_relay_config.relay_service_image, files = { - ibc_relay_config.relay_config_files_path + src_chain_id: "config-%s" % src_chain_id, - ibc_relay_config.relay_config_files_path + dst_chain_id: "config-%s" % dst_chain_id, + ibc_relay_config.relay_config_files_path + src_config["chain_id"]: "config-%s" % src_config["chain_id"], + ibc_relay_config.relay_config_files_path + dst_config["chain_id"]: "config-%s" % dst_config["chain_id"], ibc_relay_config.relay_config_files_path: "run", }, - entrypoint = ["/bin/sh", "-c", "chmod +x ../script/run.sh && sh ../script/run.sh '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s'" % (src_chain_id, dst_chain_id, src_key, dst_key, src_config["endpoint"], dst_config["endpoint"], src_chain_seed["output"], dst_chain_seed["output"])], + entrypoint = ["/bin/sh", "-c", "chmod +x ../script/run.sh && sh ../script/run.sh '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s'" % (src_config["chain_id"], dst_config["chain_id"], src_config["chain_key"], dst_config["chain_key"], src_config["endpoint"], dst_config["endpoint"], src_chain_seed["output"], dst_chain_seed["output"])], ) plan.print(relay_service) @@ -93,23 +93,20 @@ def start_cosmos_relay(plan, src_key, src_chain_id, dst_key, dst_chain_id, src_c service_name = ibc_relay_config.relay_service_name, ) -def start_cosmos_relay_for_icon_to_cosmos(plan, src_chain_config, dst_chain_config, args): +def start_cosmos_relay_for_icon_to_cosmos(plan, src_chain, dst_chain, src_chain_config, dst_chain_config): plan.print("starting the cosmos relay for icon to cosmos") - source_chain = args["links"]["src"] - destination_chain = args["links"]["dst"] - - if destination_chain == "archway": + if dst_chain == "archway": plan.upload_files(src = ibc_relay_config.config_file_path, name = "archway_config") - elif destination_chain == "neutron": + elif dst_chain == "neutron": plan.upload_files(src = ibc_relay_config.config_file_path, name = "neutron_config") plan.upload_files(src = ibc_relay_config.icon_keystore_file, name = "icon-keystore") - if destination_chain == "archway": + if dst_chain == "archway": wasm_config = read_file(ibc_relay_config.ibc_relay_wasm_file_template) - elif destination_chain == "neutron": + elif dst_chain == "neutron": wasm_config = read_file(ibc_relay_config.ibc_relay_neutron_wasm_file_template) java_config = read_file(ibc_relay_config.ibc_relay_java_file_template) diff --git a/services/cosmvm/neutron/src/node-setup/start_node.star b/services/cosmvm/neutron/src/node-setup/start_node.star index bab20cce..a320d06c 100644 --- a/services/cosmvm/neutron/src/node-setup/start_node.star +++ b/services/cosmvm/neutron/src/node-setup/start_node.star @@ -3,7 +3,7 @@ constants = import_module("../../../../../package_io/constants.star") neutron_node_constants = constants.NEUTRON_SERVICE_CONFIG network_port_keys_and_ip = constants.NETWORK_PORT_KEYS_AND_IP_ADDRESS -def start_neutron_node(plan, chain_id, key, password, service_name, private_http_port, private_rcp_port, private_tcp_port, private_grpc_port, public_http_port, public_rcp_port, public_tcp_port, public_grpc_port): +def start_neutron_node(plan, chain_id, key, password, service_name, private_http_port, private_rpc_port, private_tcp_port, private_grpc_port, public_http_port, public_rpc_port, public_tcp_port, public_grpc_port): """ Start a Neutron node service with the provided configuration. @@ -54,7 +54,7 @@ def start_neutron_node(plan, chain_id, key, password, service_name, private_http wait = "2m", ), network_port_keys_and_ip.rpc: PortSpec( - number = private_rcp_port, + number = private_rpc_port, transport_protocol = network_port_keys_and_ip.tcp.upper(), application_protocol = network_port_keys_and_ip.http, wait = "2m", @@ -80,7 +80,7 @@ def start_neutron_node(plan, chain_id, key, password, service_name, private_http wait = "2m", ), network_port_keys_and_ip.rpc: PortSpec( - number = public_rcp_port, + number = public_rpc_port, transport_protocol = network_port_keys_and_ip.tcp.upper(), application_protocol = network_port_keys_and_ip.http, wait = "2m", diff --git a/services/evm/eth/eth.star b/services/evm/eth/eth.star index 3d8dcc9c..b8f993f3 100644 --- a/services/evm/eth/eth.star +++ b/services/evm/eth/eth.star @@ -31,20 +31,15 @@ def deploy_bmv_eth(plan, bridge, data, network, network_name, chain_name): """ Function to deploy a BMV Ethereum contract. - Args: - - plan: A plan object representing the deployment plan. - - bridge: A boolean indicating whether to deploy a bridge. - - data: Data required for contract deployment. - - network: The Ethereum network. - - network_name: The name of the Ethereum network. - - chain_name: The name of the chain. - Returns: The address of the deployed contract. """ if bridge == "true": - address = eth_relay_setup.deploy_bmv_bridge(plan, network, network_name, data.block_height, data.bmc, data.network, chain_name) + address = eth_relay_setup.deploy_bmv_bridge(plan, data.block_height, data.bmc, data.network, chain_name, network, network_name) + return address + + else : + address = eth_relay_setup.deploy_bmv(plan ,data.block_header, data.bmc, data.network, data.network_type_id, chain_name, network, network_name) return address - else: - address = eth_relay_setup.deploy_bmv(plan, network, network_name, data.block_header, data.bmc, data.network, data.network_type_id, chain_name) - return address \ No newline at end of file + + diff --git a/services/evm/eth/src/node-setup/contract-service.star b/services/evm/eth/src/node-setup/contract-service.star index 8f6f372a..db16535e 100644 --- a/services/evm/eth/src/node-setup/contract-service.star +++ b/services/evm/eth/src/node-setup/contract-service.star @@ -6,8 +6,8 @@ def start_deploy_service(plan, endpoint): Function to start the Ethereum contract deployment service. Args: - - plan: A plan object representing the deployment plan. - - endpoint: The service endpoint URL. + plan: plan. + endpoint: The service endpoint URL. Returns: The service response containing configuration data. @@ -46,15 +46,16 @@ def start_deploy_service(plan, endpoint): return service_response + # Returns Latest block def get_latest_block(plan, current_chain, network_name): """ Function to retrieve the latest block number from the Ethereum network. Args: - - plan: A plan object representing the deployment plan. - - current_chain: The current chain. - - network_name: The name of the Ethereum network. + plan: A plan object representing the deployment plan. + current_chain: The current chain. + network_name: The name of the Ethereum network. Returns: The latest block number as a string. diff --git a/services/evm/eth/src/node-setup/start-eth-node.star b/services/evm/eth/src/node-setup/start-eth-node.star index 5ec0b0cf..367b4bb2 100644 --- a/services/evm/eth/src/node-setup/start-eth-node.star +++ b/services/evm/eth/src/node-setup/start-eth-node.star @@ -12,7 +12,7 @@ def start_eth_node(plan): Function to start an Ethereum node. Args: - - plan: A plan object representing the node setup plan. + plan: plan. Returns: A dictionary containing configuration data for the started Ethereum node. @@ -75,7 +75,7 @@ def start_hardhat_node(plan): Function to start a Hardhat Ethereum node. Args: - - plan: A plan object representing the node setup plan. + plan: plan. Returns: Configuration data for the started Hardhat node service as a dictionary. diff --git a/services/evm/eth/src/relay-setup/contract_configuration.star b/services/evm/eth/src/relay-setup/contract_configuration.star index 876e5e12..42cb8845 100644 --- a/services/evm/eth/src/relay-setup/contract_configuration.star +++ b/services/evm/eth/src/relay-setup/contract_configuration.star @@ -1,75 +1,136 @@ eth_contract_deployer_service = import_module("../node-setup/contract-deployer.star") -# Deploy Bmc contract on ETH and Returns it's address -def deploy_bmc(plan, network, network_name, chain_name): - +def deploy_bmc(plan, chain_name, network, network_name): + """ + Deploy BMC on the ETH network. + + Args: + plan (Plan): plan. + chain_name (str): The name of the blockchain network. + network (str): The network identifier. + network_name (str): The name of the network. + + Returns: + struct: A struct containing addresses of deployed BMC-related contracts: + - bmcm: Address of the BMC Manager contract. + - bmcs: Address of the BMC Storage contract. + - bmc: Address of the BMC Contract. + """ plan.print("Deploying BMC Contract on %s" % network) - eth_contract_deployer_service.deploy_contract(plan,"bmc",'{\"link\":\"%s\",\"chainNetwork\":\"%s\"}' % (network_name,network),"localnet") + eth_contract_deployer_service.deploy_contract(plan, "bmc", '{"link":"%s","chainNetwork":"%s"}' % (network_name, network), "localnet") - bmc_address = eth_contract_deployer_service.get_contract_address(plan,"bmc",chain_name) + bmc_address = eth_contract_deployer_service.get_contract_address(plan, "bmc", chain_name) - bmcm_address = eth_contract_deployer_service.get_contract_address(plan,"bmcm",chain_name) + bmcm_address = eth_contract_deployer_service.get_contract_address(plan, "bmcm", chain_name) - bmcs_address = eth_contract_deployer_service.get_contract_address(plan,"bmcs",chain_name) + bmcs_address = eth_contract_deployer_service.get_contract_address(plan, "bmcs", chain_name) return struct( - bmcm = bmcm_address, - bmcs = bmcs_address, - bmc = bmc_address + bmcm=bmcm_address, + bmcs=bmcs_address, + bmc=bmc_address ) -# Deploy xCall Contract and returns it's address -def deploy_xcall(plan,network, network_name,chain_name,service_name): +def deploy_xcall(plan, chain_name, network, network_name): + """ + Deploy an xCall Contract on the ETH network. + + Args: + plan (Plan): plan. + chain_name (str): The name of the blockchain network. + network (str): The network identifier. + network_name (str): The name of the xCall contract. + + Returns: + str: The address of the deployed xCall Contract. + """ plan.print("Deploying xCall Contract on %s" % network) - eth_contract_deployer_service.deploy_contract(plan,"xcall",'{"name":"%s"}' % network_name,"localnet") + eth_contract_deployer_service.deploy_contract(plan, "xcall", '{"name":"%s"}' % network_name, "localnet") - xcall_address = eth_contract_deployer_service.get_contract_address(plan,"xcall",chain_name) + xcall_address = eth_contract_deployer_service.get_contract_address(plan, "xcall", chain_name) return xcall_address -# Deploy dapp Contract and returns it's address -def deploy_dapp(plan,network, network_name,chain_name,service_name): - plan.print("Deploying dapp Contract on %s" % network) +def deploy_dapp(plan, chain_name, network, network_name): + """ + Deploy a Dapp Contract on the ETH network. - eth_contract_deployer_service.deploy_contract(plan,"dapp",'{"name":"%s"}' % network_name,"localnet") + Args: + plan (Plan): The deployment plan. + chain_name (str): The name of the blockchain network. + network (str): The network identifier. + network_name (str): The name of the Dapp contract. - dapp_address = eth_contract_deployer_service.get_contract_address(plan,"dapp",chain_name) + Returns: + str: The address of the deployed Dapp Contract. + """ + plan.print("Deploying Dapp Contract on %s" % network) + + eth_contract_deployer_service.deploy_contract(plan, "dapp", '{"name":"%s"}' % network_name, "localnet") + + dapp_address = eth_contract_deployer_service.get_contract_address(plan, "dapp", chain_name) return dapp_address -# Deploy BmvBridge Contract and returns it's address -def deploy_bmv_bridge(plan,network, network_name ,lastblock_height,src_bmc_address,srcchain_network,chain_name,service_name): +def deploy_bmv_bridge(plan, lastblock_height, src_bmc_address, src_chain_network, chain_name, network, network_name): + """ + Deploy a BmvBridge Contract on the ETH network and return its address. + + Args: + plan (Plan): The deployment plan. + lastblock_height (str): The last block height on the source chain. + src_bmc_address (str): The address of the source BMC (Blockchain Management Contract). + src_chain_network (str): The network of the source chain. + chain_name (str): The name of the blockchain network. + network (str): The network identifier. + network_name (str): The name of the network. + + Returns: + str: The address of the deployed BmvBridge Contract. + """ plan.print("Deploying Bmv-Bridge Contract on %s" % network) - params = '{"current_chain":{"name":"%s"},"src":{"lastBlockHeight":"%s","bmc":"%s","network":"%s"}}' % (network_name,lastblock_height,src_bmc_address,srcchain_network) + params = '{"current_chain":{"name":"%s"},"src":{"lastBlockHeight":"%s","bmc":"%s","network":"%s"}}' % (network_name, lastblock_height, src_bmc_address, src_chain_network) - eth_contract_deployer_service.deploy_contract(plan,"bmv_bridge",params,"localnet") + eth_contract_deployer_service.deploy_contract(plan, "bmv_bridge", params, "localnet") - bmvb = eth_contract_deployer_service.get_contract_address(plan,"bmvb",chain_name) + bmvb = eth_contract_deployer_service.get_contract_address(plan, "bmvb", chain_name) return bmvb -# Deploy Bmv contract and returns it's address -def deploy_bmv(plan,network, network_name, src_first_block_header,src_bmc_address,srcchain_network,srcchain_network_type_id,chain_name): - - plan.print("Deploying Bmv Contract on %s" % network) - params = '{"current_chain":{"name":"%s"},"src":{"firstBlockHeader":"%s","bmc":"%s","network":"%s","networkTypeId":"%s"}}' % (network_name,src_first_block_header,src_bmc_address,srcchain_network,srcchain_network_type_id) +def deploy_bmv(plan, src_first_block_header, src_bmc_address, src_chain_network, src_chain_network_type_id, chain_name, network, network_name): + """ + Deploy a Bmv Contract on the specified network and return its address. - eth_contract_deployer_service.deploy_contract(plan,"bmv",params,"localnet") + Args: + plan (Plan): plan. + src_first_block_header (str): The first block header on the source chain. + src_bmc_address (str): The address of the source BMC (Blockchain Management Contract). + src_chain_network (str): The network of the source chain. + src_chain_network_type_id (str): The network type ID of the source chain. + chain_name (str): The name of the blockchain network. + network (str): The network identifier. + network_name (str): The name of the network. - bmv = eth_contract_deployer_service.get_contract_address(plan,"bmv",chain_name) + Returns: + str: The address of the deployed Bmv Contract. + """ + plan.print("Deploying Bmv Contract on %s" % network) - return bmv + params = '{"current_chain":{"name":"%s"},"src":{"firstBlockHeader":"%s","bmc":"%s","network":"%s","networkTypeId":"%s"}}' % (network_name, src_first_block_header, src_bmc_address, src_chain_network, src_chain_network_type_id) + eth_contract_deployer_service.deploy_contract(plan, "bmv", params, "localnet") + bmv = eth_contract_deployer_service.get_contract_address(plan, "bmv", chain_name) + return bmv diff --git a/services/jvm/icon/icon.star b/services/jvm/icon/icon.star index 76e064e6..a6ed74a9 100644 --- a/services/jvm/icon/icon.star +++ b/services/jvm/icon/icon.star @@ -20,14 +20,44 @@ ICON1_GENESIS_FILE_PATH = "../../static-files/config/genesis-icon-1.zip" ICON0_GENESIS_FILE_NAME = "genesis-icon-0.zip" ICON1_GENESIS_FILE_NAME = "genesis-icon-1.zip" -# Spins up ICON Nodes {ICON-0 & ICON-1} -def start_node_service_icon_to_icon(plan): - src_chain_config = icon_node_launcher.get_service_config(ICON0_NODE_PRIVATE_RPC_PORT, ICON0_NODE_PUBLIC_RPC_PORT, ICON0_NODE_P2P_LISTEN_ADDRESS, ICON0_NODE_P2P_ADDRESS, ICON0_NODE_CID) - dst_chain_config = icon_node_launcher.get_service_config(ICON1_NODE_PRIVATE_RPC_PORT, ICON1_NODE_PUBLIC_RPC_PORT, ICON1_NODE_P2P_LISTEN_ADDRESS, ICON1_NODE_P2P_ADDRESS, ICON1_NODE_CID) - source_chain_response = icon_node_launcher.start_icon_node(plan, src_chain_config, {}, ICON0_GENESIS_FILE_PATH, ICON0_GENESIS_FILE_NAME) +def start_node_service_icon_to_icon(plan): + """ + Spin up two ICON nodes, ICON-0 and ICON-1, and return their configuration. + + Args: + plan (Plan): The kurtosis plan for ICON nodes. + + Returns: + dict: A dictionary containing the service configuration for ICON-0 and ICON-1 nodes. + + Note: + This function starts two ICON nodes, ICON-0 and ICON-1, and retrieves their configuration. + It returns a dictionary with the configuration for both nodes. + """ + source_chain_response = icon_node_launcher.start_icon_node( + plan, + ICON0_NODE_PRIVATE_RPC_PORT, + ICON0_NODE_PUBLIC_RPC_PORT, + ICON0_NODE_P2P_LISTEN_ADDRESS, + ICON0_NODE_P2P_ADDRESS, + ICON0_NODE_CID, + {}, + ICON0_GENESIS_FILE_PATH, + ICON0_GENESIS_FILE_NAME + ) - destination_chain_response = icon_node_launcher.start_icon_node(plan, dst_chain_config, {}, ICON1_GENESIS_FILE_PATH, ICON1_GENESIS_FILE_NAME) + destination_chain_response = icon_node_launcher.start_icon_node( + plan, + ICON1_NODE_PRIVATE_RPC_PORT, + ICON1_NODE_PUBLIC_RPC_PORT, + ICON1_NODE_P2P_LISTEN_ADDRESS, + ICON1_NODE_P2P_ADDRESS, + ICON1_NODE_CID, + {}, + ICON1_GENESIS_FILE_PATH, + ICON1_GENESIS_FILE_NAME + ) src_service_config = { "service_name": source_chain_response.service_name, @@ -52,15 +82,35 @@ def start_node_service_icon_to_icon(plan): } return struct( - src_config = src_service_config, - dst_config = dst_service_config, + src_config=src_service_config, + dst_config=dst_service_config, ) -# Spins up single ICON node def start_node_service(plan): - chain_config = icon_node_launcher.get_service_config(ICON0_NODE_PRIVATE_RPC_PORT, ICON0_NODE_PUBLIC_RPC_PORT, ICON0_NODE_P2P_LISTEN_ADDRESS, ICON0_NODE_P2P_ADDRESS, ICON0_NODE_CID) - - node_service_response = icon_node_launcher.start_icon_node(plan, chain_config, {}, ICON0_GENESIS_FILE_PATH, ICON0_GENESIS_FILE_NAME) + """ + Spin up a single ICON node and return its configuration. + + Args: + plan (Plan): The kurtosis plan for starting the ICON node. + + Returns: + dict: A dictionary containing the configuration for the ICON node. + + Note: + This function starts a single ICON node and retrieves its configuration. + It returns a dictionary with the configuration for the node. + """ + node_service_response = icon_node_launcher.start_icon_node( + plan, + ICON0_NODE_PRIVATE_RPC_PORT, + ICON0_NODE_PUBLIC_RPC_PORT, + ICON0_NODE_P2P_LISTEN_ADDRESS, + ICON0_NODE_P2P_ADDRESS, + ICON0_NODE_CID, + {}, + ICON0_GENESIS_FILE_PATH, + ICON0_GENESIS_FILE_NAME + ) chain_service_config = { "service_name": node_service_response.service_name, @@ -75,93 +125,128 @@ def start_node_service(plan): return chain_service_config + # Configures ICON Nodes setup def configure_icon_to_icon_node(plan, src_chain_config, dst_chain_config): plan.print("Configuring ICON Nodes") + setup_node.configure_node(plan, src_chain_config["service_name"], src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) + setup_node.configure_node(plan, dst_chain_config["service_name"], dst_chain_config["endpoint"], dst_chain_config["keystore_path"], dst_chain_config["keypassword"], dst_chain_config["nid"]) - setup_node.configure_node(plan, src_chain_config) - setup_node.configure_node(plan, dst_chain_config) # Configures ICON Node setup -def configure_icon_node(plan, chain_config): +def configure_icon_node(plan, service_name, uri, keystorepath, keypassword, nid): plan.print("configure ICON Node") - - setup_node.configure_node(plan, chain_config) - -# Deploys BMC on ICON -def deploy_bmc_icon(plan, src_chain, dst_chain,src_chain_service_name,dst_chain_service_name, args): - src_config = args["chains"][src_chain_service_name] - - src_bmc_address = icon_relay_setup.deploy_bmc(plan, src_config) + setup_node.configure_node(plan, service_name, uri, keystorepath, keypassword, nid) + + +def deploy_bmc_icon( + plan, + src_chain, + dst_chain, + src_chain_config, + dst_chain_config +): + """ + Deploy a BMC (BTP Message center contract) on the source chain and optionally on the destination chain if both are ICON chains. + + Args: + plan (str): The name of the plan to deploy the BMC contract. + src_chain (str): The name of the source chain. + dst_chain (str): The name of the destination chain. + src_chain_config (dict): Source chain configuration, a dictionary containing the following parameters: + - "service_name": The name of the source chain's service. + - "network": The source chain's network. + - "endpoint": The endpoint URL for the source chain. + - "keystore_path": The path to the keystore file for the source chain. + - "keypassword": The password for the keystore. + - "nid": The Network ID for the source chain. + + dst_chain_config (dict): Destination chain configuration, a dictionary containing the following parameters: + - "service_name": The name of the destination chain's service. + - "network": destination chain's network. + - "endpoint": The endpoint URL for the destination chain. + - "keystore_path": The path to the keystore file for the destination chain. + - "keypassword": The password for the keystore. + - "nid": The Network ID for the destination chain. + + Returns: + str: The address of the deployed BMC contract on the source chain. + str (optional): The address of the deployed BMC contract on the destination chain if both are ICON chains. + """ + + src_bmc_address = icon_relay_setup.deploy_bmc(plan, src_chain_config["network"], src_chain_config["service_name"], src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) if src_chain == "icon" and dst_chain == "icon": - dst_config = args["chains"][dst_chain_service_name] - dst_bmc_address = icon_relay_setup.deploy_bmc(plan, dst_config) + dst_bmc_address = icon_relay_setup.deploy_bmc(plan, dst_chain_config["network"], dst_chain_config["service_name"], dst_chain_config["endpoint"], dst_chain_config["keystore_path"], dst_chain_config["keypassword"], dst_chain_config["nid"]) return src_bmc_address, dst_bmc_address return src_bmc_address -# Deploys BMV for ICON to ICON setup -def deploy_bmv_icon_to_icon(plan,src_chain_service_name,dst_chain_service_name, src_bmc_address, dst_bmc_address, args): - src_chain_config = args["chains"][src_chain_service_name] - dst_chain_config = args["chains"][dst_chain_service_name] - - src_chain_service = src_chain_config["service_name"] - src_chain_network = src_chain_config["network"] - src_chain_network_name = src_chain_config["network_name"] - src_chain_keystore_path = src_chain_config["keystore_path"] - src_chain_keypassword = src_chain_config["keypassword"] - src_chain_nid = src_chain_config["nid"] - src_chain_endpoint = src_chain_config["endpoint"] - - dst_chain_service = dst_chain_config["service_name"] - dst_chain_network = dst_chain_config["network"] - dst_chain_network_name = dst_chain_config["network_name"] - dst_chain_keystore_path = dst_chain_config["keystore_path"] - dst_chain_keypassword = dst_chain_config["keypassword"] - dst_chain_nid = dst_chain_config["nid"] - dst_chain_endpoint = dst_chain_config["endpoint"] - - src_last_block_height = setup_node.get_last_block(plan, src_chain_service) - dst_last_block_height = setup_node.get_last_block(plan, dst_chain_service) - - src_network_name = "{0}-{1}".format(src_chain_network_name, src_last_block_height) - dst_network_name = "{0}-{1}".format(dst_chain_network_name, dst_last_block_height) + +# Deploys BMV for ICON to ICON setup +def deploy_bmv_icon_to_icon( + plan, + src_chain_config, + dst_chain_config, + src_bmc_address, + dst_bmc_address +): + + """ + Deploy a BMV contract between two ICON networks. + + Args: + plan: The deployment plan. + src_chain_config (dict): Source chain configuration, a dictionary containing the following parameters: + - "service_name": The name of the source chain's service. + - "network_name": The name of the source chain's network. + - "endpoint": The endpoint URL for the source chain. + - "keystore_path": The path to the keystore file for the source chain. + - "keypassword": The password for the keystore. + - "nid": The Network ID for the source chain. + + dst_chain_config (dict): Destination chain configuration, a dictionary containing the following parameters: + - "service_name": The name of the destination chain's service. + - "network_name": The name of the destination chain's network. + - "endpoint": The endpoint URL for the destination chain. + - "keystore_path": The path to the keystore file for the destination chain. + - "keypassword": The password for the keystore. + - "nid": The Network ID for the destination chain. + + src_bmc_address (str): Source BMC (Blockchain Management Contract) address. + dst_bmc_address (str): Destination BMC address. + + Returns: + A struct containing information about the deployment. + """ + + src_last_block_height = setup_node.get_last_block(plan, src_chain_config["service_name"]) + dst_last_block_height = setup_node.get_last_block(plan, dst_chain_config["service_name"]) + src_network_name = "{0}-{1}".format(src_chain_config["network_name"], src_last_block_height) + dst_network_name = "{0}-{1}".format(dst_chain_config["network_name"], dst_last_block_height) src_data = { "name": src_network_name, "owner": src_bmc_address, } - dst_data = { "name": dst_network_name, "owner": dst_bmc_address, } - - src_open_btp_network_response = setup_node.open_btp_network(plan, src_chain_service, src_data, src_chain_endpoint, src_chain_keystore_path, src_chain_keypassword, src_chain_nid) - - dst_open_btp_network_response = setup_node.open_btp_network(plan, dst_chain_service, dst_data, dst_chain_endpoint, dst_chain_keystore_path, dst_chain_keypassword, dst_chain_nid) - - src_btp_network_info = setup_node.get_btp_network_info(plan, src_chain_service, src_open_btp_network_response["extract.network_id"]) - - src_first_block_header = setup_node.get_btp_header(plan, src_chain_service, src_open_btp_network_response["extract.network_id"], src_btp_network_info) - - dst_btp_network_info = setup_node.get_btp_network_info(plan, dst_chain_service, dst_open_btp_network_response["extract.network_id"]) - - dst_first_block_header = setup_node.get_btp_header(plan, dst_chain_service, dst_open_btp_network_response["extract.network_id"], dst_btp_network_info) - - src_bmv_address = icon_relay_setup.deploy_bmv_btpblock_java(plan, src_bmc_address, dst_chain_network, dst_open_btp_network_response["extract.network_type_id"], dst_first_block_header, src_chain_config) - - dst_bmv_address = icon_relay_setup.deploy_bmv_btpblock_java(plan, dst_bmc_address, src_chain_network, src_open_btp_network_response["extract.network_type_id"], src_first_block_header, dst_chain_config) - - src_relay_address = wallet.get_network_wallet_address(plan, src_chain_service) - dst_relay_address = wallet.get_network_wallet_address(plan, dst_chain_service) - - icon_relay_setup.setup_link_icon(plan, src_chain_service, src_bmc_address, dst_chain_network, dst_bmc_address, src_open_btp_network_response["extract.network_id"], src_bmv_address, src_relay_address, src_chain_config) - - icon_relay_setup.setup_link_icon(plan, dst_chain_service, dst_bmc_address, src_chain_network, src_bmc_address, dst_open_btp_network_response["extract.network_id"], dst_bmv_address, dst_relay_address, dst_chain_config) - + src_open_btp_network_response = setup_node.open_btp_network(plan, src_chain_config["service_name"], src_data, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) + dst_open_btp_network_response = setup_node.open_btp_network(plan, dst_chain_config["service_name"], dst_data, dst_chain_config["endpoint"], dst_chain_config["keystore_path"], dst_chain_config["keypassword"], dst_chain_config["nid"]) + src_btp_network_info = setup_node.get_btp_network_info(plan, src_chain_config["service_name"], src_open_btp_network_response["extract.network_id"]) + src_first_block_header = setup_node.get_btp_header(plan, src_chain_config["service_name"], src_open_btp_network_response["extract.network_id"], src_btp_network_info) + dst_btp_network_info = setup_node.get_btp_network_info(plan, dst_chain_config["service_name"], dst_open_btp_network_response["extract.network_id"]) + dst_first_block_header = setup_node.get_btp_header(plan, dst_chain_config["service_name"], dst_open_btp_network_response["extract.network_id"], dst_btp_network_info) + src_bmv_address = icon_relay_setup.deploy_bmv_btpblock_java(plan, src_bmc_address, dst_chain_config["network"], dst_open_btp_network_response["extract.network_type_id"], dst_first_block_header, src_chain_config["service_name"], src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) + dst_bmv_address = icon_relay_setup.deploy_bmv_btpblock_java(plan, dst_bmc_address, src_chain_config["network"], src_open_btp_network_response["extract.network_type_id"], src_first_block_header, dst_chain_config["service_name"], dst_chain_config["endpoint"], dst_chain_config["keystore_path"], dst_chain_config["keypassword"], dst_chain_config["nid"]) + src_relay_address = wallet.get_network_wallet_address(plan, src_chain_config["service_name"]) + dst_relay_address = wallet.get_network_wallet_address(plan, dst_chain_config["service_name"]) + icon_relay_setup.setup_link_icon(plan, src_chain_config["service_name"], src_bmc_address, dst_chain_config["network"], dst_bmc_address, src_open_btp_network_response["extract.network_id"], src_bmv_address, src_relay_address, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) + icon_relay_setup.setup_link_icon(plan, dst_chain_config["service_name"], dst_bmc_address, src_chain_config["network"], src_bmc_address, dst_open_btp_network_response["extract.network_id"], dst_bmv_address, dst_relay_address, dst_chain_config["endpoint"], dst_chain_config["keystore_path"], dst_chain_config["keypassword"], dst_chain_config["nid"]) + return struct( src_bmc = src_bmc_address, src_bmv = src_bmv_address, @@ -174,79 +259,124 @@ def deploy_bmv_icon_to_icon(plan,src_chain_service_name,dst_chain_service_name, dst_network_type_id = dst_open_btp_network_response["extract.network_type_id"], dst_network_id = dst_open_btp_network_response["extract.network_id"], ) + # Deploys xCall Contract on ICON nodes -def deploy_xcall_icon(plan, src_chain, dst_chain, src_bmc_address, dst_bmc_address, args,src_chain_service_name,dst_chain_service_name): - src_config = args["chains"][src_chain_service_name] - dst_config = args["chains"][dst_chain_service_name] +def deploy_xcall_icon(plan, src_chain, dst_chain, src_chain_config, dst_chain_config, src_bmc_address, dst_bmc_address): - src_xcall_address = icon_relay_setup.deploy_xcall(plan, src_bmc_address, src_config) + src_xcall_address = icon_relay_setup.deploy_xcall(plan, src_bmc_address, src_chain_config["service_name"], src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) if src_chain == "icon" and dst_chain == "icon": - dst_xcall_address = icon_relay_setup.deploy_xcall(plan, dst_bmc_address, dst_config) + dst_xcall_address = icon_relay_setup.deploy_xcall(plan, dst_bmc_address, dst_chain_config["service_name"], dst_chain_config["endpoint"], dst_chain_config["keystore_path"], dst_chain_config["keypassword"], dst_chain_config["nid"]) return src_xcall_address, dst_xcall_address return src_xcall_address -# Deploys dApp Contract on ICON nodes -def deploy_dapp_icon(plan, src_chain, dst_chain, src_xcall_address, dst_xcall_address, args,src_chain_service_name,dst_chain_service_name): - src_config = args["chains"][src_chain_service_name] - dst_config = args["chains"][dst_chain_service_name] - src_dapp_address = icon_relay_setup.deploy_dapp(plan, src_xcall_address, src_config) +# Deploys dApp Contract on ICON nodes +def deploy_dapp_icon(plan, src_chain, dst_chain, src_chain_config, dst_chain_config ,src_xcall_address, dst_xcall_address): + """ + Deploy DApp contract on ICON networks. + + Args: + plan (str): The deployment plan. + src_chain (str): The source chain name. + dst_chain (str): The destination chain name. + plan: The deployment plan. + src_chain_config (dict): Source chain configuration, a dictionary containing the following parameters: + - "service_name": The name of the source chain's service. + - "network_name": The name of the source chain's network. + - "endpoint": The endpoint URL for the source chain. + - "keystore_path": The path to the keystore file for the source chain. + - "keypassword": The password for the keystore. + - "nid": The Network ID for the source chain. + + dst_chain_config (dict): Destination chain configuration, a dictionary containing the following parameters: + - "service_name": The name of the destination chain's service. + - "network_name": The name of the destination chain's network. + - "endpoint": The endpoint URL for the destination chain. + - "keystore_path": The path to the keystore file for the destination chain. + - "keypassword": The password for the keystore. + - "nid": The Network ID for the destination chain. + + src_xcall_address (str): The source XCALL contract address. + dst_xcall_address (str): The destination XCALL contract address. + + Returns: + tuple or str: If both source and destination chains are "icon," returns a tuple of source and destination DApp contract addresses. + If only the source chain is "icon," returns the source DApp contract address as a string. + """ + src_dapp_address = icon_relay_setup.deploy_dapp(plan, src_xcall_address, src_chain_config["service_name"], src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) if src_chain == "icon" and dst_chain == "icon": - dst_dapp_address = icon_relay_setup.deploy_dapp(plan, dst_xcall_address, dst_config) + dst_dapp_address = icon_relay_setup.deploy_dapp(plan, dst_xcall_address, dst_chain_config["service_name"], dst_chain_config["endpoint"], dst_chain_config["keystore_path"], dst_chain_config["keypassword"], dst_chain_config["nid"]) return src_dapp_address, dst_dapp_address return src_dapp_address -# Deploy BMV on ICON Node -def deploy_bmv_icon(plan, src_chain_service_name, dst_chain_service_name, src_bmc_address, dst_bmc_address, dst_last_block_height, args): - src_chain_config = args["chains"][src_chain_service_name] - - src_chain_service = src_chain_config["service_name"] - src_chain_network = src_chain_config["network"] - src_chain_network_name = src_chain_config["network_name"] - src_chain_keystore_path = src_chain_config["keystore_path"] - src_chain_keypassword = src_chain_config["keypassword"] - src_chain_nid = src_chain_config["nid"] - src_chain_endpoint = src_chain_config["endpoint"] - - dst_chain_config = args["chains"][dst_chain_service_name] - dst_chain_service = dst_chain_config["service_name"] - dst_chain_network = dst_chain_config["network"] - dst_chain_network_name = dst_chain_config["network_name"] - dst_chain_keystore_path = dst_chain_config["keystore_path"] - dst_chain_keypassword = dst_chain_config["keypassword"] - dst_chain_nid = dst_chain_config["nid"] - dst_chain_endpoint = dst_chain_config["endpoint"] - - src_chain_last_block_height = setup_node.get_last_block(plan, src_chain_service) +# Deploy BMV on ICON Node +def deploy_bmv_icon( + plan, + src_bmc_address, + dst_bmc_address, + src_chain_config, + dst_chain_config, + dst_last_block_height +): + """ + Deploy BMV (BTP Multi-Validator) from one ICON network to another ICON network. + + Args: + plan (str): The deployment plan. + src_bmc_address (str): The source BMC (Blockchain Management Contract) address. + dst_bmc_address (str): The destination BMC address. + plan: The deployment plan. + src_chain_config (dict): Source chain configuration, a dictionary containing the following parameters: + - "service_name": The name of the source chain's service. + - "network_name": The name of the source chain's network. + - "endpoint": The endpoint URL for the source chain. + - "keystore_path": The path to the keystore file for the source chain. + - "keypassword": The password for the keystore. + - "nid": The Network ID for the source chain. + + dst_chain_config (dict): Destination chain configuration, a dictionary containing the following parameters: + - "service_name": The name of the destination chain's service. + - "network_name": The name of the destination chain's network. + - "endpoint": The endpoint URL for the destination chain. + - "keystore_path": The path to the keystore file for the destination chain. + - "keypassword": The password for the keystore. + - "nid": The Network ID for the destination chain. + + dst_last_block_height (str): The destination chain's last block height. + + Returns: + dict: A dictionary containing information about the deployment. + """ + src_chain_last_block_height = setup_node.get_last_block(plan, src_chain_config["service_name"]) plan.print("source block height %s" % src_chain_last_block_height) - network_name = "{0}-{1}".format(dst_chain_network_name, src_chain_last_block_height) + network_name = "{0}-{1}".format(dst_chain_config["network_name"], src_chain_last_block_height) src_data = { "name": network_name, "owner": src_bmc_address, } - src_open_btp_net_response = setup_node.open_btp_network(plan, src_chain_service, src_data, src_chain_endpoint, src_chain_keystore_path, src_chain_keypassword, src_chain_nid) + src_open_btp_net_response = setup_node.open_btp_network(plan, src_chain_config["service_name"], src_data, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) - src_btp_network_info = setup_node.get_btp_network_info(plan, src_chain_service, src_open_btp_net_response["extract.network_id"]) + src_btp_network_info = setup_node.get_btp_network_info(plan, src_chain_config["service_name"], src_open_btp_net_response["extract.network_id"]) - src_first_block_header = setup_node.get_btp_header(plan, src_chain_service, src_open_btp_net_response["extract.network_id"], src_btp_network_info) + src_first_block_header = setup_node.get_btp_header(plan, src_chain_config["service_name"], src_open_btp_net_response["extract.network_id"], src_btp_network_info) - src_bmv_address = icon_relay_setup.deploy_bmv_bridge_java(plan, src_chain_service, src_bmc_address, dst_chain_network, dst_last_block_height, src_chain_config) + src_bmv_address = icon_relay_setup.deploy_bmv_bridge_java(plan, src_chain_config["service_name"], src_bmc_address, dst_chain_config["network"], dst_last_block_height, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) - relay_address = wallet.get_network_wallet_address(plan, src_chain_service) + relay_address = wallet.get_network_wallet_address(plan, src_chain_config["service_name"]) - icon_relay_setup.setup_link_icon(plan, src_chain_service, src_bmc_address, dst_chain_network, dst_bmc_address, src_open_btp_net_response["extract.network_id"], src_bmv_address, relay_address, src_chain_config) + icon_relay_setup.setup_link_icon(plan, src_chain_config["service_name"], src_bmc_address, dst_chain_config["network"], dst_bmc_address, src_open_btp_net_response["extract.network_id"], src_bmv_address, relay_address, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) return struct( bmc = src_bmc_address, @@ -255,5 +385,5 @@ def deploy_bmv_icon(plan, src_chain_service_name, dst_chain_service_name, src_bm network_id = src_open_btp_net_response["extract.network_id"], block_header = src_first_block_header, block_height = src_chain_last_block_height, - network = src_chain_network, + network = src_chain_config["network"], ) diff --git a/services/jvm/icon/src/node-setup/contract_deploy.star b/services/jvm/icon/src/node-setup/contract_deploy.star index 2ca63ae2..133cea67 100644 --- a/services/jvm/icon/src/node-setup/contract_deploy.star +++ b/services/jvm/icon/src/node-setup/contract_deploy.star @@ -1,44 +1,84 @@ DEFAULT_STEP_LIMIT = "500000000000" -""" -Deploys Contract on Icon Chain -'contract_name' - Name of the Contract to be deployed -'args' - Dict of params for deployment -""" -def deploy_contract(plan,contract_name,init_message,args): - contract = contract_name+".jar" - service_name = args["service_name"] - uri = args["endpoint"] - keystore_path = args["keystore_path"] - keystore_password = args["keypassword"] - nid = args["nid"] +def deploy_contract(plan, contract_name, init_message, service_name, uri, keystore_path, keystore_password, nid): + """ + Deploy a smart contract to the icon. + Args: + plan (Plan): The kurtosis plan. + contract_name (str): The name of the contract. + init_message (str): The initialization message for the contract. + service_name (str): The name of the service to execute the deployment. + uri (str): The URI for connecting to the Goloop blockchain. + keystore_path (str): The path to the keystore for signing the deployment. + keystore_password (str): The password for the keystore. + nid (str): The network ID of the Goloop blockchain. - execute_command = ["./bin/goloop","rpc","sendtx","deploy","contracts/"+contract,"--content_type","application/java","--params",init_message,"--key_store",keystore_path,"--key_password",keystore_password,"--step_limit",DEFAULT_STEP_LIMIT,"--uri",uri,"--nid",nid] + Returns: + str: The output of the deployment. + + Note: + This function deploys a smart contract to the Goloop blockchain by sending a transaction. + + """ + contract = contract_name + ".jar" + + execute_command = [ + "./bin/goloop", + "rpc", + "sendtx", + "deploy", + "contracts/" + contract, + "--content_type", + "application/java", + "--params", + init_message, + "--key_store", + keystore_path, + "--key_password", + keystore_password, + "--step_limit", + DEFAULT_STEP_LIMIT, + "--uri", + uri, + "--nid", + nid, + ] plan.print(execute_command) - result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=execute_command)) + result = plan.exec(service_name=service_name, recipe=ExecRecipe(command=execute_command)) return result["output"] -""" -Returns Contract Address -'tx_hash' - transaction hash -""" -def get_score_address(plan,service_name,tx_hash): +def get_score_address(plan, service_name, tx_hash): + """ + Get the score address for a given transaction hash. + + Args: + plan (Plan): The kurtosis plan. + service_name (str): The name of the service to execute the request. + tx_hash (str): The transaction hash for which to retrieve the score address. + + Returns: + str: The score address extracted from the transaction result. + + Note: + This function sends a POST request to the Icon blockchain to retrieve the score address + associated with a given transaction hash. + + """ post_request = PostHttpRequestRecipe( port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", - body='{ "jsonrpc": "2.0", "method": "icx_getTransactionResult", "id": 1, "params": { "txHash": %s } }' % tx_hash, + body='{"jsonrpc": "2.0", "method": "icx_getTransactionResult", "id": 1, "params": {"txHash": %s }}' % tx_hash, extract={ - "score_address":".result.scoreAddress" + "score_address": ".result.scoreAddress" } ) - result = plan.wait(service_name=service_name,recipe=post_request,field="code",assertion="==",target_value=200) + result = plan.wait(service_name=service_name, recipe=post_request, field="code", assertion="==", target_value=200) return result["extract.score_address"] - diff --git a/services/jvm/icon/src/node-setup/setup_icon_node.star b/services/jvm/icon/src/node-setup/setup_icon_node.star index 5b7a6178..1210ebc4 100644 --- a/services/jvm/icon/src/node-setup/setup_icon_node.star +++ b/services/jvm/icon/src/node-setup/setup_icon_node.star @@ -1,414 +1,736 @@ wallet_config = import_module("./wallet.star") -BTP_VERSION = "21" # REV Version +BTP_VERSION = "21" # REV Version + # Returns the Main PREPS of the Network -def get_main_preps(plan,service_name,uri): +def get_main_preps(plan, service_name, uri): post_request = PostHttpRequestRecipe( port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", - body = '{ "jsonrpc": "2.0", "id": 1, "method": "icx_call", "params": { "to": "cx0000000000000000000000000000000000000000", "dataType": "call", "data": { "method": "getMainPReps", "params": { } } } }', + body='{ "jsonrpc": "2.0", "id": 1, "method": "icx_call", "params": { "to": "cx0000000000000000000000000000000000000000", "dataType": "call", "data": { "method": "getMainPReps", "params": { } } } }', + ) + result = plan.wait( + service_name=service_name, + recipe=post_request, + field="code", + assertion="==", + target_value=200, ) - result = plan.wait(service_name=service_name,recipe=post_request,field="code",assertion="==",target_value=200) - + return result + # Returns the PREP of the network -def get_prep(plan,service_name,prep_address,uri): +def get_prep(plan, service_name, prep_address, uri): post_request = PostHttpRequestRecipe( port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", - body='{"jsonrpc": "2.0","id": 1,"method": "icx_call","params": {"to": "cx0000000000000000000000000000000000000000", "dataType": "call","data": {"method": "getPRep", "params": {"address": "%s" }}}}' % prep_address, + body='{"jsonrpc": "2.0","id": 1,"method": "icx_call","params": {"to": "cx0000000000000000000000000000000000000000", "dataType": "call","data": {"method": "getPRep", "params": {"address": "%s" }}}}' + % prep_address, extract={ - "result_body" : '. | if .error != null then .error else .result end', - "code" : '.| if .error.code != null then .error.code else 0 end | tonumber ' - } + "result_body": ". | if .error != null then .error else .result end", + "code": ".| if .error.code != null then .error.code else 0 end | tonumber ", + }, + ) + result = plan.wait( + service_name=service_name, + recipe=post_request, + field="code", + assertion=">=", + target_value=200, ) - result = plan.wait(service_name=service_name,recipe=post_request,field="code",assertion=">=",target_value=200) return result -# Returns Total ICX supply -def get_total_supply(plan,service_name): - post_request= PostHttpRequestRecipe( +# Returns Total ICX supply +def get_total_supply(plan, service_name): + post_request = PostHttpRequestRecipe( port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", body='{ "jsonrpc": "2.0", "method": "icx_getTotalSupply", "id": 1 }', extract={ - "supply":".result[2:]| explode | reverse | map(if . > 96 then . - 87 else . - 48 end) | reduce .[] as $c ([1,0]; (.[0] * 16) as $b | [$b, .[1] + (.[0] * $c)])| .[1] | tonumber" - } - ) - result = plan.wait(service_name=service_name,recipe=post_request,field="code",assertion="==",target_value=200) + "supply": ".result[2:]| explode | reverse | map(if . > 96 then . - 87 else . - 48 end) | reduce .[] as $c ([1,0]; (.[0] * 16) as $b | [$b, .[1] + (.[0] * $c)])| .[1] | tonumber" + }, + ) + result = plan.wait( + service_name=service_name, + recipe=post_request, + field="code", + assertion="==", + target_value=200, + ) return result["extract.supply"] -def register_prep(plan,service_name,name,uri,keystorepath,keypassword,nid): - +def register_prep(plan, service_name, name, uri, keystorepath, keypassword, nid): method = "registerPRep" value = "0x6c6b935b8bbd400000" - params = '{"name": "%s","country": "KOR", "city": "Seoul", "email": "test@example.com", "website": "https://test.example.com", "details": "https://test.example.com/details", "p2pEndpoint": "test.example.com:7100"}' % name - - - - exec_command = ["./bin/goloop","rpc","sendtx","call","--to","cx0000000000000000000000000000000000000000","--method",method,"--value",value,"--params",params,"--uri",uri,"--key_store",keystorepath,"--key_password",keypassword,"--step_limit","50000000000","--nid",nid] + params = ( + '{"name": "%s","country": "KOR", "city": "Seoul", "email": "test@example.com", "website": "https://test.example.com", "details": "https://test.example.com/details", "p2pEndpoint": "test.example.com:7100"}' + % name + ) - result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=exec_command)) + exec_command = [ + "./bin/goloop", + "rpc", + "sendtx", + "call", + "--to", + "cx0000000000000000000000000000000000000000", + "--method", + method, + "--value", + value, + "--params", + params, + "--uri", + uri, + "--key_store", + keystorepath, + "--key_password", + keypassword, + "--step_limit", + "50000000000", + "--nid", + nid, + ] + + result = plan.exec( + service_name=service_name, recipe=ExecRecipe(command=exec_command) + ) tx_hash = result["output"] + tx_result = get_tx_result(plan, service_name, tx_hash, uri) - tx_result = get_tx_result(plan,service_name,tx_hash,uri) - - plan.verify(value=tx_result["extract.status"],assertion="==",target_value="0x1") + plan.verify(value=tx_result["extract.status"], assertion="==", target_value="0x1") plan.print("Completed RegisterPrep") -# Returns transaction result based on the tx_hash -def get_tx_result(plan,service_name,tx_hash,uri): +# Returns transaction result based on the tx_hash +def get_tx_result(plan, service_name, tx_hash, uri): post_request = PostHttpRequestRecipe( port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", - body='{ "jsonrpc": "2.0", "method": "icx_getTransactionResult", "id": 1, "params": { "txHash": %s } }' % tx_hash, - extract={ - "status":".result.status" - } + body='{ "jsonrpc": "2.0", "method": "icx_getTransactionResult", "id": 1, "params": { "txHash": %s } }' + % tx_hash, + extract={"status": ".result.status"}, + ) + + result = plan.wait( + service_name=service_name, + recipe=post_request, + field="code", + assertion="==", + target_value=200, ) - - result = plan.wait(service_name=service_name,recipe=post_request,field="code",assertion="==",target_value=200) return result + # Sets Stake based on the `amount` given -def set_stake(plan,service_name,amount,uri,keystorepath,keypassword,nid): - +def set_stake(plan, service_name, amount, uri, keystorepath, keypassword, nid): method = "setStake" - + params = '{"value": "%s" }' % amount - exec_command = ["./bin/goloop","rpc","sendtx","call","--to","cx0000000000000000000000000000000000000000","--method",method,"--params",params,"--uri",uri,"--key_store",keystorepath,"--key_password",keypassword,"--step_limit","50000000000","--nid",nid] + exec_command = [ + "./bin/goloop", + "rpc", + "sendtx", + "call", + "--to", + "cx0000000000000000000000000000000000000000", + "--method", + method, + "--params", + params, + "--uri", + uri, + "--key_store", + keystorepath, + "--key_password", + keypassword, + "--step_limit", + "50000000000", + "--nid", + nid, + ] plan.print(exec_command) - result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=exec_command)) + result = plan.exec( + service_name=service_name, recipe=ExecRecipe(command=exec_command) + ) tx_hash = result["output"] - tx_result = get_tx_result(plan,service_name,tx_hash,uri) + tx_result = get_tx_result(plan, service_name, tx_hash, uri) - plan.verify(value=tx_result["extract.status"],assertion="==",target_value="0x1") + plan.verify(value=tx_result["extract.status"], assertion="==", target_value="0x1") plan.print("Set Stake Completed") -# Sets Delegation to `address` based on the `amount` given -def set_delegation(plan,service_name,address,amount,uri,keystorepath,keypassword,nid): - method="setDelegation" - params='{"delegations":[{"address":"%s","value":"%s"}]}' % (address,amount) - exec_command = ["./bin/goloop","rpc","sendtx","call","--to","cx0000000000000000000000000000000000000000","--method",method,"--params",params,"--uri",uri,"--key_store",keystorepath,"--key_password",keypassword,"--step_limit","50000000000","--nid",nid] +# Sets Delegation to `address` based on the `amount` given +def set_delegation( + plan, service_name, address, amount, uri, keystorepath, keypassword, nid +): + method = "setDelegation" + params = '{"delegations":[{"address":"%s","value":"%s"}]}' % (address, amount) + + exec_command = [ + "./bin/goloop", + "rpc", + "sendtx", + "call", + "--to", + "cx0000000000000000000000000000000000000000", + "--method", + method, + "--params", + params, + "--uri", + uri, + "--key_store", + keystorepath, + "--key_password", + keypassword, + "--step_limit", + "50000000000", + "--nid", + nid, + ] plan.print(exec_command) - result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=exec_command)) + result = plan.exec( + service_name=service_name, recipe=ExecRecipe(command=exec_command) + ) tx_hash = result["output"] - tx_result = get_tx_result(plan,service_name,tx_hash,uri) + tx_result = get_tx_result(plan, service_name, tx_hash, uri) - plan.verify(value=tx_result["extract.status"],assertion="==",target_value="0x1") + plan.verify(value=tx_result["extract.status"], assertion="==", target_value="0x1") -# Sets the bonder list with `address` specified -def set_bonder_list(plan,service_name,address,uri,keystorepath,keypassword,nid): - method="setBonderList" - params='{"bonderList":["%s"]}' % address - exec_command = ["./bin/goloop","rpc","sendtx","call","--to","cx0000000000000000000000000000000000000000","--method",method,"--params",params,"--uri",uri,"--key_store",keystorepath,"--key_password",keypassword,"--step_limit","50000000000","--nid",nid] - result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=exec_command)) +# Sets the bonder list with `address` specified +def set_bonder_list(plan, service_name, address, uri, keystorepath, keypassword, nid): + method = "setBonderList" + params = '{"bonderList":["%s"]}' % address + + exec_command = [ + "./bin/goloop", + "rpc", + "sendtx", + "call", + "--to", + "cx0000000000000000000000000000000000000000", + "--method", + method, + "--params", + params, + "--uri", + uri, + "--key_store", + keystorepath, + "--key_password", + keypassword, + "--step_limit", + "50000000000", + "--nid", + nid, + ] + result = plan.exec( + service_name=service_name, recipe=ExecRecipe(command=exec_command) + ) tx_hash = result["output"] - tx_result = get_tx_result(plan,service_name,tx_hash,uri) + tx_result = get_tx_result(plan, service_name, tx_hash, uri) - plan.verify(value=tx_result["extract.status"],assertion="==",target_value="0x1") + plan.verify(value=tx_result["extract.status"], assertion="==", target_value="0x1") -# Sets Bond `amount` to `address` -def set_bond(plan,service_name,address,amount,uri,keystorepath,keypassword,nid): - - method="setBond" - params='{"bonds":[{"address":"%s","value":"%s"}]}' % (address,amount) - exec_command = ["./bin/goloop","rpc","sendtx","call","--to","cx0000000000000000000000000000000000000000","--method",method,"--params",params,"--uri",uri,"--key_store",keystorepath,"--key_password",keypassword,"--step_limit","50000000000","--nid",nid] - result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=exec_command)) +# Sets Bond `amount` to `address` +def set_bond(plan, service_name, address, amount, uri, keystorepath, keypassword, nid): + method = "setBond" + params = '{"bonds":[{"address":"%s","value":"%s"}]}' % (address, amount) + + exec_command = [ + "./bin/goloop", + "rpc", + "sendtx", + "call", + "--to", + "cx0000000000000000000000000000000000000000", + "--method", + method, + "--params", + params, + "--uri", + uri, + "--key_store", + keystorepath, + "--key_password", + keypassword, + "--step_limit", + "50000000000", + "--nid", + nid, + ] + result = plan.exec( + service_name=service_name, recipe=ExecRecipe(command=exec_command) + ) tx_hash = result["output"] - tx_result = get_tx_result(plan,service_name,tx_hash,uri) + tx_result = get_tx_result(plan, service_name, tx_hash, uri) - plan.verify(value=tx_result["extract.status"],assertion="==",target_value="0x1") + plan.verify(value=tx_result["extract.status"], assertion="==", target_value="0x1") -# Returns Network revision -def get_revision(plan,service_name): +# Returns Network revision +def get_revision(plan, service_name): post_request = PostHttpRequestRecipe( port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", body='{"jsonrpc": "2.0","id": 1,"method": "icx_call","params": {"to": "cx0000000000000000000000000000000000000000", "dataType": "call","data": {"method": "getRevision", "params": { }}}}', extract={ - "rev_number": '.result[2:]| explode | reverse | map(if . > 96 then . - 87 else . - 48 end) | reduce .[] as $c ([1,0]; (.[0] * 16) as $b | [$b, .[1] + (.[0] * $c)])| .[1] | tonumber ' - } + "rev_number": ".result[2:]| explode | reverse | map(if . > 96 then . - 87 else . - 48 end) | reduce .[] as $c ([1,0]; (.[0] * 16) as $b | [$b, .[1] + (.[0] * $c)])| .[1] | tonumber " + }, + ) + result = plan.wait( + service_name=service_name, + recipe=post_request, + field="code", + assertion="==", + target_value=200, ) - result = plan.wait(service_name=service_name,recipe=post_request,field="code",assertion="==",target_value=200) - return result["extract.rev_number"] -# Sets Network Revision -def set_revision(plan,service_name,uri,code,keystorepath,keypassword,nid): - - method="setRevision" - params='{"code":"%s"}' % code - exec_command = ["./bin/goloop","rpc","sendtx","call","--to","cx0000000000000000000000000000000000000001","--method",method,"--params",params,"--uri",uri,"--key_store",keystorepath,"--key_password",keypassword,"--step_limit","50000000000","--nid",nid] - result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=exec_command)) +# Sets Network Revision +def set_revision(plan, service_name, uri, code, keystorepath, keypassword, nid): + method = "setRevision" + params = '{"code":"%s"}' % code + + exec_command = [ + "./bin/goloop", + "rpc", + "sendtx", + "call", + "--to", + "cx0000000000000000000000000000000000000001", + "--method", + method, + "--params", + params, + "--uri", + uri, + "--key_store", + keystorepath, + "--key_password", + keypassword, + "--step_limit", + "50000000000", + "--nid", + nid, + ] + result = plan.exec( + service_name=service_name, recipe=ExecRecipe(command=exec_command) + ) tx_hash = result["output"] - tx_result = get_tx_result(plan,service_name,tx_hash,uri) + tx_result = get_tx_result(plan, service_name, tx_hash, uri) + + plan.verify(value=tx_result["extract.status"], assertion="==", target_value="0x1") - plan.verify(value=tx_result["extract.status"],assertion="==",target_value="0x1") # Returns PREP Node Publci Key using `address` specified -def get_prep_node_public_key(plan,service_name,address): +def get_prep_node_public_key(plan, service_name, address): post_request = PostHttpRequestRecipe( port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", - body='{"jsonrpc": "2.0","id": 1,"method": "icx_call","params": {"to": "cx0000000000000000000000000000000000000000", "dataType": "call","data": {"method": "getPRepNodePublicKey", "params": { "address": %s}}}}' % address, - - + body='{"jsonrpc": "2.0","id": 1,"method": "icx_call","params": {"to": "cx0000000000000000000000000000000000000000", "dataType": "call","data": {"method": "getPRepNodePublicKey", "params": { "address": %s}}}}' + % address, + ) + result = plan.wait( + service_name=service_name, + recipe=post_request, + field="code", + assertion=">=", + target_value=200, ) - result = plan.wait(service_name=service_name,recipe=post_request,field="code",assertion=">=",target_value=200) return result -# Registers PREP Node Public Key -def register_prep_node_publickey(plan,service_name,address,pubkey,uri,keystorepath,keypassword,nid): - method="registerPRepNodePublicKey" - - params="{\"address\":\"%s\",\"pubKey\":\"%s\"}" % (address,pubkey) - exec_command = ["./bin/goloop","rpc","sendtx","call","--to","cx0000000000000000000000000000000000000000","--method",method,"--params",params,"--uri",uri,"--key_store",keystorepath,"--key_password",keypassword,"--step_limit","50000000000","--nid",nid] +# Registers PREP Node Public Key +def register_prep_node_publickey( + plan, service_name, address, pubkey, uri, keystorepath, keypassword, nid +): + method = "registerPRepNodePublicKey" + + params = '{"address":"%s","pubKey":"%s"}' % (address, pubkey) + + exec_command = [ + "./bin/goloop", + "rpc", + "sendtx", + "call", + "--to", + "cx0000000000000000000000000000000000000000", + "--method", + method, + "--params", + params, + "--uri", + uri, + "--key_store", + keystorepath, + "--key_password", + keypassword, + "--step_limit", + "50000000000", + "--nid", + nid, + ] plan.print(exec_command) - result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=exec_command)) + result = plan.exec( + service_name=service_name, recipe=ExecRecipe(command=exec_command) + ) tx_hash = result["output"] - tx_result = get_tx_result(plan,service_name,tx_hash,uri) - - plan.verify(value=tx_result["extract.status"],assertion="==",target_value="0x1") - -# Start decentralisation for btp relay -def ensure_decentralisation(plan,service_name,prep_address,uri,keystorepath,keypassword,nid): + tx_result = get_tx_result(plan, service_name, tx_hash, uri) + plan.verify(value=tx_result["extract.status"], assertion="==", target_value="0x1") +# Start decentralisation for btp relay +def ensure_decentralisation( + plan, service_name, prep_address, uri, keystorepath, keypassword, nid +): plan.print("registerPRep") - name = "node_"+prep_address + name = "node_" + prep_address - total_supply = get_total_supply(plan,service_name) - min_delegated = get_min_delegated_amount(plan,service_name,total_supply) + total_supply = get_total_supply(plan, service_name) + min_delegated = get_min_delegated_amount(plan, service_name, total_supply) bond_amount = "0x152d02c7e14af6800000" - stake = get_stake_amount(plan,service_name,bond_amount,min_delegated) + stake = get_stake_amount(plan, service_name, bond_amount, min_delegated) - response = register_prep(plan,service_name,name,uri,keystorepath,keypassword,nid) + response = register_prep( + plan, service_name, name, uri, keystorepath, keypassword, nid + ) plan.print("ICON: setStake") - set_stake(plan,service_name,stake,uri,keystorepath,keypassword,nid) + set_stake(plan, service_name, stake, uri, keystorepath, keypassword, nid) plan.print("ICON: setDelegation") - set_delegation(plan,service_name,prep_address,min_delegated,uri,keystorepath,keypassword,nid) + set_delegation( + plan, + service_name, + prep_address, + min_delegated, + uri, + keystorepath, + keypassword, + nid, + ) plan.print("ICON: setBonderList") - set_bonder_list(plan,service_name,prep_address,uri,keystorepath,keypassword,nid) + set_bonder_list( + plan, service_name, prep_address, uri, keystorepath, keypassword, nid + ) plan.print("ICON: setBond") - set_bond(plan,service_name,prep_address,bond_amount,uri,keystorepath,keypassword,nid) + set_bond( + plan, + service_name, + prep_address, + bond_amount, + uri, + keystorepath, + keypassword, + nid, + ) + # Setup Node for Btp Blocks -def setup_node(plan,service_name,uri,keystorepath,keypassword,nid,prep_address): - - revision = get_revision(plan,service_name) - +def setup_node(plan, service_name, uri, keystorepath, keypassword, nid, prep_address): + revision = get_revision(plan, service_name) + plan.print("ICON: revision:%s " % revision) if revision != BTP_VERSION: plan.print("ICON: set revision to %s" % BTP_VERSION) - set_revision(plan,service_name,uri,BTP_VERSION,keystorepath,keypassword,nid) + set_revision( + plan, service_name, uri, BTP_VERSION, keystorepath, keypassword, nid + ) - pub_key = get_prep_node_public_key(plan,service_name,prep_address) + pub_key = get_prep_node_public_key(plan, service_name, prep_address) plan.print(pub_key["body"]) - pub_key = wallet_config.get_network_wallet_public_key(plan,service_name) + pub_key = wallet_config.get_network_wallet_public_key(plan, service_name) + + register_node_pubkey = register_prep_node_publickey( + plan, service_name, prep_address, pub_key, uri, keystorepath, keypassword, nid + ) + - register_node_pubkey = register_prep_node_publickey(plan,service_name,prep_address,pub_key,uri,keystorepath,keypassword,nid) - # Returns Int from Hex value -def hex_to_int(plan,service_name,hex_number): - exec_command = ["python","-c","print(int(%s))" % hex_number] - result = plan.exec(service_name,recipe=ExecRecipe(command=exec_command)) +def hex_to_int(plan, service_name, hex_number): + exec_command = ["python", "-c", "print(int(%s))" % hex_number] + result = plan.exec(service_name, recipe=ExecRecipe(command=exec_command)) + + execute_cmd = ExecRecipe( + command=["/bin/sh", "-c", "echo \"%s\" | tr -d '\n\r'" % result["output"]] + ) + result = plan.exec(service_name=service_name, recipe=execute_cmd) - execute_cmd = ExecRecipe(command=["/bin/sh", "-c","echo \"%s\" | tr -d '\n\r'" % result["output"] ]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) - return result["output"] + # Returns Minimum Amount for Delegation -def get_min_delegated_amount(plan,service_name,total_supply): - exec_command = ["python","-c","print(hex(int(%s / 500)))" % total_supply] - result = plan.exec(service_name,recipe=ExecRecipe(exec_command)) +def get_min_delegated_amount(plan, service_name, total_supply): + exec_command = ["python", "-c", "print(hex(int(%s / 500)))" % total_supply] + result = plan.exec(service_name, recipe=ExecRecipe(exec_command)) - execute_cmd = ExecRecipe(command=["/bin/sh", "-c","echo \"%s\" | tr -d '\n\r'" % result["output"] ]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) + execute_cmd = ExecRecipe( + command=["/bin/sh", "-c", "echo \"%s\" | tr -d '\n\r'" % result["output"]] + ) + result = plan.exec(service_name=service_name, recipe=execute_cmd) return result["output"] -# Calaculates the Amount for Staking -def get_stake_amount(plan,service_name,bond_amount,min_delegated): - exec_command = ["python","-c","print(hex(int(%s) + int(%s)))" %(min_delegated,bond_amount)] - result = plan.exec(service_name,recipe=ExecRecipe(exec_command)) - execute_cmd = ExecRecipe(command=["/bin/sh", "-c","echo \"%s\" | tr -d '\n\r'" % result["output"] ]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) +# Calaculates the Amount for Staking +def get_stake_amount(plan, service_name, bond_amount, min_delegated): + exec_command = [ + "python", + "-c", + "print(hex(int(%s) + int(%s)))" % (min_delegated, bond_amount), + ] + result = plan.exec(service_name, recipe=ExecRecipe(exec_command)) + + execute_cmd = ExecRecipe( + command=["/bin/sh", "-c", "echo \"%s\" | tr -d '\n\r'" % result["output"]] + ) + result = plan.exec(service_name=service_name, recipe=execute_cmd) return result["output"] + # Configure nodes def configure_node(plan, service_name, uri, keystorepath, keypassword, nid): - plan.print("Configuring ICON Node") - prep_address = wallet_config.get_network_wallet_address(plan,service_name) - - ensure_decentralisation(plan,service_name,prep_address,uri,keystorepath,keypassword,nid) + prep_address = wallet_config.get_network_wallet_address(plan, service_name) - plan.wait(service_name,recipe=ExecRecipe(command=["/bin/sh","-c","sleep 40s && echo 'success'"]),field="code",assertion="==",target_value=0,timeout="200s") + ensure_decentralisation( + plan, service_name, prep_address, uri, keystorepath, keypassword, nid + ) + + plan.wait( + service_name, + recipe=ExecRecipe(command=["/bin/sh", "-c", "sleep 40s && echo 'success'"]), + field="code", + assertion="==", + target_value=0, + timeout="200s", + ) - main_preps = get_main_preps(plan,service_name,uri) + main_preps = get_main_preps(plan, service_name, uri) plan.print(main_preps) - setup_node(plan,service_name,uri,keystorepath,keypassword,nid,prep_address) + setup_node(plan, service_name, uri, keystorepath, keypassword, nid, prep_address) -# Opens Btp Netwok -def open_btp_network(plan,service_name,args,uri,keystorepath,keypassword,nid): + +# Opens Btp Netwok +def open_btp_network(plan, service_name, args, uri, keystorepath, keypassword, nid): name = args["name"] owner = args["owner"] - method="openBTPNetwork" - params='{"networkTypeName":"eth","name":"%s","owner":"%s"}' % (name,owner) - - exec_command = ["./bin/goloop","rpc","sendtx","call","--to","cx0000000000000000000000000000000000000001","--method",method,"--params",params,"--uri",uri,"--key_store",keystorepath,"--key_password",keypassword,"--step_limit","50000000000","--nid",nid] - result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=exec_command)) + method = "openBTPNetwork" + params = '{"networkTypeName":"eth","name":"%s","owner":"%s"}' % (name, owner) + + exec_command = [ + "./bin/goloop", + "rpc", + "sendtx", + "call", + "--to", + "cx0000000000000000000000000000000000000001", + "--method", + method, + "--params", + params, + "--uri", + uri, + "--key_store", + keystorepath, + "--key_password", + keypassword, + "--step_limit", + "50000000000", + "--nid", + nid, + ] + result = plan.exec( + service_name=service_name, recipe=ExecRecipe(command=exec_command) + ) tx_hash = result["output"] - tx_result = filter_event(plan,service_name,tx_hash) + tx_result = filter_event(plan, service_name, tx_hash) - plan.verify(value=tx_result["extract.status"],assertion="==",target_value="0x1") + plan.verify(value=tx_result["extract.status"], assertion="==", target_value="0x1") return tx_result -# Returns Last Block From Chain -def get_last_block(plan,service_name): +# Returns Last Block From Chain +def get_last_block(plan, service_name): post_request = PostHttpRequestRecipe( - port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", body='{"jsonrpc": "2.0","id": 1,"method": "icx_getLastBlock"}', - extract={ - "height": ".result.height" - } + extract={"height": ".result.height"}, ) - response = plan.wait(service_name,recipe=post_request,field="code",assertion="==",target_value=200) + response = plan.wait( + service_name, + recipe=post_request, + field="code", + assertion="==", + target_value=200, + ) return response["extract.height"] -# Filters Events -def filter_event(plan,service_name,tx_hash): +# Filters Events +def filter_event(plan, service_name, tx_hash): post_request = PostHttpRequestRecipe( port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", - body='{ "jsonrpc": "2.0", "method": "icx_getTransactionResult", "id": 1, "params": { "txHash": %s } }' % tx_hash, + body='{ "jsonrpc": "2.0", "method": "icx_getTransactionResult", "id": 1, "params": { "txHash": %s } }' + % tx_hash, extract={ - "status" : ".result.status", + "status": ".result.status", "network_type_id": '.result["eventLogs"] | .[1].indexed | .[1]', - "network_id" : '.result["eventLogs"] | .[1].indexed | .[2]' - } + "network_id": '.result["eventLogs"] | .[1].indexed | .[2]', + }, + ) + + result = plan.wait( + service_name=service_name, + recipe=post_request, + field="code", + assertion="==", + target_value=200, ) - - result = plan.wait(service_name=service_name,recipe=post_request,field="code",assertion="==",target_value=200) return result -# Returns Btp Network Info -def get_btp_network_info(plan,service_name,network_id): +# Returns Btp Network Info +def get_btp_network_info(plan, service_name, network_id): post_request = PostHttpRequestRecipe( port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", - body='{ "jsonrpc": "2.0", "method": "btp_getNetworkInfo", "id": 1, "params": { "id": "%s" } }' % network_id, + body='{ "jsonrpc": "2.0", "method": "btp_getNetworkInfo", "id": 1, "params": { "id": "%s" } }' + % network_id, extract={ - "start_height" : '.result.startHeight', - } + "start_height": ".result.startHeight", + }, + ) + result = plan.wait( + service_name=service_name, + recipe=post_request, + field="code", + assertion="==", + target_value=200, ) - result = plan.wait(service_name=service_name,recipe=post_request,field="code",assertion="==",target_value=200) - exec_command = ["python","-c","print(hex(int(%s) + 1))" % result["extract.start_height"]] - result = plan.exec(service_name,recipe=ExecRecipe(exec_command)) + exec_command = [ + "python", + "-c", + "print(hex(int(%s) + 1))" % result["extract.start_height"], + ] + result = plan.exec(service_name, recipe=ExecRecipe(exec_command)) - execute_cmd = ExecRecipe(command=["/bin/sh", "-c","echo \"%s\" | tr -d '\n\r'" % result["output"] ]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) + execute_cmd = ExecRecipe( + command=["/bin/sh", "-c", "echo \"%s\" | tr -d '\n\r'" % result["output"]] + ) + result = plan.exec(service_name=service_name, recipe=execute_cmd) return result["output"] -# Returns Btp Block Header -def get_btp_header(plan,service_name,network_id,receipt_height): +# Returns Btp Block Header +def get_btp_header(plan, service_name, network_id, receipt_height): post_request = PostHttpRequestRecipe( port_id="rpc", endpoint="/api/v3/icon_dex", content_type="application/json", - body='{ "jsonrpc": "2.0", "method": "btp_getHeader", "id": 1, "params": { "networkID": "%s" ,"height": "%s" } }' % (network_id,receipt_height), + body='{ "jsonrpc": "2.0", "method": "btp_getHeader", "id": 1, "params": { "networkID": "%s" ,"height": "%s" } }' + % (network_id, receipt_height), extract={ - "header" : '.result', - } + "header": ".result", + }, ) - result = plan.wait(service_name=service_name,recipe=post_request,field="code",assertion="==",target_value=200) + result = plan.wait( + service_name=service_name, + recipe=post_request, + field="code", + assertion="==", + target_value=200, + ) - command = ExecRecipe(command=["python", "-c","from base64 import b64encode, b64decode; print(b64decode('%s').hex())" % result["extract.header"]]) + command = ExecRecipe( + command=[ + "python", + "-c", + "from base64 import b64encode, b64decode; print(b64decode('%s').hex())" + % result["extract.header"], + ] + ) - first_header_hex = plan.exec(service_name,recipe=command) + first_header_hex = plan.exec(service_name, recipe=command) - execute_cmd = ExecRecipe(command=["/bin/sh", "-c","echo \"%s\" | tr -d '\n\r'" % first_header_hex["output"] ]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) + execute_cmd = ExecRecipe( + command=[ + "/bin/sh", + "-c", + "echo \"%s\" | tr -d '\n\r'" % first_header_hex["output"], + ] + ) + result = plan.exec(service_name=service_name, recipe=execute_cmd) return result["output"] -# Converts Int to Hex -def int_to_hex(plan,service_name,number): - exec_command = ["python","-c","print(hex(int(%s)))" % number] - result = plan.exec(service_name,recipe=ExecRecipe(exec_command)) +# Converts Int to Hex +def int_to_hex(plan, service_name, number): + exec_command = ["python", "-c", "print(hex(int(%s)))" % number] + result = plan.exec(service_name, recipe=ExecRecipe(exec_command)) - execute_cmd = ExecRecipe(command=["/bin/sh", "-c","echo \"%s\" | tr -d '\n\r'" % result["output"] ]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) + execute_cmd = ExecRecipe( + command=["/bin/sh", "-c", "echo \"%s\" | tr -d '\n\r'" % result["output"]] + ) + result = plan.exec(service_name=service_name, recipe=execute_cmd) return result["output"] - diff --git a/services/jvm/icon/src/node-setup/start_icon_node.star b/services/jvm/icon/src/node-setup/start_icon_node.star index c185f6c5..de503f87 100644 --- a/services/jvm/icon/src/node-setup/start_icon_node.star +++ b/services/jvm/icon/src/node-setup/start_icon_node.star @@ -6,15 +6,15 @@ def start_icon_node(plan, private_port, public_port, p2p_listen_address, p2p_add Function to start an ICON node. Args: - - plan: plan. - - private_port: The private port for the ICON node. - - public_port: The public port for the ICON node. - - p2p_listen_address: The P2P listen address for the ICON node. - - p2p_address: The P2P address for the ICON node. - - cid: The chain ID for the ICON network. - - uploaded_genesis: A dictionary containing uploaded genesis file data. - - genesis_file_path: The path to the genesis file. - - genesis_file_name: The name of the genesis file. + plan: kurtosis plan. + private_port: The private port for the ICON node. + public_port: The public port for the ICON node. + p2p_listen_address: The P2P listen address for the ICON node. + p2p_address: The P2P address for the ICON node. + cid: The chain ID for the ICON network. + uploaded_genesis: A dictionary containing uploaded genesis file data. + genesis_file_path: The path to the genesis file. + genesis_file_name: The name of the genesis file. Returns: Configuration data for the started ICON node service as a dictionary. @@ -116,19 +116,4 @@ def get_service_url(ip_address, ports, path): port_id = ports[network_keys_and_public_address.rpc].number protocol = ports[network_keys_and_public_address.rpc].application_protocol url = "{0}://{1}:{2}/{3}".format(protocol, ip_address, port_id, path) - return url - - -# Retruns Service Config -def get_service_config(private_port, public_port, p2p_listen_address, p2p_address, cid): - config = { - "service_name": "{0}{1}".format(constants.ICON_NODE_CLIENT.service_name, cid), - "private_port": private_port, - "public_port": public_port, - "network_name": "icon-{0}".format(cid), - "p2p_listen_address": p2p_listen_address, - "p2p_address": p2p_address, - "cid": cid, - } - - return config + return url \ No newline at end of file diff --git a/services/jvm/icon/src/node-setup/wallet.star b/services/jvm/icon/src/node-setup/wallet.star index 8fa3b3d3..25ed9190 100644 --- a/services/jvm/icon/src/node-setup/wallet.star +++ b/services/jvm/icon/src/node-setup/wallet.star @@ -1,36 +1,59 @@ -""" -Creates Wallet with Given name and password -'wallet_name' - Naming the genereated keystore -'wallet_password' - Password used for sigining and Decrypting the Generated Keystore -""" -def create_wallet(plan,service_name,wallet_name,wallet_password): +def create_wallet(plan, service_name, wallet_name, wallet_password): + """ + Create a wallet with the specified name and password. + + Args: + plan (Plan): kurtosis plan. + service_name (str): The name of the service. + wallet_name (str): The name of the wallet to be created. + wallet_password (str): The password for the wallet. + + Returns: + str: The name of the wallet file that was created (e.g., "wallet_name.json"). + """ plan.print("Creating Wallet") wallet_file = "{0}.json".format(wallet_name) - - execute_cmd = ExecRecipe(command=["./bin/goloop","ks","gen","-p",wallet_password,"-o",wallet_file]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) + + execute_cmd = ExecRecipe(command=["./bin/goloop", "ks", "gen", "-p", wallet_password, "-o", wallet_file]) + result = plan.exec(service_name=service_name, recipe=execute_cmd) return wallet_file +def get_network_wallet_address(plan, service_name): + """ + Get the address of the network wallet from the keystore configuration. -# Returns Network Wallet Address -def get_network_wallet_address(plan,service_name): + Args: + plan (Plan): The kurtosis plan. + service_name (str): The name of the service. - execute_cmd = ExecRecipe(command=["jq",".address","config/keystore.json"]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) + Returns: + str: The network wallet address extracted from the keystore configuration. + """ + execute_cmd = ExecRecipe(command=["jq", ".address", "config/keystore.json"]) + result = plan.exec(service_name=service_name, recipe=execute_cmd) - execute_cmd = ExecRecipe(command=["/bin/sh", "-c","echo \"%s\" | tr -d '\n\r'" % result["output"] ]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) + execute_cmd = ExecRecipe(command=["/bin/sh", "-c", "echo \"%s\" | tr -d '\n\r'" % result["output"]]) + result = plan.exec(service_name=service_name, recipe=execute_cmd) return result["output"] -# Returns Network Wallet Public Key -def get_network_wallet_public_key(plan,service_name): - execute_cmd = ExecRecipe(command=["./bin/goloop","ks","pubkey","-k","config/keystore.json","-p","gochain"]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) +def get_network_wallet_public_key(plan, service_name): + """ + Get the public key of the network wallet from the keystore configuration. + + Args: + plan (Plan): The kurtosis plan. + service_name (str): The name of the service. + + Returns: + str: The public key of the network wallet extracted from the keystore configuration. + """ + execute_cmd = ExecRecipe(command=["./bin/goloop", "ks", "pubkey", "-k", "config/keystore.json", "-p", "gochain"]) + result = plan.exec(service_name=service_name, recipe=execute_cmd) - execute_cmd = ExecRecipe(command=["/bin/sh", "-c","echo \"%s\" | tr -d '\n\r'" % result["output"] ]) - result = plan.exec(service_name=service_name,recipe=execute_cmd) + execute_cmd = ExecRecipe(command=["/bin/sh", "-c", "echo \"%s\" | tr -d '\n\r'" % result["output"]]) + result = plan.exec(service_name=service_name, recipe=execute_cmd) return result["output"] diff --git a/services/jvm/icon/src/relay-setup/contract_configuration.star b/services/jvm/icon/src/relay-setup/contract_configuration.star index aee5072d..6158eee7 100644 --- a/services/jvm/icon/src/relay-setup/contract_configuration.star +++ b/services/jvm/icon/src/relay-setup/contract_configuration.star @@ -2,44 +2,37 @@ contract_deployment_service = import_module("../node-setup/contract_deploy.star" node_service = import_module("../node-setup/setup_icon_node.star") # Deploys BMC contract on ICON -def deploy_bmc(plan,args): +def deploy_bmc(plan, network, service_name, uri, keystore_path, keystore_password, nid): plan.print("Deploying BMC Contract") - init_message = '{"_net":"%s"}' % args["network"] + init_message = '{"_net":"%s"}' % network - tx_hash = contract_deployment_service.deploy_contract(plan,"bmc",init_message,args) + tx_hash = contract_deployment_service.deploy_contract(plan,"bmc",init_message, service_name, uri, keystore_path, keystore_password, nid) - service_name = args["service_name"] + service_name = service_name score_address = contract_deployment_service.get_score_address(plan,service_name,tx_hash) return score_address # Deploys xCall on ICON -def deploy_xcall(plan,bmc_address,args): +def deploy_xcall(plan,bmc_address, service_name, uri, keystore_path, keystore_password, nid): plan.print("Deploying xCall Contract") init_message = '{"_bmc":"%s"}' % bmc_address - tx_hash = contract_deployment_service.deploy_contract(plan,"xcall",init_message,args) - service_name = args["service_name"] + tx_hash = contract_deployment_service.deploy_contract(plan,"xcall",init_message,service_name, uri, keystore_path, keystore_password, nid) score_address = contract_deployment_service.get_score_address(plan,service_name,tx_hash) - add_service(plan,bmc_address,score_address,args) + add_service(plan,bmc_address,score_address,service_name, uri, keystore_path, keystore_password, nid) return score_address # Adds services to BMC contract on ICON -def add_service(plan,bmc_address,xcall_address,args): +def add_service(plan,bmc_address,xcall_address, service_name, uri, keystore_path, keystore_password, nid): plan.print("Adding xcall to Bmc %s " % bmc_address) - service_name = args["service_name"] - uri = args["endpoint"] - keystore_path = args["keystore_path"] - keypassword = args["keypassword"] - nid = args["nid"] - method = "addService" params = '{"_svc":"xcall","_addr":"%s"}' % xcall_address - exec_command = ["./bin/goloop","rpc","sendtx","call","--to",bmc_address,"--method",method,"--params",params,"--uri",uri,"--key_store",keystore_path,"--key_password",keypassword,"--step_limit","50000000000","--nid",nid] + exec_command = ["./bin/goloop","rpc","sendtx","call","--to",bmc_address,"--method",method,"--params",params,"--uri",uri,"--key_store",keystore_path,"--key_password",keystore_password,"--step_limit","50000000000","--nid",nid] result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=exec_command)) tx_hash = result["output"].replace('"',"") @@ -61,22 +54,21 @@ def open_btp_network(plan,service_name,src,dst,bmc_address,uri,keystorepath,keyp return result # Deploys BMV BTPBLOCK on ICON -def deploy_bmv_btpblock_java(plan,bmc_address,dst_network_id,dst_network_type_id,first_block_header,args): +def deploy_bmv_btpblock_java(plan, bmc_address, dst_network_id, dst_network_type_id, first_block_header, service_name, uri, keystore_path, keystore_password, nid): init_message = '{"bmc": "%s","srcNetworkID": "%s","networkTypeID": "%s", "blockHeader": "0x%s","seqOffset": "0x0"}' % (bmc_address,dst_network_id,dst_network_type_id,first_block_header) - service_name = args["service_name"] - tx_hash = contract_deployment_service.deploy_contract(plan,"bmv-btpblock",init_message,args) + tx_hash = contract_deployment_service.deploy_contract(plan,"bmv-btpblock",init_message, service_name, uri, keystore_path, keystore_password, nid) score_address = contract_deployment_service.get_score_address(plan,service_name,tx_hash) plan.print("BMV-BTPBlock: deployed") return score_address # Deploys BMVBRIDGE on ICON -def deploy_bmv_bridge_java(plan,service_name,bmc_address,dst_network,offset,args): +def deploy_bmv_bridge_java(plan,service_name, bmc_address, dst_network, offset, uri, keystore_path, keystore_password, nid): init_message = '{"_bmc": "%s","_net": "%s","_offset": "%s"}' %(bmc_address,dst_network,offset) - tx_hash = contract_deployment_service.deploy_contract(plan,"bmv-bridge",init_message,args) + tx_hash = contract_deployment_service.deploy_contract(plan,"bmv-bridge",init_message, service_name, uri, keystore_path, keystore_password, nid) score_address = contract_deployment_service.get_score_address(plan,service_name,tx_hash) plan.print("BMV-BTPBlock: deployed ") @@ -130,15 +122,10 @@ def add_relay(plan,service_name,bmc_address,dst_bmc_address,relay_address,uri,ke return tx_result # Configures Link in BMC on ICON -def setup_link_icon(plan,service_name,bmc_address,dst_chain_network,dst_chain_bmc_address,src_chain_network_id,bmv_address,relay_address,args): +def setup_link_icon(plan,service_name, bmc_address, dst_chain_network, dst_chain_bmc_address, src_chain_network_id, bmv_address, relay_address, uri, keystore_path, keypassword, nid): dst_bmc_address = get_btp_address(dst_chain_network,dst_chain_bmc_address) - uri = args["endpoint"] - keystore_path = args["keystore_path"] - keypassword = args["keypassword"] - nid = args["nid"] - add_verifier(plan,service_name,bmc_address,dst_chain_network,bmv_address,uri,keystore_path,keypassword,nid) add_btp_link(plan,service_name,bmc_address,dst_bmc_address,src_chain_network_id,uri,keystore_path,keypassword,nid) add_relay(plan,service_name,bmc_address,dst_bmc_address,relay_address,uri,keystore_path,keypassword,nid) @@ -150,28 +137,26 @@ def get_btp_address(network,dapp): return "btp://{0}/{1}".format(network,dapp) # Deploys dAPP on ICON -def deploy_dapp(plan,xcall_address,args): +def deploy_dapp(plan,xcall_address, service_name, uri, keystore_path, keystore_password, nid): plan.print("Deploying dapp Contract") init_message = '{"_callService":"%s"}' % xcall_address - tx_hash = contract_deployment_service.deploy_contract(plan,"dapp-sample",init_message,args) - service_name = args["service_name"] + tx_hash = contract_deployment_service.deploy_contract(plan,"dapp-sample",init_message, service_name, uri, keystore_path, keystore_password, nid) score_address = contract_deployment_service.get_score_address(plan,service_name,tx_hash) return score_address # Deploy ibc_hndler -def deploy_ibc_handler(plan,args): +def deploy_ibc_handler(plan, service_name, uri, keystore_path, keystore_password, nid): plan.print("IBC handler") init_message = '{}' - tx_hash = contract_deployment_service.deploy_contract(plan,"ibc-0.1.0-optimized",init_message, args) + tx_hash = contract_deployment_service.deploy_contract(plan,"ibc-0.1.0-optimized",init_message, service_name, uri, keystore_path, keystore_password, nid) plan.print(tx_hash) - service_name = args["service_name"] score_address = contract_deployment_service.get_score_address(plan,service_name,tx_hash) @@ -180,21 +165,20 @@ def deploy_ibc_handler(plan,args): return score_address # deploy light_client -def deploy_light_client_for_icon(plan,args, ibc_handler_address): +def deploy_light_client_for_icon(plan,service_name, uri, keystore_path, keystore_password, nid, ibc_handler_address): plan.print("deploy tendermint lightclient") init_message = '{"ibcHandler":"%s"}' % ibc_handler_address - tx_hash = contract_deployment_service.deploy_contract(plan, "tendermint-0.1.0-optimized", init_message, args) - service_name = args["service_name"] + tx_hash = contract_deployment_service.deploy_contract(plan, "tendermint-0.1.0-optimized", init_message, service_name, uri, keystore_path, keystore_password, nid) score_address = contract_deployment_service.get_score_address(plan,service_name,tx_hash) plan.print("deployed light client") return score_address -def deploy_xcall_connection(plan,args,xcall_address,ibc_address): +def deploy_xcall_connection(plan, service_name, uri, keystore_path, keystore_password, nid, xcall_address,ibc_address): plan.print("deploy xcall connection") plan.print(xcall_address) @@ -202,51 +186,46 @@ def deploy_xcall_connection(plan,args,xcall_address,ibc_address): init_message= '{"_xCall": "%s","_ibc": "%s","port": "xcall"}' % (xcall_address,ibc_address) - tx_hash = contract_deployment_service.deploy_contract(plan, "xcall-connection-0.1.0-optimized", init_message, args) - - service_name = args["service_name"] + tx_hash = contract_deployment_service.deploy_contract(plan, "xcall-connection-0.1.0-optimized", init_message, service_name, uri, keystore_path, keystore_password, nid) score_address = contract_deployment_service.get_score_address(plan,service_name,tx_hash) - return score_address -def deploy_xcall_for_ibc(plan,args): +def deploy_xcall_for_ibc(plan, network, service_name, uri, keystore_path, keystore_password, nid): plan.print("Deploying xCall Contract for IBC") - init_message = '{"networkId":"%s"}' % args["network"] + init_message = '{"networkId":"%s"}' % network - tx_hash = contract_deployment_service.deploy_contract(plan,"xcall-0.1.0-optimized",init_message,args) - service_name = args["service_name"] + tx_hash = contract_deployment_service.deploy_contract(plan,"xcall-0.1.0-optimized",init_message, service_name, uri, keystore_path, keystore_password, nid) score_address = contract_deployment_service.get_score_address(plan,service_name,tx_hash) return score_address -def deploy_xcall_dapp(plan,args,xcall_address): +def deploy_xcall_dapp(plan, src_chain_config, xcall_address): plan.print("Deploying Xcall Dapp Contract") params = '{"_callService":"%s"}' % (xcall_address) - tx_hash = contract_deployment_service.deploy_contract(plan,"dapp-multi-protocol-0.1.0-optimized",params,args) - service_name = args["service_name"] + tx_hash = contract_deployment_service.deploy_contract(plan,"dapp-multi-protocol-0.1.0-optimized",params, src_chain_config["service_name"], src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) - score_address = contract_deployment_service.get_score_address(plan,service_name,tx_hash) + score_address = contract_deployment_service.get_score_address(plan, src_chain_config["service_name"], tx_hash) return score_address -def add_connection_xcall_dapp(plan,xcall_dapp_address,wasm_network_id,java_xcall_connection_address,wasm_xcall_connection_address,service_name,uri,keystorepath,keypassword,nid): +def add_connection_xcall_dapp(plan,xcall_dapp_address,wasm_network_id,java_xcall_connection_address,wasm_xcall_connection_address, src_chain_config): plan.print("Configure dapp connection") method = "addConnection" params = '{"nid":"%s","source":"%s","destination":"%s"}' % (wasm_network_id,java_xcall_connection_address,wasm_xcall_connection_address) #execute - exec_command = ["./bin/goloop","rpc","sendtx","call","--to",xcall_dapp_address,"--method",method,"--params",params,"--uri",uri,"--key_store",keystorepath,"--key_password",keypassword,"--step_limit","500000000000","--nid",nid] - result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=exec_command)) + exec_command = ["./bin/goloop","rpc","sendtx","call","--to",xcall_dapp_address,"--method",method,"--params",params,"--uri",src_chain_config["endpoint"],"--key_store",src_chain_config["keystore_path"],"--key_password",src_chain_config["keypassword"],"--step_limit","500000000000","--nid",src_chain_config["nid"]] + result = plan.exec(service_name=src_chain_config["service_name"],recipe=ExecRecipe(command=exec_command)) tx_hash = result["output"].replace('"',"") - tx_result = node_service.get_tx_result(plan,service_name,tx_hash,uri) + tx_result = node_service.get_tx_result(plan, src_chain_config["service_name"], tx_hash, src_chain_config["endpoint"]) plan.verify(value=tx_result["extract.status"],assertion="==",target_value="0x1") return tx_result @@ -282,17 +261,17 @@ def set_default_connection_xcall(plan,xcall_address,wasm_network_id,xcall_connec plan.verify(value=tx_result["extract.status"],assertion="==",target_value="0x1") return tx_result -def setup_contracts_for_ibc_java(plan,args): +def setup_contracts_for_ibc_java(plan, service_name, uri, keystore_path, keystore_password, nid, network): plan.print("Setting Contracts") - ibc_core_address = deploy_ibc_handler(plan,args) + ibc_core_address = deploy_ibc_handler(plan, service_name, uri, keystore_path, keystore_password, nid) - xcall_address = deploy_xcall_for_ibc(plan,args) + xcall_address = deploy_xcall_for_ibc(plan, network, service_name, uri, keystore_path, keystore_password, nid) - light_client_address = deploy_light_client_for_icon(plan,args,ibc_core_address) + light_client_address = deploy_light_client_for_icon(plan, service_name, uri, keystore_path, keystore_password, nid ,ibc_core_address) - xcall_connection_address = deploy_xcall_connection(plan,args,xcall_address,ibc_core_address) + xcall_connection_address = deploy_xcall_connection(plan, service_name, uri, keystore_path, keystore_password, nid ,xcall_address,ibc_core_address) contracts = { "ibc_core": ibc_core_address, @@ -313,13 +292,13 @@ def configure_connection_for_java(plan,xcall_address,xcall_connection_address,wa return set_xcall_connection_result -def deploy_and_configure_dapp_java(plan,args,xcall_address,wasm_network_id,java_xcall_connection_address,wasm_xcall_connection_address,service_name,uri,keystorepath,keypassword,nid): +def deploy_and_configure_dapp_java(plan, src_chain_config, xcall_address, wasm_network_id, java_xcall_connection_address, wasm_xcall_connection_address): plan.print("Deploy and Configure Dapp") - xcall_dapp_address = deploy_xcall_dapp(plan,args,xcall_address) + xcall_dapp_address = deploy_xcall_dapp(plan, src_chain_config, xcall_address) - add_connection_result = add_connection_xcall_dapp(plan,xcall_dapp_address,wasm_network_id,java_xcall_connection_address,wasm_xcall_connection_address,service_name,uri,keystorepath,keypassword,nid) + add_connection_result = add_connection_xcall_dapp(plan, xcall_dapp_address, wasm_network_id, java_xcall_connection_address, wasm_xcall_connection_address, src_chain_config) result = { "xcall_dapp" : xcall_dapp_address,