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: cosmwasm migrate contract #1121

Merged
merged 4 commits into from
May 10, 2024
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
22 changes: 22 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,28 @@ func (tn *ChainNode) ExecuteContract(ctx context.Context, keyName string, contra
return txResp, nil
}

// MigrateContract performs contract migration
func (tn *ChainNode) MigrateContract(ctx context.Context, keyName string, contractAddress string, codeID string, message string, extraExecTxArgs ...string) (res *types.TxResponse, err error) {
cmd := []string{"wasm", "migrate", contractAddress, codeID, message}
cmd = append(cmd, extraExecTxArgs...)

txHash, err := tn.ExecTx(ctx, keyName, cmd...)
if err != nil {
return &types.TxResponse{}, err
}

txResp, err := tn.GetTransaction(tn.CliContext(), txHash)
if err != nil {
return &types.TxResponse{}, fmt.Errorf("failed to get transaction %s: %w", txHash, err)
}

if txResp.Code != 0 {
return txResp, fmt.Errorf("error in transaction (code: %d): %s", txResp.Code, txResp.RawLog)
}

return txResp, nil
}

// QueryContract performs a smart query, taking in a query struct and returning a error with the response struct populated.
func (tn *ChainNode) QueryContract(ctx context.Context, contractAddress string, queryMsg any, response any) error {
var query []byte
Expand Down
5 changes: 5 additions & 0 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ func (c *CosmosChain) ExecuteContract(ctx context.Context, keyName string, contr
return c.getFullNode().ExecuteContract(ctx, keyName, contractAddress, message, extraExecTxArgs...)
}

// MigrateContract performs contract migration
func (c *CosmosChain) MigrateContract(ctx context.Context, keyName string, contractAddress string, codeID string, message string, extraExecTxArgs ...string) (res *types.TxResponse, err error) {
return c.getFullNode().MigrateContract(ctx, keyName, contractAddress, codeID, message, extraExecTxArgs...)
}

// QueryContract performs a smart query, taking in a query struct and returning a error with the response struct populated.
func (c *CosmosChain) QueryContract(ctx context.Context, contractAddress string, query any, response any) error {
return c.getFullNode().QueryContract(ctx, contractAddress, query, response)
Expand Down
Loading