Skip to content

Commit

Permalink
fix missing label in custom/wasm/client (#254)
Browse files Browse the repository at this point in the history
Co-authored-by: nghuyenthevinh2000 <[email protected]>
  • Loading branch information
fragwuerdig and nghuyenthevinh2000 committed Jun 10, 2023
1 parent e504e2b commit 4207f83
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
6 changes: 2 additions & 4 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions custom/wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
flagAdmin = "admin"
flagNoAdmin = "no-admin"
flagFixMsg = "fix-msg"
flagLabel = "label"
)

// GetTxCmd returns the transaction commands for this module
Expand Down Expand Up @@ -103,7 +104,7 @@ func ExecuteContractCmd() *cobra.Command {
// InstantiateContractCmd will instantiate a contract from previously uploaded code.
func InstantiateContractCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "instantiate [code_id_int64] [json_encoded_init_args] --admin [address,optional] --amount [coins,optional] ",
Use: "instantiate [code_id_int64] [json_encoded_init_args] --label [text] --admin [address,optional] --amount [coins,optional] ",
Short: "Instantiate a wasm contract",
Long: fmt.Sprintf(`Creates a new instance of an uploaded wasm code with the given 'constructor' message.
Each contract instance has a unique address assigned.
Expand Down Expand Up @@ -150,6 +151,7 @@ $ %s tx wasm instantiate 1 '{"foo":"bar"}' --admin="$(%s keys show mykey -a)" \
}

cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
cmd.Flags().String(flagLabel, "", "Human readable contract label in lists")
cmd.Flags().String(flagAdmin, "", "Address of an admin")
cmd.Flags().Bool(flagNoAdmin, false, "You must set this explicitly if you don't want an admin")
flags.AddTxFlagsToCmd(cmd)
Expand All @@ -160,7 +162,7 @@ $ %s tx wasm instantiate 1 '{"foo":"bar"}' --admin="$(%s keys show mykey -a)" \
func InstantiateContract2Cmd() *cobra.Command {
decoder := newArgDecoder(hex.DecodeString)
cmd := &cobra.Command{
Use: "instantiate2 [code_id_int64] [json_encoded_init_args] [salt] --admin [address,optional] --amount [coins,optional] " +
Use: "instantiate2 [code_id_int64] [json_encoded_init_args] [salt] --label [text] --admin [address,optional] --amount [coins,optional] " +
"--fix-msg [bool,optional]",
Short: "Instantiate a wasm contract with predictable address",
Long: fmt.Sprintf(`Creates a new instance of an uploaded wasm code with the given 'constructor' message.
Expand Down Expand Up @@ -197,6 +199,7 @@ $ %s tx wasm instantiate2 1 '{"foo":"bar"}' $(echo -n "testing" | xxd -ps) --adm
CodeID: data.CodeID,
Msg: data.Msg,
Funds: data.Funds,
Label: data.Label,
Salt: salt,
FixMsg: fixMsg,
}
Expand Down Expand Up @@ -228,6 +231,7 @@ $ %s tx wasm instantiate2 1 '{"foo":"bar"}' $(echo -n "testing" | xxd -ps) --adm
}

cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
cmd.Flags().String(flagLabel, "", "Human readable contract label in lists")
cmd.Flags().String(flagAdmin, "", "Address of an admin")
cmd.Flags().Bool(flagNoAdmin, false, "You must set this explicitly if you don't want an admin")
cmd.Flags().Bool(flagFixMsg, false, "An optional flag to include the json_encoded_init_args for the predictable address generation mode")
Expand Down Expand Up @@ -270,6 +274,13 @@ func parseInstantiateArgs(rawCodeID, initMsg string, sender sdk.AccAddress, flag
if err != nil {
return nil, fmt.Errorf("amount: %s", err)
}
label, err := flags.GetString(flagLabel)
if err != nil {
return nil, fmt.Errorf("label: %s", err)
}
if label == "" {
return nil, errors.New("label is required on all contracts")
}
adminStr, err := flags.GetString(flagAdmin)
if err != nil {
return nil, fmt.Errorf("admin: %s", err)
Expand All @@ -294,6 +305,7 @@ func parseInstantiateArgs(rawCodeID, initMsg string, sender sdk.AccAddress, flag
Funds: amount,
Msg: []byte(initMsg),
Admin: adminStr,
Label: label,
}
return &msg, nil
}
Expand Down
2 changes: 2 additions & 0 deletions custom/wasm/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type storeCodeReq struct {

type instantiateContractReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
Label string `json:"label" yaml:"label"`
Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
Admin string `json:"admin,omitempty" yaml:"admin"`
Msg []byte `json:"msg" yaml:"msg"`
Expand Down Expand Up @@ -103,6 +104,7 @@ func instantiateContractHandlerFn(cliCtx client.Context) http.HandlerFunc {
msg := types.MsgInstantiateContract{
Sender: req.BaseReq.From,
CodeID: codeID,
Label: req.Label,
Funds: req.Deposit,
Msg: req.Msg,
Admin: req.Admin,
Expand Down
5 changes: 1 addition & 4 deletions custom/wasm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import (
customrest "github.com/classic-terra/core/v2/custom/wasm/client/rest"
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
)
var _ module.AppModuleBasic = AppModuleBasic{}

// AppModuleBasic defines the basic application module used by the wasm module.
type AppModuleBasic struct {
Expand Down

0 comments on commit 4207f83

Please sign in to comment.