Updated with PR comments
This commit is contained in:
@@ -2,7 +2,6 @@ package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/CosmWasm/wasmd/x/wasm/internal/types"
|
||||
@@ -13,7 +12,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// MigrateContractCmd will migrate a contract to a new code version
|
||||
@@ -52,12 +50,12 @@ func MigrateContractCmd(cdc *codec.Codec) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
// UpdateContractAdminCmd sets or clears an admin for a contract
|
||||
// UpdateContractAdminCmd sets an new admin for a contract
|
||||
func UpdateContractAdminCmd(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "set-contract-admin [contract_addr_bech32] [new_admin_addr_bech32]",
|
||||
Short: "Set new admin for a contract. Can be empty to prevent further migrations",
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
Short: "Set new admin for a contract",
|
||||
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))
|
||||
@@ -67,18 +65,9 @@ func UpdateContractAdminCmd(cdc *codec.Codec) *cobra.Command {
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(err, "contract")
|
||||
}
|
||||
var newAdmin sdk.AccAddress
|
||||
if len(args) > 1 && len(args[1]) != 0 {
|
||||
newAdmin, err = sdk.AccAddressFromBech32(args[1])
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(err, "new admin")
|
||||
}
|
||||
} else {
|
||||
// safety net to not accidentally clear an admin
|
||||
clearAdmin := viper.GetBool(flagNoAdmin)
|
||||
if !clearAdmin {
|
||||
return errors.New("new admin address required or no admin flag")
|
||||
}
|
||||
newAdmin, err := sdk.AccAddressFromBech32(args[1])
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(err, "new admin")
|
||||
}
|
||||
|
||||
msg := types.MsgUpdateAdmin{
|
||||
@@ -89,6 +78,31 @@ func UpdateContractAdminCmd(cdc *codec.Codec) *cobra.Command {
|
||||
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
||||
},
|
||||
}
|
||||
cmd.Flags().Bool(flagNoAdmin, false, "Remove admin which disables future admin updates and migrations")
|
||||
return cmd
|
||||
}
|
||||
|
||||
// ClearContractAdminCmd clears an admin for a contract
|
||||
func ClearContractAdminCmd(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "clear-contract-admin [contract_addr_bech32]",
|
||||
Short: "Clears admin for a contract to prevent further migrations",
|
||||
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")
|
||||
}
|
||||
|
||||
msg := types.MsgClearAdmin{
|
||||
Sender: cliCtx.GetFromAddress(),
|
||||
Contract: contractAddr,
|
||||
}
|
||||
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
ExecuteContractCmd(cdc),
|
||||
MigrateContractCmd(cdc),
|
||||
UpdateContractAdminCmd(cdc),
|
||||
ClearContractAdminCmd(cdc),
|
||||
)...)
|
||||
return txCmd
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ func (msg MsgMigrateContract) GetSigners() []sdk.AccAddress {
|
||||
|
||||
type MsgUpdateAdmin struct {
|
||||
Sender sdk.AccAddress `json:"sender" yaml:"sender"`
|
||||
NewAdmin sdk.AccAddress `json:"new_admin,omitempty" yaml:"new_admin"`
|
||||
NewAdmin sdk.AccAddress `json:"new_admin" yaml:"new_admin"`
|
||||
Contract sdk.AccAddress `json:"contract" yaml:"contract"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user