diff --git a/local-interchain/chains/base_ibc.json b/local-interchain/chains/base_ibc.json index 22bcd15cc..9c03a3a76 100644 --- a/local-interchain/chains/base_ibc.json +++ b/local-interchain/chains/base_ibc.json @@ -9,7 +9,7 @@ "docker_image": { "version": "v9.1.0" }, - "block_time": "6s", + "block_time": "2s", "gas_prices": "0%DENOM%", "gas_adjustment": 2.0, "ibc_paths": ["atom-juno", "atom-terra"], @@ -49,7 +49,7 @@ "docker_image": { "version": "v2.3.4" }, - "block_time": "6s", + "block_time": "2s", "encoding-options": ["wasm"], "gas_prices": "0%DENOM%", "gas_adjustment": 2.0, diff --git a/local-interchain/chains/cosmoshub.json b/local-interchain/chains/cosmoshub.json index 23edf037b..a402ec225 100644 --- a/local-interchain/chains/cosmoshub.json +++ b/local-interchain/chains/cosmoshub.json @@ -1,23 +1,23 @@ -{ +{ "chains": [ { - "name": "gaia", + "name": "gaia", "chain_id": "localcosmos-1", "denom": "uatom", "binary": "gaiad", "bech32_prefix": "cosmos", - "docker_image": { + "docker_image": { "version": "v10.0.1" - }, + }, "gas_prices": "0%DENOM%", "chain_type": "cosmos", "coin_type": 118, "trusting_period": "112h", "gas_adjustment": 2.0, "number_vals": 1, - "number_node": 0, + "number_node": 0, "debugging": true, - "block_time": "500ms", + "block_time": "500ms", "genesis": { "modify": [ { @@ -32,15 +32,15 @@ "key": "app_state.gov.deposit_params.min_deposit.0.denom", "value": "uatom" } - ], + ], "accounts": [ { "name": "acc0", - "address": "cosmos1hj5fveer5cjtn4wd6wstzugjfdxzl0xpxvjjvr", + "address": "cosmos1hj5fveer5cjtn4wd6wstzugjfdxzl0xpxvjjvr", "amount": "10000000000%DENOM%", "mnemonic": "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" } - ] + ] } } ] diff --git a/local-interchain/chains/juno_ibc.json b/local-interchain/chains/juno_ibc.json index f22cdaddc..b991b5844 100644 --- a/local-interchain/chains/juno_ibc.json +++ b/local-interchain/chains/juno_ibc.json @@ -1,7 +1,7 @@ -{ +{ "chains": [ { - "name": "juno", + "name": "juno", "chain_id": "localjuno-1", "denom": "ujuno", "binary": "junod", @@ -19,7 +19,7 @@ "number_node": 0, "block_time": "500ms", "ibc_paths": ["juno-ibc-1"], - "debugging": true, + "debugging": true, "encoding-options": ["juno"], "genesis": { "modify": [ @@ -35,7 +35,7 @@ "key": "app_state.gov.params.min_deposit.0.denom", "value": "ujuno" } - ], + ], "accounts": [ { "name": "acc0", @@ -49,7 +49,7 @@ "amount": "10000000%DENOM%", "mnemonic": "wealth flavor believe regret funny network recall kiss grape useless pepper cram hint member few certain unveil rather brick bargain curious require crowd raise" } - ] + ] } }, { @@ -62,7 +62,7 @@ "repository": "ghcr.io/cosmoscontracts/juno", "version": "v17.0.0" }, - "genesis": { + "genesis": { "accounts": [ { "name": "second0", @@ -76,13 +76,13 @@ "amount": "10000000%DENOM%", "mnemonic": "wealth flavor believe regret funny network recall kiss grape useless pepper cram hint member few certain unveil rather brick bargain curious require crowd raise" } - ] + ] }, "block_time": "500ms", "encoding-options": ["juno"], "gas_prices": "0%DENOM%", "gas_adjustment": 2.0, - "ibc_paths": ["juno-ibc-1"] + "ibc_paths": ["juno-ibc-1"] } ] } \ No newline at end of file diff --git a/local-interchain/chains/stargaze.json b/local-interchain/chains/stargaze.json index 331372f82..dda204fc2 100644 --- a/local-interchain/chains/stargaze.json +++ b/local-interchain/chains/stargaze.json @@ -1,21 +1,21 @@ -{ +{ "chains": [ { - "name": "stargaze", + "name": "stargaze", "chain_id": "localstars-1", "denom": "ustars", "binary": "starsd", "bech32_prefix": "stars", - "docker_image": { + "docker_image": { "version": "v10.0.1" - }, + }, "gas_prices": "0%DENOM%", "chain_type": "cosmos", "coin_type": 118, "trusting_period": "112h", "gas_adjustment": 2.0, "number_vals": 1, - "number_node": 0, + "number_node": 0, "debugging": true, "block_time": "500ms", "encoding-options": ["wasm"], @@ -33,15 +33,15 @@ "key": "app_state.gov.deposit_params.min_deposit.0.denom", "value": "ustars" } - ], + ], "accounts": [ { "name": "acc0", - "address": "stars1hj5fveer5cjtn4wd6wstzugjfdxzl0xpjs908j", + "address": "stars1hj5fveer5cjtn4wd6wstzugjfdxzl0xpjs908j", "amount": "10000000000%DENOM%", "mnemonic": "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" } - ] + ] } } ] diff --git a/local-interchain/cmd/local-ic/interaction.go b/local-interchain/cmd/local-ic/interaction.go new file mode 100644 index 000000000..547bc3cb7 --- /dev/null +++ b/local-interchain/cmd/local-ic/interaction.go @@ -0,0 +1,83 @@ +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "net/http" + "strings" + + "github.com/spf13/cobra" + "github.com/strangelove-ventures/localinterchain/interchain/handlers" +) + +const ( + FlagAPIEndpoint = "api-endpoint" +) + +func init() { + interactCmd.Flags().String(FlagAPIAddressOverride, "http://127.0.0.1:8080", "override the default API address") +} + +var interactCmd = &cobra.Command{ + Use: "interact [chain_id] [interaction] [arguments...]", + Short: "Interact with a node", + Example: `local-ic interact localcosmos-1 bin 'status --node=%RPC%' --api-endpoint=http://127.0.0.1:8080 +local-ic interact localcosmos-1 query bank balances cosmos1hj5fveer5cjtn4wd6wstzugjfdxzl0xpxvjjvr +local-ic interact localcosmos-1 get_channels +local-ic interact localcosmos-1 relayer-exec rly q channels localcosmos-1 +`, + Args: cobra.MinimumNArgs(2), + Aliases: []string{"i"}, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return GetFiles(), cobra.ShellCompDirectiveNoFileComp + }, + Run: func(cmd *cobra.Command, args []string) { + + ah := handlers.ActionHandler{ + ChainId: args[0], + Action: args[1], + } + + if len(args) > 2 { + ah.Cmd = strings.Join(args[2:], " ") + } + + apiAddr, _ := cmd.Flags().GetString(FlagAPIAddressOverride) + + res := makeHttpReq(apiAddr, ah) + fmt.Println(res) + }, +} + +func makeHttpReq(apiEndpoint string, ah handlers.ActionHandler) string { + client := &http.Client{} + + // curl -X POST -H "Content-Type: application/json" -d '{ + // "chain_id": "localjuno-1", + // "action": "query", + // "cmd": "bank balances juno1hj5fveer5cjtn4wd6wstzugjfdxzl0xps73ftl" + // }' http://127.0.0.1:8080/ + jsonData, err := json.Marshal(ah) + if err != nil { + panic(err) + } + + req, err := http.NewRequest("POST", apiEndpoint, bytes.NewReader(jsonData)) + if err != nil { + panic(err) + } + req.Header.Set("Content-Type", "application/json") + resp, err := client.Do(req) + if err != nil { + panic(err) + } + defer resp.Body.Close() + bodyText, err := io.ReadAll(resp.Body) + if err != nil { + panic(err) + } + + return string(bodyText) +} diff --git a/local-interchain/cmd/local-ic/main.go b/local-interchain/cmd/local-ic/main.go index a78af4c51..4a1ee8b63 100644 --- a/local-interchain/cmd/local-ic/main.go +++ b/local-interchain/cmd/local-ic/main.go @@ -9,6 +9,7 @@ func main() { rootCmd.AddCommand(chainsCmd) rootCmd.AddCommand(newChainCmd) rootCmd.AddCommand(startCmd) + rootCmd.AddCommand(interactCmd) if err := rootCmd.Execute(); err != nil { fmt.Fprintf(os.Stderr, "error while executing your CLI. Err: %v\n", err)