From 34164efb37fe88eeb182a599915f3880e4e186b7 Mon Sep 17 00:00:00 2001 From: Kien Date: Mon, 29 Apr 2024 18:58:24 +0700 Subject: [PATCH] feat(08-wasm): expose migrate entry point for 08-wasm (#6231) * feat: expose migrate entry point for 08-wasm * add CLI documentation * add changelog * improve CLI inline docs * small fix * rename variable * remove gov flags * use double quotes * fix lint warning * Apply suggestions from code review Co-authored-by: Damian Nolan --------- Co-authored-by: Carlos Rodriguez Co-authored-by: Damian Nolan --- .../03-light-clients/04-wasm/08-client.md | 10 +++++ modules/light-clients/08-wasm/CHANGELOG.md | 1 + .../light-clients/08-wasm/client/cli/cli.go | 1 + .../light-clients/08-wasm/client/cli/tx.go | 40 ++++++++++++++++++- 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/docs/docs/03-light-clients/04-wasm/08-client.md b/docs/docs/03-light-clients/04-wasm/08-client.md index dd24108f2d0..1139d4e2510 100644 --- a/docs/docs/03-light-clients/04-wasm/08-client.md +++ b/docs/docs/03-light-clients/04-wasm/08-client.md @@ -29,6 +29,16 @@ simd tx ibc-wasm store-code [path/to/wasm-file] [flags] `path/to/wasm-file` is the path to the `.wasm` or `.wasm.gz` file. +#### `migrate-contract` + +The `migrate-contract` command allows users to broadcast a transaction with a `MsgMigrateContract` to migrate the contract for a given light client to a new byte code denoted by the given checksum. + +```shell +simd tx ibc-wasm migrate-contract [client-id] [checksum] [migrate-msg] +``` + +The migrate message must not be emptied and is expected to be a JSON-encoded string. + ### Query The `query` commands allow users to query `08-wasm` state. diff --git a/modules/light-clients/08-wasm/CHANGELOG.md b/modules/light-clients/08-wasm/CHANGELOG.md index e8f10e5432f..aae2b208d88 100644 --- a/modules/light-clients/08-wasm/CHANGELOG.md +++ b/modules/light-clients/08-wasm/CHANGELOG.md @@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features * [#\5821](https://github.com/cosmos/ibc-go/pull/5821) feat: add `VerifyMembershipProof` RPC query (querier approach for conditional clients). +* [#\6231](https://github.com/cosmos/ibc-go/pull/6231) feat: add CLI to broadcast transaction with `MsgMigrateContract`. ### Bug Fixes diff --git a/modules/light-clients/08-wasm/client/cli/cli.go b/modules/light-clients/08-wasm/client/cli/cli.go index a40ea3ce48f..96e35b5c39a 100644 --- a/modules/light-clients/08-wasm/client/cli/cli.go +++ b/modules/light-clients/08-wasm/client/cli/cli.go @@ -36,6 +36,7 @@ func NewTxCmd() *cobra.Command { txCmd.AddCommand( newSubmitStoreCodeProposalCmd(), + newMigrateContractCmd(), ) return txCmd diff --git a/modules/light-clients/08-wasm/client/cli/tx.go b/modules/light-clients/08-wasm/client/cli/tx.go index 7e85a26b7e5..92c5a95c21c 100644 --- a/modules/light-clients/08-wasm/client/cli/tx.go +++ b/modules/light-clients/08-wasm/client/cli/tx.go @@ -27,7 +27,7 @@ func newSubmitStoreCodeProposalCmd() *cobra.Command { Use: "store-code [path/to/wasm-file]", Short: "Reads wasm code from the file and creates a proposal to store the wasm code", Long: "Reads wasm code from the file and creates a proposal to store the wasm code", - Example: fmt.Sprintf("%s tx %s wasm [path/to/wasm_file]", version.AppName, ibcexported.ModuleName), + Example: fmt.Sprintf("%s tx %s-wasm store-code [path/to/wasm_file]", version.AppName, ibcexported.ModuleName), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) @@ -82,3 +82,41 @@ func newSubmitStoreCodeProposalCmd() *cobra.Command { return cmd } + +func newMigrateContractCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "migrate-contract [client-id] [checksum] [migrate-msg]", + Short: "Migrates a contract to a new byte code", + Long: "Migrates the contract for the specified client ID to the byte code corresponding to checksum, passing the JSON-encoded migrate message to the contract", + Example: fmt.Sprintf("%s tx %s-wasm migrate-contract 08-wasm-0 b3a49b2914f5e6a673215e74325c1d153bb6776e079774e52c5b7e674d9ad3ab {}", version.AppName, ibcexported.ModuleName), + Args: cobra.ExactArgs(3), // Ensure exactly three arguments are passed + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + clientID := args[0] + checksum := args[1] + migrateMsg := args[2] + + // Construct the message + msg := &types.MsgMigrateContract{ + Signer: clientCtx.GetFromAddress().String(), + ClientId: clientID, + Checksum: []byte(checksum), + Msg: []byte(migrateMsg), + } + + if err := msg.ValidateBasic(); err != nil { + return err + } + + // Generate or broadcast the transaction + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + return cmd +}