Skip to content

Commit

Permalink
feat: icon cosmos integration (#146)
Browse files Browse the repository at this point in the history
* feat: update icon and wasm contracts for ibc setup

* feat: implement methods to deploy wasm contracts

* feat: implement contract mehtods for icon ibc

* feat: update contract deployment for ibc setup

* chore: update code

* feat: update main.star file

* chore:update code

* feat: update contract deployment

* chore: add relay service for icon to cosmos

* feat: update comos constants

* feat: update cosmos relayer for icon to cosmos

* fix: remove typos from code

* feat; update keystore for relay setup

* chore: update main

* feat: update relay setup for icon comsos

* feat: add relay start command

* fix: rly start command

* chore: update icon-ibc-relay image version

* fix: contract setup archway

* fix: remove debug print statements

* feat: update relay start command

* fix: error when node already running

* fix: help falg for archway chain command

* feat: update bridge

* feat: update cosmos package for icon archway

* chore: bump versions of dive and kurtosis sdk

* fix: typo in user output

* feat: update service file writes

* chore: remove print statemet

---------

Co-authored-by: Prathiksha-Nataraja <[email protected]>
Co-authored-by: Shanith K K <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2023
1 parent 8266f65 commit 2327a66
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 32 deletions.
10 changes: 6 additions & 4 deletions cli/commands/chain/types/archway.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func NewArchwayCmd(diveContext *common.DiveContext) *cobra.Command {

common.WriteToServiceFile(runResponse.ServiceName, *runResponse)

diveContext.StopSpinner("Archyway Node Started. Please find service details in current working directory(services.json)")
diveContext.StopSpinner("Archway Node Started. Please find service details in current working directory(services.json)")
},
}
archwayCmd.Flags().StringVarP(&config, "config", "c", "", "provide config to start archway node ")
archwayCmd.Flags().StringVarP(&config, "config", "c", "", "path to custom config json file to start archway node ")

return archwayCmd
}
Expand Down Expand Up @@ -170,12 +170,14 @@ func runArchwayWithDefaultServiceConfig(diveContext *common.DiveContext, enclave

}

nodeServiceResponseData, _, _, err := diveContext.GetSerializedData(nodeServiceResponse)
nodeServiceResponseData, services, skippedInstructions, err := diveContext.GetSerializedData(nodeServiceResponse)
if err != nil {

return "", err
diveContext.StopServices(services)
diveContext.FatalError("Starlark Run Failed", err.Error())

}
diveContext.CheckInstructionSkipped(skippedInstructions, "Archway Node Already Running")

return nodeServiceResponseData, nil
}
2 changes: 1 addition & 1 deletion cli/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package common
var DiveLogs bool

// !!!!!!!!!!! DO NOT UPDATE! WILL BE UPDATED DURING THE RELEASE PROCESS !!!!!!!!!!!!!!!!!!!!!!
var DiveVersion = "v0.0.8-beta"
var DiveVersion = "v0.0.9-beta"

const (
DiveEnclave = "dive"
Expand Down
36 changes: 11 additions & 25 deletions cli/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,42 +212,28 @@ func WriteToServiceFile(serviceName string, data DiveserviceResponse) error {
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
}

if len(jsonDataFromFile) == 0 {
jsonDataFromFile = Services{}
}
newServices := Services{}

newServices[serviceName] = &data
var dataToWrite []byte

dataTowrite, err := json.Marshal(newServices)
if err != nil {
return err
_, ok := jsonDataFromFile[serviceName]
if !ok {
jsonDataFromFile[serviceName] = &data
dataToWrite, err = json.Marshal(jsonDataFromFile)
if err != nil {
return err
}
}

_, err = file.Write(dataTowrite)
_, err = file.Write(dataToWrite)

if err != nil {
return err
}

return nil

}

func ReadServiceJsonFile() (Services, error) {
Expand Down
2 changes: 1 addition & 1 deletion cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/briandowns/spinner v1.23.0
github.com/fatih/color v1.15.0
github.com/google/go-github v17.0.0+incompatible
github.com/kurtosis-tech/kurtosis/api/golang v0.82.5
github.com/kurtosis-tech/kurtosis/api/golang v0.82.6
github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/sirupsen/logrus v1.9.3
Expand Down
92 changes: 91 additions & 1 deletion main.star
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ btp_bridge = import_module("github.com/hugobyte/dive/services/bridges/btp/src/br
input_parser = import_module("github.com/hugobyte/dive/package_io/input_parser.star")
cosmvm_node = import_module("github.com/hugobyte/dive/services/cosmvm/cosmvm.star")
cosmvm_relay = import_module("github.com/hugobyte/dive/services/bridges/ibc/src/bridge.star")
cosmvm_relay_setup = import_module("github.com/hugobyte/dive/services/cosmvm/archway/src/relay-setup/contract-configuration.star")

def run(plan, args):
return parse_input(plan, args)
Expand Down Expand Up @@ -48,13 +49,17 @@ def parse_input(plan, args):

return data

elif args["relay"]["name"] == "cosmos":
elif args["relay"]["name"] == "ibc":
data = run_cosmos_ibc_setup(plan, args["relay"])

return data

else:
fail("More Relay Support will be added soon")
if args["action"] == "start_relay":
if args["relay"]["name"] == "ibc":
service_name = args["relay"]["service"]
cosmvm_relay.start_relay(plan,service_name)

def run_node(plan, node_name, args):
if node_name == "icon":
Expand Down Expand Up @@ -245,6 +250,90 @@ def run_cosmos_ibc_setup(plan, args):
config_data = run_cosmos_ibc_relay_for_already_running_chains(plan,links,data.src_config,data.dst_config)
return config_data

if destination_chain == "archway":

src_chain_config = icon_service.start_node_service(plan)
data = {"data":{}}
dst_chain_config = cosmvm_node.start_cosmvm_chains(plan, destination_chain,data)

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,"")

config_data["chains"][src_chain_service_name] = src_chain_config
config_data["chains"][dst_chain_service_name] = dst_chain_config

deploy_icon_contracts = icon_relay_setup.setup_contracts_for_ibc_java(plan,src_chain_config)
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"])

icon_setup_node.configure_node(plan,src_chain_config)

src_chain_last_block_height = icon_setup_node.get_last_block(plan,src_chain_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)

src_data = {
"name" : network_name,
"owner" : deploy_icon_contracts["ibc_core"]
}

icon_setup_node.open_btp_network(plan,src_chain_service_name,src_data,src_chain_config["endpoint"],src_chain_config["keystore_path"], src_chain_config["keypassword"],src_chain_config["nid"])

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")

deploy_archway_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_archway_contracts["ibc_core"],deploy_archway_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_archway_contracts["ibc_core"],deploy_archway_contracts["xcall_connection"])


config_data["contracts"][src_chain_service_name] = deploy_icon_contracts
config_data["contracts"][dst_chain_service_name] = deploy_archway_contracts

src_chain_data = {
"chain_id": "0xacbc4e",
"rpc_address": src_chain_config["endpoint"],
"ibc_address": deploy_icon_contracts["ibc_core"],
"password" : src_chain_config["keypassword"]
}
dst_chain_data = {
"chain_id": dst_chain_config.chain_id,
"key": dst_chain_config.chain_key,
"rpc_address": dst_chain_config.endpoint,
"ibc_address": deploy_archway_contracts["ibc_core"],
"service_name": dst_chain_config.service_name
}
relay_service_response = cosmvm_relay.start_cosmos_relay_for_icon_to_cosmos(plan,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_archway_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_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_archway_contracts["xcall"],deploy_archway_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_archway_contracts["xcall_connection"],relay_data.dst_connection_id,"xcall",src_chain_config["network"],relay_data.dst_client_id,deploy_archway_contracts["xcall"])

icon_relay_setup.configure_connection_for_java(plan,deploy_icon_contracts["xcall"],deploy_icon_contracts["xcall_connection"],dst_chain_config.chain_id,relay_data.src_connection_id,"xcall",dst_chain_config.chain_id,relay_data.src_client_id,src_chain_service_name,src_chain_config["endpoint"],src_chain_config["keystore_path"],src_chain_config["keypassword"],src_chain_config["nid"])


config_data["contracts"][src_chain_service_name]["dapp"] = dapp_result_java["xcall_dapp"]
config_data["contracts"][dst_chain_service_name]["dapp"] = dapp_result_wasm["xcall_dapp"]

cosmvm_relay.start_channel(plan,relay_service_response.service_name,path_name,"xcall","xcall")


return config_data



def run_cosmos_ibc_relay_for_already_running_chains(plan,links,src_config,dst_config):

src_chain_service_name = src_config["service_name"]
Expand All @@ -260,3 +349,4 @@ def run_cosmos_ibc_relay_for_already_running_chains(plan,links,src_config,dst_co
cosmvm_relay.start_cosmos_relay(plan, src_chain_key, src_chain_id, dst_chain_key, dst_chain_id, src_config, dst_config)

return config_data

0 comments on commit 2327a66

Please sign in to comment.