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

Add wasm gov proposals to cli #183

Merged
merged 7 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]

### Features
* (wasmd) [\#178](https://github.com/CosmWasm/wasmd/issues/178) Add cli support for wasm gov proposals
* (wasmd) [\#163](https://github.com/CosmWasm/wasmd/issues/163) Control who can instantiate code
* (wasmd) [\#164](https://github.com/CosmWasm/wasmd/issues/164) Control who can upload code
* (wasmd) [\#173](https://github.com/CosmWasm/wasmd/issues/173) Gov proposal types and handler
Expand Down
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"os"
"path/filepath"

"github.com/spf13/viper"

"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
Expand All @@ -30,6 +29,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
"github.com/spf13/viper"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
Expand All @@ -56,7 +56,7 @@ var (
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(paramsclient.ProposalHandler, distr.ProposalHandler, upgradeclient.ProposalHandler),
gov.NewAppModuleBasic(append(wasmclient.ProposalHandlers, paramsclient.ProposalHandler, distr.ProposalHandler, upgradeclient.ProposalHandler)...),
params.AppModuleBasic{},
wasm.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand Down
9 changes: 7 additions & 2 deletions cmd/wasmcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
"github.com/cosmos/cosmos-sdk/x/bank"
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"

"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down Expand Up @@ -127,12 +127,17 @@ func txCmd(cdc *amino.Codec) *cobra.Command {
// add modules' tx commands
app.ModuleBasics.AddTxCommands(txCmd, cdc)

//wasmGovCmds := []*cobra.Command{}
alpe marked this conversation as resolved.
Show resolved Hide resolved

// remove auth and bank commands as they're mounted under the root tx command
var cmdsToRemove []*cobra.Command

for _, cmd := range txCmd.Commands() {
if cmd.Use == auth.ModuleName || cmd.Use == bank.ModuleName {
cmdsToRemove = append(cmdsToRemove, cmd)
continue
}
if cmd.Use == gov.ModuleName {
//cmd.AddCommand(wasmGovCmds...)
}
}

Expand Down
295 changes: 295 additions & 0 deletions x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
package cli

import (
"bufio"

"github.com/CosmWasm/wasmd/x/wasm/internal/types"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func ProposalStoreCodeCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "wasm-store [wasm file] --source [source] --builder [builder] --title [text] --description [text] --creator [address]",
Short: "Submit a wasm binary proposal",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

src, err := parseStoreCodeArgs(args, cliCtx)
if err != nil {
return err
}
if len(viper.GetString(flagCreator)) == 0 {
return errors.New("creator address is required")
}
creator, err := sdk.AccAddressFromBech32(viper.GetString(flagCreator))
if err != nil {
return errors.Wrap(err, "creator")
}
content := types.StoreCodeProposal{
alpe marked this conversation as resolved.
Show resolved Hide resolved
WasmProposal: types.WasmProposal{
Title: viper.GetString(cli.FlagTitle),
Description: viper.GetString(cli.FlagDescription),
},
Creator: creator,
WASMByteCode: src.WASMByteCode,
Source: src.Source,
Builder: src.Builder,
InstantiatePermission: src.InstantiatePermission,
}

deposit, err := sdk.ParseCoins(viper.GetString(cli.FlagDeposit))
if err != nil {
return err
}

msg := govtypes.NewMsgSubmitProposal(content, deposit, cliCtx.GetFromAddress())
if err = msg.ValidateBasic(); err != nil {
return err
}

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}

cmd.Flags().String(flagSource, "", "A valid URI reference to the contract's source code, optional")
cmd.Flags().String(flagBuilder, "", "A valid docker tag for the build system, optional")
cmd.Flags().String(flagCreator, "", "The address that is stored as code creator")
cmd.Flags().String(flagInstantiateByEverybody, "", "Everybody can instantiate a contract from the code, optional")
cmd.Flags().String(flagInstantiateByAddress, "", "Only this address can instantiate a contract instance from the code, optional")

// proposal flags
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "Description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal")
cmd.Flags().String(cli.FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)")
// type values must match the "ProposalHandler" "routes" in cli
cmd.Flags().String(flagProposalType, "", "Type of proposal, types: store-code/instantiate/migrate/update-admin/clear-admin/text/parameter_change/software_upgrade")
return cmd
}

func ProposalInstantiateContractCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "instantiate-contract [code_id_int64] [json_encoded_init_args] --label [text] --admin [address] --title [text] --description [text] --creator [address]",
Short: "Submit an instantiate wasm contract proposal",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

src, err := parseInstantiateArgs(args, cliCtx)
if err != nil {
return err
}
if len(viper.GetString(flagCreator)) == 0 {
return errors.New("creator address is required")
}
creator, err := sdk.AccAddressFromBech32(viper.GetString(flagCreator))
if err != nil {
return errors.Wrap(err, "creator")
}
content := types.InstantiateContractProposal{
WasmProposal: types.WasmProposal{
Title: viper.GetString(cli.FlagTitle),
Description: viper.GetString(cli.FlagDescription),
},
Creator: creator,
Admin: src.Admin,
Code: src.Code,
Label: src.Label,
InitMsg: src.InitMsg,
InitFunds: src.InitFunds,
}

deposit, err := sdk.ParseCoins(viper.GetString(cli.FlagDeposit))
if err != nil {
return err
}

msg := govtypes.NewMsgSubmitProposal(content, deposit, cliCtx.GetFromAddress())
if err = msg.ValidateBasic(); err != nil {
return err
}

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
cmd.Flags().String(flagLabel, "", "A human-readable name for this contract in lists")
cmd.Flags().String(flagAdmin, "", "Address of an admin")
cmd.Flags().String(flagCreator, "", "The address that is stored as code creator")

// proposal flags
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "Description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal")
cmd.Flags().String(cli.FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)")
// type values must match the "ProposalHandler" "routes" in cli
cmd.Flags().String(flagProposalType, "", "Type of proposal, types: store-code/instantiate/migrate/update-admin/clear-admin/text/parameter_change/software_upgrade")
return cmd
}

func ProposalMigrateContractCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "migrate-contract [contract_addr_bech32] [new_code_id_int64] [json_encoded_migration_args]",
Short: "Submit a migrate wasm contract to a new code version proposal",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

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

if len(viper.GetString(flagSender)) == 0 {
return errors.New("sender address is required")
}
sender, err := sdk.AccAddressFromBech32(viper.GetString(flagSender))
if err != nil {
return errors.Wrap(err, "sender")
}

content := types.MigrateContractProposal{
WasmProposal: types.WasmProposal{
Title: viper.GetString(cli.FlagTitle),
Description: viper.GetString(cli.FlagDescription),
},
Contract: src.Contract,
Code: src.Code,
MigrateMsg: src.MigrateMsg,
Sender: sender,
}

deposit, err := sdk.ParseCoins(viper.GetString(cli.FlagDeposit))
if err != nil {
return err
}

msg := govtypes.NewMsgSubmitProposal(content, deposit, cliCtx.GetFromAddress())
if err = msg.ValidateBasic(); err != nil {
return err
}

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
cmd.Flags().String(flagSender, "", "The address that is passed as sender to the contract")

// proposal flags
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "Description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal")
cmd.Flags().String(cli.FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)")
// type values must match the "ProposalHandler" "routes" in cli
cmd.Flags().String(flagProposalType, "", "Type of proposal, types: store-code/instantiate/migrate/update-admin/clear-admin/text/parameter_change/software_upgrade")
return cmd
}

func ProposalUpdateContractAdminCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "set-contract-admin [contract_addr_bech32] [new_admin_addr_bech32]",
Short: "Submit a new admin for a contract proposal",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

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

content := types.UpdateAdminProposal{
WasmProposal: types.WasmProposal{
Title: viper.GetString(cli.FlagTitle),
Description: viper.GetString(cli.FlagDescription),
},
Contract: src.Contract,
NewAdmin: src.NewAdmin,
}

deposit, err := sdk.ParseCoins(viper.GetString(cli.FlagDeposit))
if err != nil {
return err
}

msg := govtypes.NewMsgSubmitProposal(content, deposit, cliCtx.GetFromAddress())
if err = msg.ValidateBasic(); err != nil {
return err
}

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
// proposal flags
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "Description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal")
cmd.Flags().String(cli.FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)")
// type values must match the "ProposalHandler" "routes" in cli
cmd.Flags().String(flagProposalType, "", "Type of proposal, types: store-code/instantiate/migrate/update-admin/clear-admin/text/parameter_change/software_upgrade")
return cmd
}

func ProposalClearContractAdminCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "clear-contract-admin [contract_addr_bech32]",
Short: "Submit a clear admin for a contract to prevent further migrations proposal",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

contractAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return sdkerrors.Wrap(err, "contract")
}

content := types.ClearAdminProposal{
WasmProposal: types.WasmProposal{
Title: viper.GetString(cli.FlagTitle),
Description: viper.GetString(cli.FlagDescription),
},
Contract: contractAddr,
}

deposit, err := sdk.ParseCoins(viper.GetString(cli.FlagDeposit))
if err != nil {
return err
}

msg := govtypes.NewMsgSubmitProposal(content, deposit, cliCtx.GetFromAddress())
if err = msg.ValidateBasic(); err != nil {
return err
}

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
// proposal flags
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "Description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal")
cmd.Flags().String(cli.FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)")
// type values must match the "ProposalHandler" "routes" in cli
cmd.Flags().String(flagProposalType, "", "Type of proposal, types: store-code/instantiate/migrate/update-admin/clear-admin/text/parameter_change/software_upgrade")
return cmd
}
Loading