Skip to content

Commit

Permalink
feat(08-wasm): expose migrate entry point for 08-wasm (#6231)
Browse files Browse the repository at this point in the history
* 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 <damiannolan@gmail.com>

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: Damian Nolan <damiannolan@gmail.com>
  • Loading branch information
3 people committed Apr 29, 2024
1 parent 038b244 commit 34164ef
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
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`.

### 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),
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]",
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
}

0 comments on commit 34164ef

Please sign in to comment.