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(08-wasm): expose migrate entry point for 08-wasm #6231

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
10 changes: 10 additions & 0 deletions docs/docs/03-light-clients/04-wasm/08-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions modules/light-clients/08-wasm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistency in the use of backticks for command names.

- * [#\6231](https://github.com/cosmos/ibc-go/pull/6231) feat: add CLI to broadcast transaction with `MsgMigrateContract`.
+ * [#\6231](https://github.com/cosmos/ibc-go/pull/6231) feat: add CLI to broadcast transaction with `MsgMigrateContract`.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* [#\6231](https://github.com/cosmos/ibc-go/pull/6231) feat: add CLI to broadcast transaction with `MsgMigrateContract`.
* [#\6231](https://github.com/cosmos/ibc-go/pull/6231) feat: add CLI to broadcast transaction with `MsgMigrateContract`.


### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions modules/light-clients/08-wasm/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewTxCmd() *cobra.Command {

txCmd.AddCommand(
newSubmitStoreCodeProposalCmd(),
newMigrateContractCmd(),
)

return txCmd
Expand Down
40 changes: 39 additions & 1 deletion modules/light-clients/08-wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this was wrong, so I took the liberty to fix it here.

Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down Expand Up @@ -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]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed new-code-msg to migrate-msg, since this is a JSON-encoded string that is passed to the contract that is being migrated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cmd also support passing the json msg as a path to a file? We do that on many other cmds that accept some kind of sub msg.

Do you think we should support this? cc. @crodriguezvega @srdtrk

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess most contracts for now will not do anything with this message, so most of the times it will be just {}? I am fine supporting it already now or adding support for it later.

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
}
Loading