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 3 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 `migration-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.
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved

```shell
simd tx ibc-wasm migration-contract [client-id] [checksum] [migrate-msg]
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
```

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
45 changes: 45 additions & 0 deletions modules/light-clients/08-wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,48 @@

return cmd
}

func newMigrateContractCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "migrate-contract [client-id] [checksum] [new-code-msg]",
Short: "Migrates a contract to a new code version",
Long: `Migrates a contract to a new code version using the specified client ID, checksum, and new code message.`,
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]

Check warning on line 98 in modules/light-clients/08-wasm/client/cli/tx.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var clientId should be clientID (revive)
checksum := args[1]
newCodeMsg := args[2]

// Construct the message
msg := &types.MsgMigrateContract{
Signer: clientCtx.GetFromAddress().String(),
ClientId: clientId,
Checksum: []byte(checksum),
Msg: []byte(newCodeMsg),
}

if err := msg.ValidateBasic(); err != nil {
return err
}

// Generate or broadcast the transaction
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

cmd.Flags().String(FlagAuthority, "", "The address of the wasm client module authority (defaults to gov)")

flags.AddTxFlagsToCmd(cmd)
govcli.AddGovPropFlagsToCmd(cmd)
err := cmd.MarkFlagRequired(govcli.FlagTitle)
if err != nil {
panic(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing panic with a more graceful error handling method in the flag setup. Panicking in a CLI application can lead to abrupt termination which might not be user-friendly.

- panic(err)
+ if err != nil {
+     fmt.Fprintf(os.Stderr, "Error setting up required flags: %v\n", err)
+     os.Exit(1)
+ }

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
err := cmd.MarkFlagRequired(govcli.FlagTitle)
if err != nil {
panic(err)
}
err := cmd.MarkFlagRequired(govcli.FlagTitle)
if err != nil {
fmt.Fprintf(os.Stderr, "Error setting up required flags: %v\n", err)
os.Exit(1)
}


return cmd
}
Loading