From d8dc128ff789f0f4bc47f081ecd7c6e329bb9e32 Mon Sep 17 00:00:00 2001 From: BiPhan4 Date: Mon, 29 Apr 2024 16:06:31 -0400 Subject: [PATCH 1/3] migrate contract --- chain/cosmos/chain_node.go | 22 ++++++++++++++++++++++ chain/cosmos/cosmos_chain.go | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/chain/cosmos/chain_node.go b/chain/cosmos/chain_node.go index a289dd8f7..484e82dd3 100644 --- a/chain/cosmos/chain_node.go +++ b/chain/cosmos/chain_node.go @@ -1022,6 +1022,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, message string, extraExecTxArgs ...string) (res *types.TxResponse, err error) { + cmd := []string{"wasm", "migrate", contractAddress, 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 diff --git a/chain/cosmos/cosmos_chain.go b/chain/cosmos/cosmos_chain.go index 22e76c8dc..b8143259c 100644 --- a/chain/cosmos/cosmos_chain.go +++ b/chain/cosmos/cosmos_chain.go @@ -551,6 +551,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, message string, extraExecTxArgs ...string) (res *types.TxResponse, err error) { + return c.getFullNode().MigrateContract(ctx, keyName, contractAddress, 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) From 2aedf77763aa1039e78779d569b876101b576c6f Mon Sep 17 00:00:00 2001 From: BiPhan4 Date: Tue, 30 Apr 2024 12:54:31 -0400 Subject: [PATCH 2/3] consume codeID --- chain/cosmos/chain_node.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chain/cosmos/chain_node.go b/chain/cosmos/chain_node.go index 484e82dd3..163120e98 100644 --- a/chain/cosmos/chain_node.go +++ b/chain/cosmos/chain_node.go @@ -1023,8 +1023,8 @@ func (tn *ChainNode) ExecuteContract(ctx context.Context, keyName string, contra } // MigrateContract performs contract migration -func (tn *ChainNode) MigrateContract(ctx context.Context, keyName string, contractAddress string, message string, extraExecTxArgs ...string) (res *types.TxResponse, err error) { - cmd := []string{"wasm", "migrate", contractAddress, message} +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...) From 798101f2cacd300511d5fd544b9cbc8ebf8e519f Mon Sep 17 00:00:00 2001 From: BiPhan4 Date: Tue, 30 Apr 2024 13:18:26 -0400 Subject: [PATCH 3/3] fix --- chain/cosmos/cosmos_chain.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chain/cosmos/cosmos_chain.go b/chain/cosmos/cosmos_chain.go index b8143259c..330d403a9 100644 --- a/chain/cosmos/cosmos_chain.go +++ b/chain/cosmos/cosmos_chain.go @@ -552,8 +552,8 @@ func (c *CosmosChain) ExecuteContract(ctx context.Context, keyName string, contr } // MigrateContract performs contract migration -func (c *CosmosChain) MigrateContract(ctx context.Context, keyName string, contractAddress string, message string, extraExecTxArgs ...string) (res *types.TxResponse, err error) { - return c.getFullNode().MigrateContract(ctx, keyName, contractAddress, message, extraExecTxArgs...) +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.