Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cosmos starlark package #104

Merged
merged 6 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/commands/chain/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ maintenance within the specified blockchain ecosystem.`,
chainCmd.AddCommand(types.NewIconCmd(diveContext))
chainCmd.AddCommand(types.NewEthCmd(diveContext))
chainCmd.AddCommand(types.NewHardhatCmd(diveContext))
chainCmd.AddCommand(types.NewCosmosCmd(diveContext))

return chainCmd

Expand Down
21 changes: 21 additions & 0 deletions cli/commands/chain/types/cosmos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package types

import (
"github.com/hugobyte/dive/common"
"github.com/spf13/cobra"
)

func NewCosmosCmd(diveContext *common.DiveContext) *cobra.Command {

cosmosCmd := &cobra.Command{
Use: "cosmos",
Short: "Build, initialize and start a cosmos node.",
Long: `The command starts an Cosmos node, initiating the process of setting up and launching a local cosmos network.
It establishes a connection to the Cosmos network and allows the node in executing smart contracts and maintaining the decentralized ledger.`,
Run: func(cmd *cobra.Command, args []string) {

},
}

return cosmosCmd
}
192 changes: 97 additions & 95 deletions main.star

Large diffs are not rendered by default.

61 changes: 31 additions & 30 deletions package_io/constants.star
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ICON_NODE_CLIENT = struct(
public_ip_address = "127.0.0.1",
rpc_endpoint_path = "api/v3/icon_dex",
service_name = "icon-node-",
genesis_file_path = "/goloop/genesis/"
genesis_file_path = "/goloop/genesis/",
)

HARDHAT_NODE_CLIENT = struct(
Expand All @@ -23,38 +23,37 @@ HARDHAT_NODE_CLIENT = struct(
network = "0x539.hardhat",
network_id = "0x539",
keystore_path = "keystores/hardhat_keystore.json",
keypassword = "hardhat"
keypassword = "hardhat",
)

CONTRACT_DEPLOYMENT_SERVICE_ETHEREUM = struct(
node_image = "node:lts-alpine",
static_file_path = "github.com/hugobyte/dive/services/evm/eth/static-files/",
static_files_directory_path = "/static-files/",
service_name = "eth-contract-deployer",
template_file = "github.com/hugobyte/dive/services/evm/eth/static-files/hardhat.config.ts.tmpl",
rendered_file_directory = "/static-files/rendered/"
node_image = "node:lts-alpine",
static_file_path = "github.com/hugobyte/dive/services/evm/eth/static-files/",
static_files_directory_path = "/static-files/",
service_name = "eth-contract-deployer",
template_file = "github.com/hugobyte/dive/services/evm/eth/static-files/hardhat.config.ts.tmpl",
rendered_file_directory = "/static-files/rendered/",
)

ETH_NODE_CLIENT = struct(
service_name = "el-1-geth-lighthouse",
network_name= "eth",
network = "0x301824.eth",
nid = "0x301824",
keystore_path = "keystores/eth_keystore.json",
keypassword = "password"
service_name = "el-1-geth-lighthouse",
network_name = "eth",
network = "0x301824.eth",
nid = "0x301824",
keystore_path = "keystores/eth_keystore.json",
keypassword = "password",
)

COSMOS_NODE_CLIENT = struct(
start_cosmos = "github.com/hugobyte/dive/services/cosmvm/start-cosmos-0.sh",
start_cosmos_1 = "github.com/hugobyte/dive/services/cosmvm/start-cosmos-1.sh",
start_script = "github.com/hugobyte/dive/services/cosmvm/static_files/start.sh",
default_contract_path = "github.com/hugobyte/dive/services/cosmvm/static_files/contracts",
service_name = "cosmos",
service_name_1 = "cosmos1",
image = "archwaynetwork/archwayd:constantine",
path = "/start-scripts/",
contract_path = "/root/contracts/",
chain_id = "my-chain",
chain_id_1 = "chain-1",
chain_id = "chain-1",
chain_id_1 = "chain-2",
public_ip_address = "127.0.0.1",
cosmos_grpc_port_key = "grpc",
cosmos_rpc_port_key = "rpc",
Expand All @@ -64,19 +63,21 @@ COSMOS_NODE_CLIENT = struct(
private_port_http = 9091,
private_port_tcp = 26656,
private_port_rpc = 26657,
public_port_grpc_node_1 = 9090,
public_port_http_node_1 = 9091,
public_port_tcp_node_1 = 26656,
public_port_rpc_node_1 = 4564,
public_port_grpc_node_2 = 9080,
public_port_http_node_2 = 9092,
public_port_tcp_node_2 = 26658,
public_port_rpc_node_2 = 4566,
public_port_grpc = 9090,
public_port_http = 9091,
public_port_tcp = 26656,
public_port_rpc = 4564,
public_port_grpc_node = 9080,
public_port_http_node = 9092,
public_port_tcp_node = 26658,
public_port_rpc_node = 4566,
config_files = "github.com/hugobyte/dive/services/cosmvm/static_files/config/",
config_files_template = "github.com/hugobyte/dive/services/bridges/ibc/static-files/config/archwayjson.tpl",
relay_service_name = "cosmos-relay",
relay_service_image = "relay1",
relay_service_image = "hugobyte/ibc-relay",
relay_config_files_path = "/script/",
run_file_path = "github.com/hugobyte/dive/services/bridges/ibc/static-files/run.sh",
key = "chain-1-key",
key1 = "chain-2-key",
password = "password",
)



43 changes: 27 additions & 16 deletions package_io/input_parser.star
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
def generate_config_data(args):

data = get_args_data(args)
config_data = {
"links": data.links,
"chains" : {
"%s" % data.src : {},
"%s" % data.dst : {}
"chains": {
"%s" % data.src: {},
"%s" % data.dst: {},
},
"contracts" : {
"%s" % data.src : {},
"%s" % data.dst : {}
"contracts": {
"%s" % data.src: {},
"%s" % data.dst: {},
},
"bridge" : data.bridge
"bridge": data.bridge,
}

return config_data

def get_args_data(args):

links = args["links"]
source_chain = links["src"]
destination_chain = links["dst"]

if destination_chain == "icon" and source_chain == "icon":
destination_chain = "icon-1"

if source_chain == "eth" or source_chain == "hardhat":
if destination_chain == "icon":
destination_chain = source_chain
source_chain = "icon"
source_chain = "icon"

if destination_chain == "cosmwasm" and source_chain == "cosmwasm":
destination_chain = "cosmwasm1"
destination_chain = "cosmwasm1"

bridge = args["bridge"]

return struct(
links = links,
src = source_chain,
dst = destination_chain,
bridge = bridge
)
bridge = bridge,
)

def generate_new_config_data(links, srcchain_service_name, dst_chain_service_name, bridge):
config_data = {
"links": links,
"chains": {
"%s" % srcchain_service_name: {},
"%s" % dst_chain_service_name: {},
},
"contracts": {
"%s" % srcchain_service_name: {},
"%s" % dst_chain_service_name: {},
},
"bridge": bridge,
}

return config_data
24 changes: 0 additions & 24 deletions services/bridges/btp/src/cosmos_relay.star

This file was deleted.

61 changes: 61 additions & 0 deletions services/bridges/ibc/src/bridge.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
constants = import_module("github.com/hugobyte/dive/package_io/constants.star")
cosmos_node_constants = constants.COSMOS_NODE_CLIENT

def start_cosmos_relay(plan, src_key, src_chain_id, dst_key, dst_chain_id, src_config, dst_config):
plan.print("starting cosmos relay")

plan.upload_files(src = cosmos_node_constants.run_file_path, name = "run")
comos_config = read_file(cosmos_node_constants.config_files_template)
cfg_template_data = {
"KEY": src_key,
"CHAINID": src_chain_id,
}
plan.render_templates(
config = {
"cosmos-%s.json" % src_chain_id: struct(
template = comos_config,
data = cfg_template_data,
),
},
name = "config-%s" % src_chain_id,
)

cfg_template_data = {
"KEY": dst_key,
"CHAINID": dst_chain_id,
}
plan.render_templates(
config = {
"cosmos-%s.json" % dst_chain_id: struct(
template = comos_config,
data = cfg_template_data,
),
},
name = "config-%s" % dst_chain_id,
)

plan.exec(service_name = src_config["service_name"], recipe = ExecRecipe(command = ["/bin/sh", "-c", "apk add jq"]))

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

plan.exec(service_name = dst_config["service_name"], recipe = ExecRecipe(command = ["/bin/sh", "-c", "apk add jq"]))

dst_chain_seed = plan.exec(service_name = dst_config["service_name"], recipe = ExecRecipe(command = ["/bin/sh", "-c", "jq -r '.mnemonic' ../../start-scripts/key_seed.json | tr -d '\n\r'"]))

relay_service = ServiceConfig(
image = cosmos_node_constants.relay_service_image,
files = {
cosmos_node_constants.relay_config_files_path + src_chain_id: "config-%s" % src_chain_id,
cosmos_node_constants.relay_config_files_path + dst_chain_id: "config-%s" % dst_chain_id,
cosmos_node_constants.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"])],
)

plan.print(relay_service)

plan.add_service(name = cosmos_node_constants.relay_service_name, config = relay_service)

return struct(
service_name = cosmos_node_constants.relay_service_name,
)
17 changes: 17 additions & 0 deletions services/bridges/ibc/static-files/config/archwayjson.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "cosmos",
"value": {
"key": "{{.KEY}}",
"chain-id": "{{.CHAINID}}",
"rpc-addr": "",
"grpc-addr": "",
"account-prefix": "archway",
"keyring-backend": "test",
"gas-adjustment": 1.5,
"gas-prices": "0.0025stake",
"debug": true,
"timeout": "20s",
"output-format": "json",
"sign-mode": "direct"
}
}
47 changes: 47 additions & 0 deletions services/bridges/ibc/static-files/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

srcChainId=$1
dstChainId=$2
srcChainKey=$3
dstChainKey=$4
srcChainEndpoint=$5
dstChainEndpoint=$6
srcChainSeed=$7
dstChainSeed=$8
relayConnectionPath=${srcChainId}-${dstChainId}

sed -i -e 's|\"rpc-addr\": \"\"|\"rpc-addr\": \"'${srcChainEndpoint}'\"|' ../script/${srcChainId}/cosmos-${srcChainId}.json

sed -i -e 's|\"rpc-addr\": \"\"|\"rpc-addr\": \"'${dstChainEndpoint}'\"|' ../script/${dstChainId}/cosmos-${dstChainId}.json


echo "Init Relay"

rly config init

echo "Adding Chain ${srcChainId}"

rly chains add --file ../script/${srcChainId}/cosmos-${srcChainId}.json ${srcChainId}

echo "Adding Chain ${dstChainId}"

rly chains add --file ../script/${dstChainId}/cosmos-${dstChainId}.json ${dstChainId}

echo "Adding Keys"

rly keys restore ${srcChainId} ${srcChainKey} "${srcChainSeed}"

rly keys restore ${dstChainId} ${dstChainKey} "${dstChainSeed}"

echo "Adding the paths"

rly paths new ${srcChainId} ${dstChainId} ${relayConnectionPath}

rly transact connection ${relayConnectionPath}

rly tx link ${relayConnectionPath} -d -t 3s

rly paths list

rly start

Loading