diff --git a/cli/commands/bridge/bridge.go b/cli/commands/bridge/bridge.go index 2b3bd593..4f71e1cc 100644 --- a/cli/commands/bridge/bridge.go +++ b/cli/commands/bridge/bridge.go @@ -5,6 +5,7 @@ package bridge import ( "fmt" + "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" "strconv" "strings" @@ -14,6 +15,8 @@ import ( ) const bridgeMainFunction = "run_btp_setup" +const runbridgeicon2icon = "start_btp_for_already_running_icon_nodes" +const runbridgeicon2ethhardhat = "start_btp_icon_to_eth_for_already_running_nodes" var ( chainA string @@ -57,44 +60,73 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { bridge, _ := cmd.Flags().GetBool("bridge") - params := fmt.Sprintf(`{"args":{"links": {"src": "%s", "dst": "%s"},"bridge":"%s"}}`, chainA, chainB, strconv.FormatBool(bridge)) - if strings.ToLower(chainA) == "icon" && strings.ToLower(chainB) == "icon" { - diveContext.SetSpinnerMessage(" Executing BTP Starlark Package") - - data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, bridgeMainFunction, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + serviceConfig, err := common.ReadServiceJsonFile() if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) + diveContext.FatalError("Failed To read ServiceFile", err.Error()) } - response, services, skippedInstructions, err := diveContext.GetSerializedData(data) - if err != nil { - diveContext.StopServices(services) - diveContext.FatalError("Starlark Run Failed", err.Error()) - } + if len(serviceConfig) != 0 { + srcChain := "icon" + dstChain := "icon-1" - diveContext.CheckInstructionSkipped(skippedInstructions, "Bridge Already Running") + srcChainServiceResponse, err := serviceConfig["icon-0"].EncodeToString() + if err != nil { + diveContext.FatalError("Failed To read ServiceFile", err.Error()) + } + dstChainServiceResponse, err := serviceConfig["icon-1"].EncodeToString() - common.WriteToFile(response) + if err != nil { + diveContext.FatalError("Failed To read ServiceFile", err.Error()) + } - } else if strings.ToLower(chainA) == "icon" && (strings.ToLower(chainB) == "eth" || strings.ToLower(chainB) == "hardhat") { - diveContext.SetSpinnerMessage(" Executing BTP Starlark Package") - data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, bridgeMainFunction, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + srcChainServiceName := serviceConfig["icon-0"].ServiceName + dstChainServiceName := serviceConfig["icon-1"].ServiceName - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) + runBtpSetupForAlreadyRunningNodes(diveContext, enclaveCtx, runbridgeicon2icon, srcChain, dstChain, srcChainServiceName, dstChainServiceName, bridge, srcChainServiceResponse, dstChainServiceResponse) + + } else { + + params := getParams(chainA, chainA, strconv.FormatBool(bridge)) + + runBtpSetupByRunningNodes(diveContext, enclaveCtx, params) } - response, services, skippedInstructions, err := diveContext.GetSerializedData(data) - if err != nil { - diveContext.StopServices(services) - diveContext.FatalError("Starlark Run Failed", err.Error()) + } else if (strings.ToLower(chainA) == "icon") && (strings.ToLower(chainB) == "eth" || strings.ToLower(chainB) == "hardhat") { + + serviceConfig, err := common.ReadServiceJsonFile() + + if err != nil { + diveContext.FatalError("Failed To read ServiceFile", err.Error()) } - diveContext.CheckInstructionSkipped(skippedInstructions, "Bridge Already Running") - common.WriteToFile(response) + if len(serviceConfig) != 0 { + srcChain := strings.ToLower(chainA) + dstChain := strings.ToLower(chainB) + + srcChainServiceResponse, err := serviceConfig["icon-0"].EncodeToString() + if err != nil { + diveContext.FatalError("Failed To read ServiceFile", err.Error()) + } + dstChainServiceResponse, err := serviceConfig[dstChain].EncodeToString() + + if err != nil { + diveContext.FatalError("Failed To read ServiceFile", err.Error()) + } + + srcChainServiceName := serviceConfig["icon-0"].ServiceName + dstChainServiceName := serviceConfig[dstChain].ServiceName + + runBtpSetupForAlreadyRunningNodes(diveContext, enclaveCtx, runbridgeicon2ethhardhat, srcChain, dstChain, srcChainServiceName, dstChainServiceName, bridge, srcChainServiceResponse, dstChainServiceResponse) + + } else { + + params := getParams(chainA, chainB, strconv.FormatBool(bridge)) + + runBtpSetupByRunningNodes(diveContext, enclaveCtx, params) + } } else { diveContext.FatalError("Chains Not Supported", "Supported Chains [icon,eth,hardhat]") } @@ -112,3 +144,50 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { return btpbridgeCmd } + +func runBtpSetupByRunningNodes(diveContext *common.DiveContext, enclaveCtx *enclaves.EnclaveContext, params string) { + diveContext.SetSpinnerMessage(" Executing BTP Starlark Package") + + data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, bridgeMainFunction, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + + if err != nil { + diveContext.FatalError("Starlark Run Failed", err.Error()) + } + response, services, skippedInstructions, err := diveContext.GetSerializedData(data) + if err != nil { + diveContext.StopServices(services) + diveContext.FatalError("Starlark Run Failed", err.Error()) + + } + diveContext.CheckInstructionSkipped(skippedInstructions, "Bridge Already Running") + common.WriteToFile(response) + +} + +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, srcChain, srcChainServiceResponse, dstChain, dstChainServiceResponse, srcChain, dstChain, strconv.FormatBool(bridge)) + + params := fmt.Sprintf(`{"src_chain":"%s", "dst_chain":"%s", "config_data":%s, "src_service_name":"%s", "dst_src_name":"%s"}`, srcChain, dstChain, configData, srcChainServiceName, dstChainServiceName) + + data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, mainFunctionName, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + + if err != nil { + diveContext.FatalError("Starlark Run Failed", err.Error()) + } + response, services, skippedInstructions, err := diveContext.GetSerializedData(data) + if err != nil { + diveContext.StopServices(services) + diveContext.FatalError("Starlark Run Failed", err.Error()) + + } + + diveContext.CheckInstructionSkipped(skippedInstructions, "Bridge Already Running") + + common.WriteToFile(response) + +} + +func getParams(chainSrc, chainDst, bridge string) string { + return fmt.Sprintf(`{"args":{"links": {"src": "%s", "dst": "%s"},"bridge":"%s"}}`, chainSrc, chainDst, bridge) +} diff --git a/cli/commands/chain/types/eth.go b/cli/commands/chain/types/eth.go index 3f451b4f..1a6c6741 100644 --- a/cli/commands/chain/types/eth.go +++ b/cli/commands/chain/types/eth.go @@ -23,7 +23,7 @@ It establishes a connection to the Ethereum network and allows the node in execu data := RunEthNode(diveContext) diveContext.SetSpinnerMessage("Execution Completed") - err := data.WriteDiveResponse() + err := common.WriteToServiceFile(data.NetworkName, *data) if err != nil { diveContext.FatalError("Failed To Write To File", err.Error()) } diff --git a/cli/commands/chain/types/hardhat.go b/cli/commands/chain/types/hardhat.go index 87de6be1..5556082c 100644 --- a/cli/commands/chain/types/hardhat.go +++ b/cli/commands/chain/types/hardhat.go @@ -21,7 +21,7 @@ It establishes a connection to the hardhat network and allows the node in execut diveContext.SetSpinnerMessage("Execution Completed") - err := data.WriteDiveResponse() + err := common.WriteToServiceFile(data.NetworkName, *data) if err != nil { diveContext.FatalError("Failed To Write To File", err.Error()) } diff --git a/cli/commands/chain/types/icon.go b/cli/commands/chain/types/icon.go index 22823832..798a8324 100644 --- a/cli/commands/chain/types/icon.go +++ b/cli/commands/chain/types/icon.go @@ -75,7 +75,7 @@ It establishes a connection to the Icon network and allows the node in executing diveContext.SetSpinnerMessage("Starting Decentralisation") Decentralisation(diveContext, params) - err := nodeResponse.WriteDiveResponse() + err := common.WriteToServiceFile(nodeResponse.NetworkName, *nodeResponse) if err != nil { diveContext.FatalError("Failed To Write To File", err.Error()) @@ -87,7 +87,7 @@ It establishes a connection to the Icon network and allows the node in executing nodeResponse := RunIconNode(diveContext) - err := nodeResponse.WriteDiveResponse() + err := common.WriteToServiceFile(nodeResponse.NetworkName, *nodeResponse) if err != nil { diveContext.FatalError("Failed To Write To File", err.Error()) diff --git a/cli/commands/root.go b/cli/commands/root.go index ea320a55..74f719af 100644 --- a/cli/commands/root.go +++ b/cli/commands/root.go @@ -17,7 +17,7 @@ import ( "github.com/hugobyte/dive/styles" "github.com/spf13/cobra" -) +) func RootCmd() *cobra.Command { diveContext := common.NewDiveContext() diff --git a/cli/common/types.go b/cli/common/types.go index 78a3aa39..ddbf9dec 100644 --- a/cli/common/types.go +++ b/cli/common/types.go @@ -190,3 +190,96 @@ func setupLogger() *logrus.Logger { return log } + +type Services map[string]*DiveserviceResponse + +func WriteToServiceFile(serviceName string, data DiveserviceResponse) error { + + pwd, err := getPwd() + if err != nil { + return err + } + + file, err := os.OpenFile(pwd+"/services.json", os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return err + } + + if err != nil { + return err + } + defer file.Close() + + jsonDataFromFile, err := ReadServiceJsonFile() + + if err != nil { + return err + } + + if len(jsonDataFromFile) != 0 { + _, ok := jsonDataFromFile[serviceName] + if !ok { + jsonDataFromFile[serviceName] = &data + dataTowrite, err := json.Marshal(jsonDataFromFile) + if err != nil { + return err + } + + _, err = file.WriteAt(dataTowrite, 0) + + if err != nil { + return err + } + + return nil + } + + } + newServices := Services{} + + newServices[serviceName] = &data + + dataTowrite, err := json.Marshal(newServices) + if err != nil { + return err + } + + _, err = file.Write(dataTowrite) + + if err != nil { + return err + } + + return nil + +} + +func ReadServiceJsonFile() (Services, error) { + + services := Services{} + + pwd, err := getPwd() + if err != nil { + return nil, err + } + + jsonFile, _ := os.ReadFile(pwd + "/services.json") + + if len(jsonFile) == 0 { + return nil, nil + } + json.Unmarshal(jsonFile, &services) + + return services, nil + +} + +func getPwd() (string, error) { + pwd, err := os.Getwd() + + if err != nil { + return "", err + } + + return pwd, nil +} diff --git a/main.star b/main.star index cf309853..84f80af0 100644 --- a/main.star +++ b/main.star @@ -7,33 +7,22 @@ icon_service = import_module("github.com/hugobyte/dive/services/jvm/icon/icon.st btp_bridge = import_module("github.com/hugobyte/dive/services/bridges/btp/src/bridge.star") input_parser = import_module("github.com/hugobyte/dive/package_io/input_parser.star") - - -def run(plan,args): - +def run(plan, args): plan.print("Starting") - return parse_input(plan,args) - - -def parse_input(plan,args): + return parse_input(plan, args) +def parse_input(plan, args): if args["action"] == "start_node": - node_name = args["node_name"] - run_node(plan,node_name,args) - - + run_node(plan, node_name, args) if args["action"] == "start_nodes": - nodes = args["nodes"] if len(nodes) == 1: - - if nodes[0] == "icon": - + if nodes[0] == "icon": data = icon_service.start_node_service_icon_to_icon(plan) return data @@ -42,49 +31,39 @@ def parse_input(plan,args): if len(nodes) > 2: fail("Maximum two nodes are allowed") - + if nodes[0] == "icon" and nodes[1] == "icon": data = icon_service.start_node_service_icon_to_icon(plan) return data - - else: - node_0 = run_node(plan,nodes[0],args) - node_1 = run_node(plan,nodes[1],args) - - return node_0,node_1 + else: + node_0 = run_node(plan, nodes[0], args) + node_1 = run_node(plan, nodes[1], args) - + return node_0, node_1 if args["action"] == "setup_relay": - if args["relay"]["name"] == "btp": - data = run_btp_setup(plan,args["relay"]) - + data = run_btp_setup(plan, args["relay"]) + return data else: fail("More Relay Support will be added soon") - -def run_node(plan,node_name,args): - +def run_node(plan, node_name, args): if node_name == "icon": - return icon_service.start_node_service(plan) - - elif node_name == "eth" or node_name == "hardhat": - return eth_node.start_eth_node_serivce(plan,args,node_name) + elif node_name == "eth" or node_name == "hardhat": + return eth_node.start_eth_node_serivce(plan, args, node_name) - else : + else: fail("Unknown Chain Type. Expected ['icon','eth','hardhat']") - -def run_btp_setup(plan,args): - +def run_btp_setup(plan, args): args_data = input_parser.get_args_data(args) - + config_data = input_parser.generate_config_data(args) if args_data.dst == "icon-1": data = icon_service.start_node_service_icon_to_icon(plan) @@ -92,141 +71,132 @@ def run_btp_setup(plan,args): config_data["chains"][args_data.src] = data.src_config config_data["chains"][args_data.dst] = data.dst_config - icon_service.configure_icon_to_icon_node(plan,config_data["chains"][args_data.src],config_data["chains"][args_data.dst]) + icon_service.configure_icon_to_icon_node(plan, config_data["chains"][args_data.src], config_data["chains"][args_data.dst]) - src_bmc_address , dst_bmc_address = icon_service.deploy_bmc_icon(plan,args_data.src,args_data.dst,config_data) + config = start_btp_for_already_running_icon_nodes(plan, args_data.src, args_data.dst, config_data, data.src_config["service_name"], data.dst_config["service_name"]) - response = icon_service.deploy_bmv_icon_to_icon(plan,args_data.src,args_data.dst,src_bmc_address,dst_bmc_address,config_data) + return config - src_xcall_address , dst_xcall_address = icon_service.deploy_xcall_icon(plan,args_data.src,args_data.dst,src_bmc_address,dst_bmc_address,config_data) - - src_dapp_address , dst_dapp_address = icon_service.deploy_dapp_icon(plan,args_data.src,args_data.dst,src_xcall_address,dst_xcall_address,config_data) - - - src_block_height = icon_setup_node.hex_to_int(plan,data.src_config["service_name"],response.src_block_height) - dst_block_height = icon_setup_node.hex_to_int(plan,data.src_config["service_name"],response.dst_block_height) - - src_contract_addresses = { - "bmc": response.src_bmc, - "bmv": response.src_bmv, - "xcall": src_xcall_address, - "dapp": src_dapp_address, - } - - dst_contract_addresses = { - "bmc": response.dst_bmc, - "bmv": response.dst_bmv, - "xcall": dst_xcall_address, - "dapp": dst_dapp_address, - } - - config_data["chains"][args_data.src]["networkTypeId"] = response.src_network_type_id - config_data["chains"][args_data.src]["networkId"] = response.src_network_id - config_data["chains"][args_data.dst]["networkTypeId"] = response.dst_network_type_id - config_data["chains"][args_data.dst]["networkId"] = response.dst_network_id - - config_data["contracts"][args_data.src] = src_contract_addresses - config_data["contracts"][args_data.dst] = dst_contract_addresses - config_data["chains"][args_data.src]["block_number"] = src_block_height - config_data["chains"][args_data.dst]["block_number"] = dst_block_height - - - - - if args_data.dst == "eth" or args_data.dst == "hardhat": - src_chain_config = icon_service.start_node_service(plan) - dst_chain_config = eth_node.start_eth_node_serivce(plan,args,args_data.dst) + dst_chain_config = eth_node.start_eth_node_serivce(plan, args, args_data.dst) config_data["chains"][args_data.src] = src_chain_config config_data["chains"][args_data.dst] = dst_chain_config - icon_service.configure_icon_node(plan,src_chain_config) + icon_service.configure_icon_node(plan, src_chain_config) - eth_contract_service.start_deploy_service(plan,dst_chain_config) + config = start_btp_icon_to_eth_for_already_running_nodes(plan, args_data.src, args_data.dst, config_data, src_chain_config["service_name"], dst_chain_config["service_name"]) - src_bmc_address = icon_service.deploy_bmc_icon(plan,args_data.src,args_data.dst,config_data) + return config - dst_bmc_deploy_response = eth_relay_setup.deploy_bmc(plan,config_data,args_data.dst) +def start_btp_for_already_running_icon_nodes(plan, src_chain, dst_chain, config_data, src_service_name, dst_src_name): + src_bmc_address, dst_bmc_address = icon_service.deploy_bmc_icon(plan, src_chain, dst_chain, config_data) - dst_bmc_address = dst_bmc_deploy_response.bmc + response = icon_service.deploy_bmv_icon_to_icon(plan, src_chain, dst_chain, 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) - dst_last_block_height_number = eth_contract_service.get_latest_block(plan,args_data.dst,"localnet") + src_dapp_address, dst_dapp_address = icon_service.deploy_dapp_icon(plan, src_chain, dst_chain, src_xcall_address, dst_xcall_address, config_data) - dst_last_block_height_hex = icon_setup_node.int_to_hex(plan,src_chain_config["service_name"],dst_last_block_height_number) + 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_src_name, response.dst_block_height) + src_contract_addresses = { + "bmc": response.src_bmc, + "bmv": response.src_bmv, + "xcall": src_xcall_address, + "dapp": src_dapp_address, + } - src_response = icon_service.deploy_bmv_icon(plan,args_data.src,args_data.dst,src_bmc_address ,dst_bmc_address,dst_last_block_height_hex,config_data) + dst_contract_addresses = { + "bmc": response.dst_bmc, + "bmv": response.dst_bmv, + "xcall": dst_xcall_address, + "dapp": dst_dapp_address, + } - dst_bmv_address = eth_node.deploy_bmv_eth(plan,args_data.bridge,src_response,config_data,args_data.dst) + config_data["chains"][src_chain]["networkTypeId"] = response.src_network_type_id + config_data["chains"][src_chain]["networkId"] = response.src_network_id + config_data["chains"][dst_chain]["networkTypeId"] = response.dst_network_type_id + config_data["chains"][dst_chain]["networkId"] = response.dst_network_id + config_data["contracts"][src_chain] = src_contract_addresses + config_data["contracts"][dst_chain] = dst_contract_addresses + config_data["chains"][src_chain]["block_number"] = src_block_height + config_data["chains"][dst_chain]["block_number"] = dst_block_height - src_xcall_address = icon_service.deploy_xcall_icon(plan,args_data.src,args_data.dst,src_bmc_address,dst_bmc_address,config_data) + config_data = start_btp_relayer(plan, src_chain, dst_chain, config_data) - dst_xcall_address = eth_relay_setup.deploy_xcall(plan,config_data,args_data.dst) - - src_dapp_address = icon_service.deploy_dapp_icon(plan,args_data.src,args_data.dst,src_xcall_address,dst_xcall_address,config_data) - - dst_dapp_address = eth_relay_setup.deploy_dapp(plan,config_data,args_data.dst) - - src_block_height = icon_setup_node.hex_to_int(plan,src_chain_config["service_name"],src_response.block_height) - - src_contract_addresses = { - "bmc": src_response.bmc, - "bmv": src_response.bmvbridge, - "xcall": src_xcall_address, - "dapp": src_dapp_address, - } - - 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"][args_data.src] = src_contract_addresses - config_data["contracts"][args_data.dst] = dst_contract_addresses - config_data["chains"][args_data.src]["networkTypeId"] = src_response.network_type_id - config_data["chains"][args_data.src]["networkId"] = src_response.network_id - config_data["chains"][args_data.src]["block_number"] = src_block_height - config_data["chains"][args_data.dst]["block_number"] = dst_last_block_height_number + return config_data +def start_btp_icon_to_eth_for_already_running_nodes(plan, src_chain, dst_chain, config_data, src_service_name, dst_src_name): + dst_chain_config = config_data["chains"][dst_chain] + src_chain_config = config_data["chains"][src_chain] + eth_contract_service.start_deploy_service(plan, dst_chain_config) - src_network = config_data["chains"][args_data.src]["network"] - src_bmc = config_data["contracts"][args_data.src]["bmc"] + src_bmc_address = icon_service.deploy_bmc_icon(plan, src_chain, dst_chain, config_data) - dst_network = config_data["chains"][args_data.dst]["network"] - dst_bmc = config_data["contracts"][args_data.dst]["bmc"] + dst_bmc_deploy_response = eth_relay_setup.deploy_bmc(plan, config_data, dst_chain) - src_btp_address = 'btp://{0}/{1}'.format(src_network,src_bmc) - dst_btp_address = 'btp://{0}/{1}'.format(dst_network,dst_bmc) + dst_bmc_address = dst_bmc_deploy_response.bmc + dst_last_block_height_number = eth_contract_service.get_latest_block(plan, dst_chain, "localnet") - btp_bridge.start_relayer(plan,args_data.src,args_data.dst,config_data,src_btp_address,dst_btp_address,args_data.bridge) + dst_last_block_height_hex = icon_setup_node.int_to_hex(plan, src_chain_config["service_name"], dst_last_block_height_number) + src_response = icon_service.deploy_bmv_icon(plan, src_chain, dst_chain, src_bmc_address, dst_bmc_address, dst_last_block_height_hex, config_data) - return config_data + dst_bmv_address = eth_node.deploy_bmv_eth(plan, config_data["bridge"], src_response, config_data, dst_chain) + src_xcall_address = icon_service.deploy_xcall_icon(plan, src_chain, dst_chain, src_bmc_address, dst_bmc_address, config_data) - + dst_xcall_address = eth_relay_setup.deploy_xcall(plan, config_data, dst_chain) + src_dapp_address = icon_service.deploy_dapp_icon(plan, src_chain, dst_chain, src_xcall_address, dst_xcall_address, config_data) + dst_dapp_address = eth_relay_setup.deploy_dapp(plan, config_data, dst_chain) + src_block_height = icon_setup_node.hex_to_int(plan, src_chain_config["service_name"], src_response.block_height) + src_contract_addresses = { + "bmc": src_response.bmc, + "bmv": src_response.bmvbridge, + "xcall": src_xcall_address, + "dapp": src_dapp_address, + } + 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_chain] = src_contract_addresses + config_data["contracts"][dst_chain] = dst_contract_addresses + config_data["chains"][src_chain]["networkTypeId"] = src_response.network_type_id + config_data["chains"][src_chain]["networkId"] = src_response.network_id + config_data["chains"][src_chain]["block_number"] = src_block_height + config_data["chains"][dst_chain]["block_number"] = dst_last_block_height_number + config_data = start_btp_relayer(plan, src_chain, dst_chain, config_data) + return config_data +def start_btp_relayer(plan, src_chain, dst_chain, config_data): + src_network = config_data["chains"][src_chain]["network"] + src_bmc = config_data["contracts"][src_chain]["bmc"] + dst_network = config_data["chains"][dst_chain]["network"] + dst_bmc = config_data["contracts"][dst_chain]["bmc"] - + src_btp_address = "btp://{0}/{1}".format(src_network, src_bmc) + dst_btp_address = "btp://{0}/{1}".format(dst_network, dst_bmc) + btp_bridge.start_relayer(plan, src_chain, dst_chain, config_data, src_btp_address, dst_btp_address, config_data["bridge"]) + return config_data