Skip to content

Commit

Permalink
Merge pull request #1934 from chipshort/co/fix-instantiate-2-prop
Browse files Browse the repository at this point in the history
Fix instantiate2 proposal cli command
  • Loading branch information
chipshort authored Jul 17, 2024
2 parents 1ff8188 + fae5fc2 commit dd21e64
Showing 1 changed file with 47 additions and 23 deletions.
70 changes: 47 additions & 23 deletions x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"bytes"
"encoding/hex"
"fmt"
"net/url"
"strconv"
Expand Down Expand Up @@ -75,12 +76,12 @@ func ProposalStoreCodeCmd() *cobra.Command {
return errors.New("authority address is required")
}

src, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())
storeCodeMsg, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())
if err != nil {
return err
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&src}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&storeCodeMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
if err != nil {
return err
}
Expand Down Expand Up @@ -165,12 +166,12 @@ func ProposalInstantiateContractCmd() *cobra.Command {
return errors.New("authority address is required")
}

src, err := parseInstantiateArgs(args[0], args[1], clientCtx.Keyring, authority, cmd.Flags())
instantiateMsg, err := parseInstantiateArgs(args[0], args[1], clientCtx.Keyring, authority, cmd.Flags())
if err != nil {
return err
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{src}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{instantiateMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
if err != nil {
return err
}
Expand All @@ -190,16 +191,25 @@ func ProposalInstantiateContractCmd() *cobra.Command {
}

func ProposalInstantiateContract2Cmd() *cobra.Command {
decoder := newArgDecoder(hex.DecodeString)
cmd := &cobra.Command{
Use: "instantiate-contract-2 [code_id_int64] [json_encoded_init_args] --authority [address] --label [text] --title [text] --summary [text] --admin [address,optional] --amount [coins,optional]",
Use: "instantiate-contract-2 [code_id_int64] [json_encoded_init_args] [salt] --authority [address] --label [text] --title [text] " +
"--summary [text] --admin [address,optional] --amount [coins,optional] --fix-msg [bool,optional]",
Short: "Submit an instantiate wasm contract proposal with predictable address",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, proposalTitle, summary, deposit, expedite, err := getProposalInfo(cmd)
if err != nil {
return err
}

salt, err := decoder.DecodeString(args[2])
if err != nil {
return fmt.Errorf("salt: %w", err)
}
fixMsg, err := cmd.Flags().GetBool(flagFixMsg)
if err != nil {
return fmt.Errorf("fix msg: %w", err)
}
authority, err := cmd.Flags().GetString(flagAuthority)
if err != nil {
return fmt.Errorf("authority: %s", err)
Expand All @@ -209,12 +219,22 @@ func ProposalInstantiateContract2Cmd() *cobra.Command {
return errors.New("authority address is required")
}

src, err := parseInstantiateArgs(args[0], args[1], clientCtx.Keyring, authority, cmd.Flags())
data, err := parseInstantiateArgs(args[0], args[1], clientCtx.Keyring, authority, cmd.Flags())
if err != nil {
return err
}
instantiateMsg := &types.MsgInstantiateContract2{
Sender: data.Sender,
Admin: data.Admin,
CodeID: data.CodeID,
Label: data.Label,
Msg: data.Msg,
Funds: data.Funds,
Salt: salt,
FixMsg: fixMsg,
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{src}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{instantiateMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
if err != nil {
return err
}
Expand All @@ -228,6 +248,8 @@ func ProposalInstantiateContract2Cmd() *cobra.Command {
cmd.Flags().String(flagLabel, "", "A human-readable name for this contract 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")
decoder.RegisterFlags(cmd.PersistentFlags(), "salt")

// proposal flags
addCommonProposalFlags(cmd)
Expand Down Expand Up @@ -255,7 +277,8 @@ func ProposalStoreAndInstantiateContractCmd() *cobra.Command {
return errors.New("authority address is required")
}

src, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())
// Variable storeCodeMsg is not really used. But this allows us to reuse parseStoreCodeArgs.
storeCodeMsg, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())
if err != nil {
return err
}
Expand All @@ -265,7 +288,7 @@ func ProposalStoreAndInstantiateContractCmd() *cobra.Command {
return err
}

source, builder, codeHash, err := parseVerificationFlags(src.WASMByteCode, cmd.Flags())
source, builder, codeHash, err := parseVerificationFlags(storeCodeMsg.WASMByteCode, cmd.Flags())
if err != nil {
return err
}
Expand Down Expand Up @@ -319,10 +342,10 @@ func ProposalStoreAndInstantiateContractCmd() *cobra.Command {
}
}

msg := types.MsgStoreAndInstantiateContract{
storeAndInstantiateMsg := types.MsgStoreAndInstantiateContract{
Authority: authority,
WASMByteCode: src.WASMByteCode,
InstantiatePermission: src.InstantiatePermission,
WASMByteCode: storeCodeMsg.WASMByteCode,
InstantiatePermission: storeCodeMsg.InstantiatePermission,
UnpinCode: unpinCode,
Source: source,
Builder: builder,
Expand All @@ -332,11 +355,11 @@ func ProposalStoreAndInstantiateContractCmd() *cobra.Command {
Msg: []byte(args[1]),
Funds: amount,
}
if err = msg.ValidateBasic(); err != nil {
if err = storeAndInstantiateMsg.ValidateBasic(); err != nil {
return err
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&msg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&storeAndInstantiateMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
if err != nil {
return err
}
Expand Down Expand Up @@ -380,12 +403,12 @@ func ProposalMigrateContractCmd() *cobra.Command {
return errors.New("authority address is required")
}

src, err := parseMigrateContractArgs(args, authority)
migrateMsg, err := parseMigrateContractArgs(args, authority)
if err != nil {
return err
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&src}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&migrateMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
if err != nil {
return err
}
Expand Down Expand Up @@ -519,12 +542,12 @@ func ProposalUpdateContractAdminCmd() *cobra.Command {
return errors.New("authority address is required")
}

src, err := parseUpdateContractAdminArgs(args, authority)
upgradeAdminMsg, err := parseUpdateContractAdminArgs(args, authority)
if err != nil {
return err
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&src}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&upgradeAdminMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
if err != nil {
return err
}
Expand Down Expand Up @@ -747,7 +770,7 @@ func ProposalUpdateInstantiateConfigCmd() *cobra.Command {
Long: strings.TrimSpace(
fmt.Sprintf(`Submit an update instantiate config proposal for multiple code ids.
Example:
Example:
$ %s tx gov submit-proposal update-instantiate-config 1:nobody 2:everybody 3:%s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm,%s1vx8knpllrj7n963p9ttd80w47kpacrhuts497x
`, version.AppName, bech32Prefix, bech32Prefix)),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -939,15 +962,16 @@ func ProposalStoreAndMigrateContractCmd() *cobra.Command {
return errors.New("authority address is required")
}

src, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())
// Variable storeCodeMsg is not really used. But this allows us to reuse parseStoreCodeArgs.
storeCodeMsg, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())
if err != nil {
return err
}

msg := types.MsgStoreAndMigrateContract{
Authority: authority,
WASMByteCode: src.WASMByteCode,
InstantiatePermission: src.InstantiatePermission,
WASMByteCode: storeCodeMsg.WASMByteCode,
InstantiatePermission: storeCodeMsg.InstantiatePermission,
Msg: []byte(args[2]),
Contract: args[1],
}
Expand Down

0 comments on commit dd21e64

Please sign in to comment.