diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index fa47709174..5f4c0e67dd 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -23,6 +23,7 @@ Write the changes made after branching from cosmos-sdk v0.42.1. * (global) [\#97](https://github.com/line/lbm-sdk/pull/97) Add codespace to query error * (config) [\#114](https://github.com/line/lbm-sdk/pull/114) Add idle-timeout to rest server and rpc server config * (x/wasm) [\#127](https://github.com/line/lbm-sdk/pull/127) Add wasm with Staragate migration completed. +* (x/wasm) [\#151](https://github.com/line/lbm-sdk/pull/151) Add contract access control. ### IMPROVEMENTS diff --git a/client/utils_test.go b/client/utils_test.go index fd66e2c759..23d93bd8f1 100644 --- a/client/utils_test.go +++ b/client/utils_test.go @@ -1,11 +1,14 @@ package client_test import ( + "strconv" "testing" + "github.com/spf13/pflag" "github.com/stretchr/testify/require" "github.com/line/lbm-sdk/v2/client" + "github.com/line/lbm-sdk/v2/client/flags" ) func TestPaginate(t *testing.T) { @@ -75,3 +78,61 @@ func TestPaginate(t *testing.T) { }) } } + +func TestReadPageRequest(t *testing.T) { + + testCases := []struct { + name string + pageKey string + offset, limit, page int + countTotal bool + ok bool + }{ + { + "use page ok", + "page key", + 0, 100, 10, + true, + true, + }, + { + "use offset ok", + "page key", + 10, 100, 0, + true, + true, + }, + { + "page and offset cannot be used together", + "page key", + 100, 100, 10, + true, + false, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + flagSet := pflag.NewFlagSet("test flag set", pflag.ContinueOnError) + flagSet.String(flags.FlagPageKey, "default page key", "page key") + flagSet.Uint64(flags.FlagOffset, 0, "offset") + flagSet.Uint64(flags.FlagLimit, 0, "limit") + flagSet.Uint64(flags.FlagPage, 0, "page") + flagSet.Bool(flags.FlagCountTotal, false, "count total") + + err := flagSet.Set(flags.FlagPageKey, tc.pageKey) + err = flagSet.Set(flags.FlagOffset, strconv.Itoa(tc.offset)) + err = flagSet.Set(flags.FlagLimit, strconv.Itoa(tc.limit)) + err = flagSet.Set(flags.FlagPage, strconv.Itoa(tc.page)) + err = flagSet.Set(flags.FlagCountTotal, strconv.FormatBool(tc.countTotal)) + + pr, err := client.ReadPageRequest(flagSet) + if tc.ok { + require.NoError(t, err) + require.NotNil(t, pr) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/wasm/alias.go b/x/wasm/alias.go index e69a144172..4decb29ef8 100644 --- a/x/wasm/alias.go +++ b/x/wasm/alias.go @@ -99,42 +99,44 @@ var ( ) type ( - ProposalType = types.ProposalType - GenesisState = types.GenesisState - Code = types.Code - Contract = types.Contract - MsgStoreCode = types.MsgStoreCode - MsgStoreCodeResponse = types.MsgStoreCodeResponse - MsgInstantiateContract = types.MsgInstantiateContract - MsgInstantiateContractResponse = types.MsgInstantiateContractResponse - MsgExecuteContract = types.MsgExecuteContract - MsgExecuteContractResponse = types.MsgExecuteContractResponse - MsgMigrateContract = types.MsgMigrateContract - MsgMigrateContractResponse = types.MsgMigrateContractResponse - MsgUpdateAdmin = types.MsgUpdateAdmin - MsgUpdateAdminResponse = types.MsgUpdateAdminResponse - MsgClearAdmin = types.MsgClearAdmin - MsgWasmIBCCall = types.MsgIBCSend - MsgClearAdminResponse = types.MsgClearAdminResponse - MsgServer = types.MsgServer - Model = types.Model - CodeInfo = types.CodeInfo - ContractInfo = types.ContractInfo - CreatedAt = types.AbsoluteTxPosition - Config = types.WasmConfig - ContractInfoWithAddress = types.ContractInfoWithAddress - CodeInfoResponse = types.CodeInfoResponse - MessageHandler = keeper.DefaultMessageHandler - BankEncoder = keeper.BankEncoder - CustomEncoder = keeper.CustomEncoder - StakingEncoder = keeper.StakingEncoder - WasmEncoder = keeper.WasmEncoder - MessageEncoders = keeper.MessageEncoders - Keeper = keeper.Keeper - QueryHandler = keeper.QueryHandler - CustomQuerier = keeper.CustomQuerier - QueryPlugins = keeper.QueryPlugins - Option = keeper.Option + ProposalType = types.ProposalType + GenesisState = types.GenesisState + Code = types.Code + Contract = types.Contract + MsgStoreCode = types.MsgStoreCode + MsgStoreCodeResponse = types.MsgStoreCodeResponse + MsgInstantiateContract = types.MsgInstantiateContract + MsgInstantiateContractResponse = types.MsgInstantiateContractResponse + MsgStoreCodeAndInstantiateContract = types.MsgStoreCodeAndInstantiateContract + MsgStoreCodeAndInstantiateContractResponse = types.MsgStoreCodeAndInstantiateContractResponse + MsgExecuteContract = types.MsgExecuteContract + MsgExecuteContractResponse = types.MsgExecuteContractResponse + MsgMigrateContract = types.MsgMigrateContract + MsgMigrateContractResponse = types.MsgMigrateContractResponse + MsgUpdateAdmin = types.MsgUpdateAdmin + MsgUpdateAdminResponse = types.MsgUpdateAdminResponse + MsgClearAdmin = types.MsgClearAdmin + MsgWasmIBCCall = types.MsgIBCSend + MsgClearAdminResponse = types.MsgClearAdminResponse + MsgServer = types.MsgServer + Model = types.Model + CodeInfo = types.CodeInfo + ContractInfo = types.ContractInfo + CreatedAt = types.AbsoluteTxPosition + Config = types.WasmConfig + ContractInfoWithAddress = types.ContractInfoWithAddress + CodeInfoResponse = types.CodeInfoResponse + MessageHandler = keeper.DefaultMessageHandler + BankEncoder = keeper.BankEncoder + CustomEncoder = keeper.CustomEncoder + StakingEncoder = keeper.StakingEncoder + WasmEncoder = keeper.WasmEncoder + MessageEncoders = keeper.MessageEncoders + Keeper = keeper.Keeper + QueryHandler = keeper.QueryHandler + CustomQuerier = keeper.CustomQuerier + QueryPlugins = keeper.QueryPlugins + Option = keeper.Option EncodeHandler = types.EncodeHandler EncodeQuerier = types.EncodeQuerier diff --git a/x/wasm/client/cli/new_tx.go b/x/wasm/client/cli/new_tx.go index cabfc4d904..9af82d24ee 100644 --- a/x/wasm/client/cli/new_tx.go +++ b/x/wasm/client/cli/new_tx.go @@ -113,3 +113,35 @@ func ClearContractAdminCmd() *cobra.Command { flags.AddTxFlagsToCmd(cmd) return cmd } + +// UpdateContractStatusCmd clears an admin for a contract +func UpdateContractStatusCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-contract-status [contract_addr_bech32] [status(Active|Inactive)]", + Short: "Clears admin for a contract to prevent further migrations", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + status := types.ContractStatusUnspecified + if err := (&status).UnmarshalText([]byte(args[1])); err != nil { + return err + } + + msg := types.MsgUpdateContractStatus{ + Sender: clientCtx.GetFromAddress().String(), + Contract: args[0], + Status: status, + } + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} diff --git a/x/wasm/client/cli/tx.go b/x/wasm/client/cli/tx.go index cf1e4b7465..fe4d69b7b3 100644 --- a/x/wasm/client/cli/tx.go +++ b/x/wasm/client/cli/tx.go @@ -41,10 +41,12 @@ func GetTxCmd() *cobra.Command { txCmd.AddCommand( StoreCodeCmd(), InstantiateContractCmd(), + StoreCodeAndInstantiateContractCmd(), ExecuteContractCmd(), MigrateContractCmd(), UpdateContractAdminCmd(), ClearContractAdminCmd(), + UpdateContractStatusCmd(), ) return txCmd } @@ -213,6 +215,128 @@ func parseInstantiateArgs(rawCodeID, initMsg string, sender sdk.AccAddress, flag return msg, nil } +// StoreCodeAndInstantiatecontractcmd will upload code and instantiate a contract using it +func StoreCodeAndInstantiateContractCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "store-instantiate [wasm file] [json_encoded_init_args] --source [source] --builder [builder] --label [text] --admin [address,optional] --amount [coins,optional]", + Short: "Upload a wasm binary and instantiate a wasm contract from the code", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + msg, err := parseStoreCodeAndInstantiateContractArgs(args[0], args[1], clientCtx.GetFromAddress(), cmd.Flags()) + if err != nil { + return err + } + if err = msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &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(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") + 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") + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +func parseStoreCodeAndInstantiateContractArgs(file string, initMsg string, sender sdk.AccAddress, flags *flag.FlagSet) (types.MsgStoreCodeAndInstantiateContract, error) { + wasm, err := ioutil.ReadFile(file) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, err + } + + // gzip the wasm file + if wasmUtils.IsWasm(wasm) { + wasm, err = wasmUtils.GzipIt(wasm) + + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, err + } + } else if !wasmUtils.IsGzip(wasm) { + return types.MsgStoreCodeAndInstantiateContract{}, fmt.Errorf("invalid input file. Use wasm binary or gzip") + } + + var perm *types.AccessConfig + onlyAddrStr, err := flags.GetString(flagInstantiateByAddress) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, fmt.Errorf("instantiate by address: %s", err) + } + if onlyAddrStr != "" { + allowedAddr, err := sdk.AccAddressFromBech32(onlyAddrStr) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, sdkerrors.Wrap(err, flagInstantiateByAddress) + } + x := types.AccessTypeOnlyAddress.With(allowedAddr) + perm = &x + } else { + everybodyStr, err := flags.GetString(flagInstantiateByEverybody) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, fmt.Errorf("instantiate by everybody: %s", err) + } + if everybodyStr != "" { + ok, err := strconv.ParseBool(everybodyStr) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, fmt.Errorf("boolean value expected for instantiate by everybody: %s", err) + } + if ok { + perm = &types.AllowEverybody + } + } + } + + // build and sign the transaction, then broadcast to Tendermint + source, err := flags.GetString(flagSource) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, fmt.Errorf("source: %s", err) + } + builder, err := flags.GetString(flagBuilder) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, fmt.Errorf("builder: %s", err) + } + + amountStr, err := flags.GetString(flagAmount) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, fmt.Errorf("amount: %s", err) + } + amount, err := sdk.ParseCoinsNormalized(amountStr) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, fmt.Errorf("amount: %s", err) + } + label, err := flags.GetString(flagLabel) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, fmt.Errorf("label: %s", err) + } + if label == "" { + return types.MsgStoreCodeAndInstantiateContract{}, errors.New("label is required on all contracts") + } + adminStr, err := flags.GetString(flagAdmin) + if err != nil { + return types.MsgStoreCodeAndInstantiateContract{}, fmt.Errorf("admin: %s", err) + } + + msg := types.MsgStoreCodeAndInstantiateContract{ + Sender: sender.String(), + WASMByteCode: wasm, + Source: source, + Builder: builder, + InstantiatePermission: perm, + Label: label, + Funds: amount, + InitMsg: []byte(initMsg), + Admin: adminStr, + } + return msg, nil +} + // ExecuteContractCmd will instantiate a contract from previously uploaded code. func ExecuteContractCmd() *cobra.Command { cmd := &cobra.Command{ diff --git a/x/wasm/client/rest/tx.go b/x/wasm/client/rest/tx.go index b053db58af..23f5ee18f0 100644 --- a/x/wasm/client/rest/tx.go +++ b/x/wasm/client/rest/tx.go @@ -16,6 +16,7 @@ import ( func registerTxRoutes(cliCtx client.Context, r *mux.Router) { r.HandleFunc("/wasm/code", storeCodeHandlerFn(cliCtx)).Methods("POST") r.HandleFunc("/wasm/code/{codeId}", instantiateContractHandlerFn(cliCtx)).Methods("POST") + r.HandleFunc("/wasm/codeinit", storeCodeAndInstantiateContractHandlerFn(cliCtx)).Methods("POST") r.HandleFunc("/wasm/contract/{contractAddr}", executeContractHandlerFn(cliCtx)).Methods("POST") } @@ -32,6 +33,15 @@ type instantiateContractReq struct { InitMsg []byte `json:"init_msg" yaml:"init_msg"` } +type storeCodeAndInstantiateContractReq struct { + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + WasmBytes []byte `json:"wasm_bytes"` + Label string `json:"label" yaml:"label"` + Deposit sdk.Coins `json:"deposit" yaml:"deposit"` + Admin string `json:"admin,omitempty" yaml:"admin"` + InitMsg []byte `json:"init_msg" yaml:"init_msg"` +} + type executeContractReq struct { BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` ExecMsg []byte `json:"exec_msg" yaml:"exec_msg"` @@ -118,6 +128,52 @@ func instantiateContractHandlerFn(cliCtx client.Context) http.HandlerFunc { } } +func storeCodeAndInstantiateContractHandlerFn(cliCtx client.Context) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req storeCodeAndInstantiateContractReq + if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) { + return + } + + req.BaseReq = req.BaseReq.Sanitize() + if !req.BaseReq.ValidateBasic(w) { + return + } + + var err error + wasm := req.WasmBytes + + // gzip the wasm file + if wasmUtils.IsWasm(wasm) { + wasm, err = wasmUtils.GzipIt(wasm) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + } else if !wasmUtils.IsGzip(wasm) { + rest.WriteErrorResponse(w, http.StatusBadRequest, "Invalid input file, use wasm binary or zip") + return + } + + // build and sign the transaction, then broadcast to Tendermint + msg := types.MsgStoreCodeAndInstantiateContract{ + Sender: req.BaseReq.From, + WASMByteCode: wasm, + Label: req.Label, + Funds: req.Deposit, + InitMsg: req.InitMsg, + Admin: req.Admin, + } + + if err := msg.ValidateBasic(); err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, &msg) + } +} + func executeContractHandlerFn(cliCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req executeContractReq diff --git a/x/wasm/common_test.go b/x/wasm/common_test.go index 818f9f7baf..ad0586b7a1 100644 --- a/x/wasm/common_test.go +++ b/x/wasm/common_test.go @@ -31,3 +31,17 @@ func parseInitResponse(t *testing.T, data []byte) string { require.NoError(t, err) return addr } + +// ensures this returns a valid codeID and bech32 address and returns it +func parseStoreAndInitResponse(t *testing.T, data []byte) (uint64, string) { + var res MsgStoreCodeAndInstantiateContractResponse + require.NoError(t, res.Unmarshal(data)) + require.NotEmpty(t, res.CodeID) + require.NotEmpty(t, res.Address) + addr := res.Address + codeID := res.CodeID + // ensure this is a valid sdk address + _, err := sdk.AccAddressFromBech32(addr) + require.NoError(t, err) + return codeID, addr +} diff --git a/x/wasm/handler.go b/x/wasm/handler.go index 26d1566835..ff95a6060f 100644 --- a/x/wasm/handler.go +++ b/x/wasm/handler.go @@ -28,6 +28,8 @@ func NewHandler(k *Keeper) sdk.Handler { res, err = msgServer.StoreCode(sdk.WrapSDKContext(ctx), msg) case *MsgInstantiateContract: res, err = msgServer.InstantiateContract(sdk.WrapSDKContext(ctx), msg) + case *MsgStoreCodeAndInstantiateContract: + res, err = msgServer.StoreCodeAndInstantiateContract(sdk.WrapSDKContext(ctx), msg) case *MsgExecuteContract: res, err = msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), msg) case *MsgMigrateContract: @@ -36,6 +38,8 @@ func NewHandler(k *Keeper) sdk.Handler { res, err = msgServer.UpdateAdmin(sdk.WrapSDKContext(ctx), msg) case *MsgClearAdmin: res, err = msgServer.ClearAdmin(sdk.WrapSDKContext(ctx), msg) + case *types.MsgUpdateContractStatus: + res, err = msgServer.UpdateContractStatus(sdk.WrapSDKContext(ctx), msg) default: errMsg := fmt.Sprintf("unrecognized wasm message type: %T", msg) return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) diff --git a/x/wasm/internal/keeper/authz_policy.go b/x/wasm/internal/keeper/authz_policy.go index 30dd0ec36b..66b2517cfb 100644 --- a/x/wasm/internal/keeper/authz_policy.go +++ b/x/wasm/internal/keeper/authz_policy.go @@ -9,6 +9,7 @@ type AuthorizationPolicy interface { CanCreateCode(c types.AccessConfig, creator sdk.AccAddress) bool CanInstantiateContract(c types.AccessConfig, actor sdk.AccAddress) bool CanModifyContract(admin, actor sdk.AccAddress) bool + CanUpdateContractStatus(c types.AccessConfig, actor sdk.AccAddress) bool } type DefaultAuthorizationPolicy struct { @@ -26,17 +27,30 @@ func (p DefaultAuthorizationPolicy) CanModifyContract(admin, actor sdk.AccAddres return admin != nil && admin.Equals(actor) } +func (p DefaultAuthorizationPolicy) CanUpdateContractStatus(config types.AccessConfig, actor sdk.AccAddress) bool { + return config.Allowed(actor) +} + +// GovAuthorizationPolicy is for the gov handler(proposal_handler.go) authorities type GovAuthorizationPolicy struct { } func (p GovAuthorizationPolicy) CanCreateCode(types.AccessConfig, sdk.AccAddress) bool { + // The gov handler can create code regardless of the current access config return true } func (p GovAuthorizationPolicy) CanInstantiateContract(types.AccessConfig, sdk.AccAddress) bool { + // The gov handler can instantiate contract regardless of the code access config return true } func (p GovAuthorizationPolicy) CanModifyContract(sdk.AccAddress, sdk.AccAddress) bool { + // The gov handler can migrate contract regardless of the contract admin + return true +} + +func (p GovAuthorizationPolicy) CanUpdateContractStatus(types.AccessConfig, sdk.AccAddress) bool { + // The gov handler can update contract status regardless of the current access config return true } diff --git a/x/wasm/internal/keeper/genesis_test.go b/x/wasm/internal/keeper/genesis_test.go index ec4553ab32..74022254bd 100644 --- a/x/wasm/internal/keeper/genesis_test.go +++ b/x/wasm/internal/keeper/genesis_test.go @@ -444,6 +444,9 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) { "permission": "Everybody" }, "instantiate_default_permission": "Everybody", + "contract_status_access": { + "permission": "Nobody" + }, "max_wasm_code_size": 500000, "gas_multiplier": 100, "instance_cost": 40000, @@ -472,7 +475,8 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) { "code_id": "1", "creator": "link1p0yx9c9q4xsnedlcn24gqfry5dcu6e9xkhv9aj", "admin": "link1qyqszqgpqyqszqgpqyqszqgpqyqszqgp8apuk5", - "label": "ȀĴnZV芢毤" + "label": "ȀĴnZV芢毤", + "status": "Active" } } ], @@ -537,6 +541,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) { Admin: adminAddr, Label: "ȀĴnZV芢毤", Created: &types.AbsoluteTxPosition{BlockHeight: 0, TxIndex: 0}, + Status: wasmTypes.ContractStatusActive, } assert.Equal(t, expContractInfo, *gotContractInfo) diff --git a/x/wasm/internal/keeper/keeper.go b/x/wasm/internal/keeper/keeper.go index fb8dceff68..eb2b9df4c5 100644 --- a/x/wasm/internal/keeper/keeper.go +++ b/x/wasm/internal/keeper/keeper.go @@ -127,6 +127,12 @@ func (k Keeper) getInstantiateAccessConfig(ctx sdk.Context) types.AccessType { return a } +func (k Keeper) getContractStatusAccessConfig(ctx sdk.Context) types.AccessConfig { + var a types.AccessConfig + k.paramSpace.Get(ctx, types.ParamStoreKeyContractStatusAccess, &a) + return a +} + func (k Keeper) getMaxWasmCodeSize(ctx sdk.Context) uint64 { var a uint64 k.paramSpace.Get(ctx, types.ParamStoreKeyMaxWasmCodeSize, &a) @@ -290,7 +296,7 @@ func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A // persist instance first createdAt := types.NewAbsoluteTxPosition(ctx) - contractInfo := types.NewContractInfo(codeID, creator, admin, label, createdAt) + contractInfo := types.NewContractInfo(codeID, creator, admin, label, createdAt, types.ContractStatusActive) // check for IBC flag report, err := k.wasmer.AnalyzeCode(codeInfo.CodeHash) @@ -325,6 +331,9 @@ func (k Keeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller if err != nil { return nil, err } + if contractInfo.Status != types.ContractStatusActive { + return nil, sdkerrors.Wrap(types.ErrInvalid, "inactive contract") + } if !k.IsPinnedCode(ctx, contractInfo.CodeID) { ctx.GasMeter().ConsumeGas(k.getInstanceCost(ctx), "Loading CosmWasm module: execute") @@ -379,6 +388,9 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller if contractInfo == nil { return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "unknown contract") } + if contractInfo.Status != types.ContractStatusActive { + return nil, sdkerrors.Wrap(types.ErrInvalid, "inactive contract") + } if !authZ.CanModifyContract(contractInfo.AdminAddr(), caller) { return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not migrate") } @@ -539,11 +551,35 @@ func (k Keeper) ClearContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddre return k.setContractAdmin(ctx, contractAddress, caller, nil, k.authZPolicy) } +// UpdateContractStatus sets a new status of the contract on the ContractInfo. +func (k Keeper) UpdateContractStatus(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, status types.ContractStatus) error { + return k.updateContractStatus(ctx, contractAddress, caller, status, k.authZPolicy) +} + +func (k Keeper) updateContractStatus(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, status types.ContractStatus, authZ AuthorizationPolicy) error { + if !authZ.CanUpdateContractStatus(k.getContractStatusAccessConfig(ctx), caller) { + return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not update contract status") + } + + contractInfo := k.GetContractInfo(ctx, contractAddress) + if contractInfo == nil { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "unknown contract") + } + if contractInfo.Status != status { + contractInfo.Status = status + k.storeContractInfo(ctx, contractAddress, contractInfo) + } + return nil +} + func (k Keeper) setContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress, authZ AuthorizationPolicy) error { contractInfo := k.GetContractInfo(ctx, contractAddress) if contractInfo == nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "unknown contract") } + if contractInfo.Status != types.ContractStatusActive { + return sdkerrors.Wrap(types.ErrInvalid, "inactive contract") + } if !authZ.CanModifyContract(contractInfo.AdminAddr(), caller) { return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not modify contract") } diff --git a/x/wasm/internal/keeper/keeper_test.go b/x/wasm/internal/keeper/keeper_test.go index 65e8307cb4..681cf22355 100644 --- a/x/wasm/internal/keeper/keeper_test.go +++ b/x/wasm/internal/keeper/keeper_test.go @@ -10,13 +10,12 @@ import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - banktypes "github.com/line/lbm-sdk/v2/x/bank/types" - "github.com/line/lbm-sdk/v2/x/wasm/internal/keeper/wasmtesting" - stypes "github.com/line/lbm-sdk/v2/store/types" sdk "github.com/line/lbm-sdk/v2/types" sdkerrors "github.com/line/lbm-sdk/v2/types/errors" authtypes "github.com/line/lbm-sdk/v2/x/auth/types" + banktypes "github.com/line/lbm-sdk/v2/x/bank/types" + "github.com/line/lbm-sdk/v2/x/wasm/internal/keeper/wasmtesting" "github.com/line/lbm-sdk/v2/x/wasm/internal/types" tmproto "github.com/line/ostracon/proto/ostracon/types" "github.com/stretchr/testify/assert" @@ -85,6 +84,7 @@ func TestCreateStoresInstantiatePermission(t *testing.T) { keeper.setParams(ctx, types.Params{ CodeUploadAccess: types.AllowEverybody, InstantiateDefaultPermission: spec.srcPermission, + ContractStatusAccess: types.DefaultContractStatusAccess, MaxWasmCodeSize: types.DefaultMaxWasmCodeSize, GasMultiplier: types.DefaultGasMultiplier, InstanceCost: types.DefaultInstanceCost, @@ -287,7 +287,7 @@ func TestInstantiate(t *testing.T) { gasAfter := ctx.GasMeter().GasConsumed() if types.EnableGasVerification { - require.Equal(t, uint64(0x13324), gasAfter-gasBefore) + require.Equal(t, uint64(0x13360), gasAfter-gasBefore) } // ensure it is stored properly @@ -296,6 +296,7 @@ func TestInstantiate(t *testing.T) { assert.Equal(t, creator.String(), info.Creator) assert.Equal(t, codeID, info.CodeID) assert.Equal(t, "demo contract 1", info.Label) + assert.Equal(t, types.ContractStatusActive, info.Status) exp := []types.ContractCodeHistoryEntry{{ Operation: types.ContractCodeHistoryOperationTypeInit, @@ -520,7 +521,7 @@ func TestExecute(t *testing.T) { // make sure gas is properly deducted from ctx gasAfter := ctx.GasMeter().GasConsumed() if types.EnableGasVerification { - require.Equal(t, uint64(0x1405a), gasAfter-gasBefore) + require.Equal(t, uint64(0x14060), gasAfter-gasBefore) } // ensure bob now exists and got both payments released bobAcct = accKeeper.GetAccount(ctx, bob) @@ -765,6 +766,43 @@ func TestExecuteWithStorageLoop(t *testing.T) { require.True(t, false, "We must panic before this line") } +func TestExecuteInactiveContract(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) + accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.WasmKeeper, keepers.BankKeeper + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + topUp := sdk.NewCoins(sdk.NewInt64Coin("denom", 5000)) + creator := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, deposit.Add(deposit...)) + fred := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, topUp) + + wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm") + require.NoError(t, err) + + contractID, err := keeper.Create(ctx, creator, wasmCode, "", "", nil) + require.NoError(t, err) + + _, _, bob := keyPubAddr() + initMsg := HackatomExampleInitMsg{ + Verifier: fred, + Beneficiary: bob, + } + initMsgBz, err := json.Marshal(initMsg) + require.NoError(t, err) + + addr, _, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 3", deposit) + require.NoError(t, err) + require.Equal(t, "link18vd8fpwxzck93qlwghaj6arh4p7c5n89fvcmzu", addr.String()) + + // execute inactive contract + params := keeper.GetParams(ctx) + params.ContractStatusAccess = types.AccessTypeOnlyAddress.With(creator) + keeper.setParams(ctx, params) + err = keeper.UpdateContractStatus(ctx, addr, creator, types.ContractStatusInactive) + require.NoError(t, err) + _, err = keeper.Execute(ctx, addr, fred, []byte(`{"release":{}}`), topUp) + require.True(t, types.ErrInvalid.Is(err), "expected %v but got %+v", types.ErrInvalid, err) +} + func TestMigrate(t *testing.T) { ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.WasmKeeper, keepers.BankKeeper @@ -1050,6 +1088,41 @@ func TestMigrateWithDispatchedMessage(t *testing.T) { assert.Equal(t, deposit, balance) } +func TestMigrateInactiveContract(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) + accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.WasmKeeper, keepers.BankKeeper + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + topUp := sdk.NewCoins(sdk.NewInt64Coin("denom", 5000)) + creator := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, deposit.Add(deposit...)) + fred := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, topUp) + + originalCodeID := StoreHackatomExampleContract(t, ctx, keepers).CodeID + newCodeID := StoreHackatomExampleContract(t, ctx, keepers).CodeID + require.NotEqual(t, originalCodeID, newCodeID) + + anyAddr := RandomAccountAddress(t) + newVerifierAddr := RandomAccountAddress(t) + initMsgBz := HackatomExampleInitMsg{ + Verifier: fred, + Beneficiary: anyAddr, + }.GetBytes(t) + migMsg := struct { + Verifier sdk.AccAddress `json:"verifier"` + }{Verifier: newVerifierAddr} + migMsgBz, err := json.Marshal(migMsg) + + contractAddr, _, err := keeper.Instantiate(ctx, originalCodeID, creator, creator, initMsgBz, "demo contract", nil) + + params := keeper.GetParams(ctx) + params.ContractStatusAccess = types.AccessTypeOnlyAddress.With(creator) + keeper.setParams(ctx, params) + err = keeper.UpdateContractStatus(ctx, contractAddr, creator, types.ContractStatusInactive) + require.NoError(t, err) + _, err = keeper.Migrate(ctx, contractAddr, creator, newCodeID, migMsgBz) + require.True(t, types.ErrInvalid.Is(err), "expected %v but got %+v", types.ErrInvalid, err) +} + type sudoMsg struct { // This is a tongue-in-check demo command. This is not the intended purpose of Sudo. // Here we show that some priviledged Go module can make a call that should never be exposed @@ -1217,6 +1290,42 @@ func TestUpdateContractAdmin(t *testing.T) { } } +func TestUpdateContractAdminInactiveContract(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) + accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.WasmKeeper, keepers.BankKeeper + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + topUp := sdk.NewCoins(sdk.NewInt64Coin("denom", 5000)) + creator := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, deposit.Add(deposit...)) + fred := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, topUp) + + wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm") + require.NoError(t, err) + + originalContractID, err := keeper.Create(ctx, creator, wasmCode, "", "", nil) + require.NoError(t, err) + + _, _, anyAddr := keyPubAddr() + initMsg := HackatomExampleInitMsg{ + Verifier: fred, + Beneficiary: anyAddr, + } + initMsgBz, err := json.Marshal(initMsg) + require.NoError(t, err) + + addr, _, err := keeper.Instantiate(ctx, originalContractID, creator, fred, initMsgBz, "demo contract", nil) + require.NoError(t, err) + + params := keeper.GetParams(ctx) + params.ContractStatusAccess = types.AccessTypeOnlyAddress.With(creator) + keeper.setParams(ctx, params) + err = keeper.UpdateContractStatus(ctx, addr, creator, types.ContractStatusInactive) + require.NoError(t, err) + + err = keeper.UpdateContractAdmin(ctx, addr, fred, anyAddr) + require.True(t, types.ErrInvalid.Is(err), "expected %v but got %+v", types.ErrInvalid, err) +} + func TestClearContractAdmin(t *testing.T) { ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.WasmKeeper, keepers.BankKeeper @@ -1282,3 +1391,145 @@ func TestClearContractAdmin(t *testing.T) { }) } } + +func TestClearContractAdminInactiveContract(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) + accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.WasmKeeper, keepers.BankKeeper + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + topUp := sdk.NewCoins(sdk.NewInt64Coin("denom", 5000)) + creator := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, deposit.Add(deposit...)) + fred := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, topUp) + + wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm") + require.NoError(t, err) + + originalContractID, err := keeper.Create(ctx, creator, wasmCode, "", "", nil) + require.NoError(t, err) + + _, _, anyAddr := keyPubAddr() + initMsg := HackatomExampleInitMsg{ + Verifier: fred, + Beneficiary: anyAddr, + } + initMsgBz, err := json.Marshal(initMsg) + require.NoError(t, err) + + addr, _, err := keeper.Instantiate(ctx, originalContractID, creator, fred, initMsgBz, "demo contract", nil) + require.NoError(t, err) + + params := keeper.GetParams(ctx) + params.ContractStatusAccess = types.AccessTypeOnlyAddress.With(creator) + keeper.setParams(ctx, params) + err = keeper.UpdateContractStatus(ctx, addr, creator, types.ContractStatusInactive) + require.NoError(t, err) + + err = keeper.ClearContractAdmin(ctx, addr, fred) + require.True(t, types.ErrInvalid.Is(err), "expected %v but got %+v", types.ErrInvalid, err) +} + +func TestUpdateContractStatus(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) + accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.WasmKeeper, keepers.BankKeeper + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + topUp := sdk.NewCoins(sdk.NewInt64Coin("denom", 5000)) + creator := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, deposit.Add(deposit...)) + fred := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, topUp) + + wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm") + require.NoError(t, err) + + originalContractID, err := keeper.Create(ctx, creator, wasmCode, "", "", nil) + require.NoError(t, err) + + _, _, anyAddr := keyPubAddr() + initMsg := HackatomExampleInitMsg{ + Verifier: fred, + Beneficiary: anyAddr, + } + initMsgBz, err := json.Marshal(initMsg) + require.NoError(t, err) + + type spec struct { + instAdmin sdk.AccAddress + newStatus types.ContractStatus + overrideContractAddr sdk.AccAddress + caller sdk.AccAddress + expErr *sdkerrors.Error + } + + // Default Nobody can update the status + s := spec{ + instAdmin: fred, + newStatus: types.ContractStatusInactive, + caller: fred, + expErr: sdkerrors.ErrUnauthorized, + } + runUpdateStatusSpec(t, "ContractStatusAccess nobody", keeper, ctx, originalContractID, creator, s, initMsgBz) + + // Everybody can update the status + params := keeper.GetParams(ctx) + params.ContractStatusAccess = types.AllowEverybody + keeper.setParams(ctx, params) + specs := map[string]spec{ + "admin can update the status": { + instAdmin: fred, + newStatus: types.ContractStatusInactive, + caller: fred, + }, + "any can update the status": { + instAdmin: fred, + newStatus: types.ContractStatusInactive, + caller: anyAddr, + }, + } + for msg, spec := range specs { + runUpdateStatusSpec(t, msg, keeper, ctx, originalContractID, creator, spec, initMsgBz) + } + + // Only authorized account can update the status + params = keeper.GetParams(ctx) + params.ContractStatusAccess = types.AccessTypeOnlyAddress.With(fred) + keeper.setParams(ctx, params) + specs = map[string]spec{ + "authorized account update the status": { + instAdmin: fred, + newStatus: types.ContractStatusInactive, + caller: fred, + }, + "any cannot update the status": { + instAdmin: fred, + newStatus: types.ContractStatusInactive, + caller: anyAddr, + expErr: sdkerrors.ErrUnauthorized, + }, + } + for msg, spec := range specs { + runUpdateStatusSpec(t, msg, keeper, ctx, originalContractID, creator, spec, initMsgBz) + } +} + +func runUpdateStatusSpec(t *testing.T, msg string, keeper *Keeper, ctx sdk.Context, originalContractID uint64, creator sdk.AccAddress, spec struct { + instAdmin sdk.AccAddress + newStatus types.ContractStatus + overrideContractAddr sdk.AccAddress + caller sdk.AccAddress + expErr *sdkerrors.Error +}, initMsgBz []byte) { + + t.Run(msg, func(t *testing.T) { + addr, _, err := keeper.Instantiate(ctx, originalContractID, creator, spec.instAdmin, initMsgBz, "demo contract", nil) + require.NoError(t, err) + if spec.overrideContractAddr != nil { + addr = spec.overrideContractAddr + } + err = keeper.UpdateContractStatus(ctx, addr, spec.caller, types.ContractStatusInactive) + require.True(t, spec.expErr.Is(err), "expected %v but got %+v", spec.expErr, err) + if spec.expErr != nil { + return + } + cInfo := keeper.GetContractInfo(ctx, addr) + assert.Equal(t, spec.newStatus, cInfo.Status) + }) +} diff --git a/x/wasm/internal/keeper/msg_server.go b/x/wasm/internal/keeper/msg_server.go index 836b3b377e..be6fc4d8aa 100644 --- a/x/wasm/internal/keeper/msg_server.go +++ b/x/wasm/internal/keeper/msg_server.go @@ -75,6 +75,51 @@ func (m msgServer) InstantiateContract(goCtx context.Context, msg *types.MsgInst }, nil } +func (m msgServer) StoreCodeAndInstantiateContract(goCtx context.Context, msg *types.MsgStoreCodeAndInstantiateContract) (*types.MsgStoreCodeAndInstantiateContractResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return nil, sdkerrors.Wrap(err, "sender") + } + codeID, err := m.keeper.Create(ctx, senderAddr, msg.WASMByteCode, msg.Source, msg.Builder, msg.InstantiatePermission) + if err != nil { + return nil, err + } + + ctx.EventManager().EmitEvent(sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeySigner, msg.Sender), + sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)), + )) + + var adminAddr sdk.AccAddress + if msg.Admin != "" { + if adminAddr, err = sdk.AccAddressFromBech32(msg.Admin); err != nil { + return nil, sdkerrors.Wrap(err, "admin") + } + } + + contractAddr, data, err := m.keeper.Instantiate(ctx, codeID, senderAddr, adminAddr, msg.InitMsg, msg.Label, msg.Funds) + if err != nil { + return nil, err + } + + ctx.EventManager().EmitEvent(sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeySigner, msg.Sender), + sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)), + sdk.NewAttribute(types.AttributeKeyContract, contractAddr.String()), + )) + + return &types.MsgStoreCodeAndInstantiateContractResponse{ + CodeID: codeID, + Address: contractAddr.String(), + Data: data, + }, nil +} + func (m msgServer) ExecuteContract(goCtx context.Context, msg *types.MsgExecuteContract) (*types.MsgExecuteContractResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) @@ -185,3 +230,37 @@ func (m msgServer) ClearAdmin(goCtx context.Context, msg *types.MsgClearAdmin) ( return &types.MsgClearAdminResponse{}, nil } + +// UpdateContractStatus handles MsgUpdateContractStatus +// CONTRACT: msg.validateBasic() must be called before calling this +func (m msgServer) UpdateContractStatus(goCtx context.Context, msg *types.MsgUpdateContractStatus) (*types.MsgUpdateContractStatusResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return nil, sdkerrors.Wrap(err, "sender") + } + contractAddr, err := sdk.AccAddressFromBech32(msg.Contract) + if err != nil { + return nil, sdkerrors.Wrap(err, "contract") + } + + if err = m.keeper.UpdateContractStatus(ctx, contractAddr, senderAddr, msg.Status); err != nil { + return nil, err + } + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeySigner, msg.Sender), + sdk.NewAttribute(types.AttributeKeyContract, msg.Contract), + ), + sdk.NewEvent( + types.EventTypeUpdateContractStatus, + sdk.NewAttribute(types.AttributeKeyContract, msg.Contract), + sdk.NewAttribute(types.AttributeKeyContractStatus, msg.Status.String()), + ), + }) + + return &types.MsgUpdateContractStatusResponse{}, nil +} diff --git a/x/wasm/internal/keeper/proposal_handler.go b/x/wasm/internal/keeper/proposal_handler.go index 862b37c78b..f6dbd5a7a8 100644 --- a/x/wasm/internal/keeper/proposal_handler.go +++ b/x/wasm/internal/keeper/proposal_handler.go @@ -19,6 +19,7 @@ type governing interface { setContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress, authZ AuthorizationPolicy) error PinCode(ctx sdk.Context, codeID uint64) error UnpinCode(ctx sdk.Context, codeID uint64) error + updateContractStatus(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, status types.ContractStatus, authZ AuthorizationPolicy) error } // NewWasmProposalHandler creates a new governance Handler for wasm proposals @@ -49,6 +50,8 @@ func NewWasmProposalHandler(k governing, enabledProposalTypes []types.ProposalTy return handlePinCodesProposal(ctx, k, *c) case *types.UnpinCodesProposal: return handleUnpinCodesProposal(ctx, k, *c) + case *types.UpdateContractStatusProposal: + return handleUpdateContractStatusProposal(ctx, k, *c) default: return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized wasm proposal content type: %T", c) } @@ -233,3 +236,24 @@ func handleUnpinCodesProposal(ctx sdk.Context, k governing, p types.UnpinCodesPr return nil } + +func handleUpdateContractStatusProposal(ctx sdk.Context, k governing, p types.UpdateContractStatusProposal) error { + if err := p.ValidateBasic(); err != nil { + return err + } + contractAddr, err := sdk.AccAddressFromBech32(p.Contract) + if err != nil { + return sdkerrors.Wrap(err, "contract") + } + + if err = k.updateContractStatus(ctx, contractAddr, nil, p.Status, GovAuthorizationPolicy{}); err != nil { + return err + } + + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeUpdateContractStatus, + sdk.NewAttribute(types.AttributeKeyContract, p.Contract), + sdk.NewAttribute(types.AttributeKeyContractStatus, p.Status.String()), + )) + return nil +} diff --git a/x/wasm/internal/keeper/proposal_integration_test.go b/x/wasm/internal/keeper/proposal_integration_test.go index 867d4c362a..9ff2e72ee8 100644 --- a/x/wasm/internal/keeper/proposal_integration_test.go +++ b/x/wasm/internal/keeper/proposal_integration_test.go @@ -9,11 +9,10 @@ import ( "testing" wasmvm "github.com/CosmWasm/wasmvm" - "github.com/line/lbm-sdk/v2/x/wasm/internal/keeper/wasmtesting" - sdk "github.com/line/lbm-sdk/v2/types" govtypes "github.com/line/lbm-sdk/v2/x/gov/types" "github.com/line/lbm-sdk/v2/x/params/types/proposal" + "github.com/line/lbm-sdk/v2/x/wasm/internal/keeper/wasmtesting" "github.com/line/lbm-sdk/v2/x/wasm/internal/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -25,6 +24,7 @@ func TestStoreCodeProposal(t *testing.T) { wasmKeeper.setParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, + ContractStatusAccess: types.DefaultContractStatusAccess, MaxWasmCodeSize: types.DefaultMaxWasmCodeSize, GasMultiplier: types.DefaultGasMultiplier, InstanceCost: types.DefaultInstanceCost, @@ -69,6 +69,7 @@ func TestInstantiateProposal(t *testing.T) { wasmKeeper.setParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, + ContractStatusAccess: types.DefaultContractStatusAccess, MaxWasmCodeSize: types.DefaultMaxWasmCodeSize, GasMultiplier: types.DefaultGasMultiplier, InstanceCost: types.DefaultInstanceCost, @@ -128,6 +129,7 @@ func TestMigrateProposal(t *testing.T) { wasmKeeper.setParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, + ContractStatusAccess: types.DefaultContractStatusAccess, MaxWasmCodeSize: types.DefaultMaxWasmCodeSize, GasMultiplier: types.DefaultGasMultiplier, InstanceCost: types.DefaultInstanceCost, @@ -263,6 +265,7 @@ func TestAdminProposals(t *testing.T) { wasmKeeper.setParams(ctx, types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, + ContractStatusAccess: types.DefaultContractStatusAccess, MaxWasmCodeSize: types.DefaultMaxWasmCodeSize, GasMultiplier: types.DefaultGasMultiplier, InstanceCost: types.DefaultInstanceCost, @@ -536,3 +539,69 @@ func TestUnpinCodesProposal(t *testing.T) { }) } } + +func TestUpdateContractStatusProposals(t *testing.T) { + var contractAddr = contractAddress(1, 1) + wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm") + require.NoError(t, err) + + specs := map[string]struct { + state types.ContractInfo + srcProposal govtypes.Content + expStatus types.ContractStatus + }{ + "update with different Status": { + state: types.ContractInfoFixture(), + srcProposal: &types.UpdateContractStatusProposal{ + Title: "Foo", + Description: "Bar", + Contract: contractAddr.String(), + Status: types.ContractStatusInactive, + }, + expStatus: types.ContractStatusInactive, + }, + "update with old Status": { + state: types.ContractInfoFixture(), + srcProposal: &types.UpdateContractStatusProposal{ + Title: "Foo", + Description: "Bar", + Contract: contractAddr.String(), + Status: types.ContractStatusActive, + }, + expStatus: types.ContractStatusActive, + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, "staking", nil, nil) + govKeeper, wasmKeeper := keepers.GovKeeper, keepers.WasmKeeper + wasmKeeper.setParams(ctx, types.Params{ + CodeUploadAccess: types.AllowNobody, + InstantiateDefaultPermission: types.AccessTypeNobody, + ContractStatusAccess: types.AllowNobody, + MaxWasmCodeSize: types.DefaultMaxWasmCodeSize, + GasMultiplier: types.DefaultGasMultiplier, + InstanceCost: types.DefaultInstanceCost, + CompileCost: types.DefaultCompileCost, + }) + + codeInfoFixture := types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)) + require.NoError(t, wasmKeeper.importCode(ctx, 1, codeInfoFixture, wasmCode)) + + require.NoError(t, wasmKeeper.importContract(ctx, contractAddr, &spec.state, []types.Model{})) + // when stored + storedProposal, err := govKeeper.SubmitProposal(ctx, spec.srcProposal) + require.NoError(t, err) + + // and execute proposal + handler := govKeeper.Router().GetRoute(storedProposal.ProposalRoute()) + err = handler(ctx, storedProposal.GetContent()) + require.NoError(t, err) + + // then + cInfo := wasmKeeper.GetContractInfo(ctx, contractAddr) + require.NotNil(t, cInfo) + assert.Equal(t, spec.expStatus, cInfo.Status) + }) + } +} diff --git a/x/wasm/internal/keeper/recurse_test.go b/x/wasm/internal/keeper/recurse_test.go index f12d1e156c..82ca94692f 100644 --- a/x/wasm/internal/keeper/recurse_test.go +++ b/x/wasm/internal/keeper/recurse_test.go @@ -58,9 +58,9 @@ func initRecurseContract(t *testing.T) (contract sdk.AccAddress, creator sdk.Acc func TestGasCostOnQuery(t *testing.T) { const ( - GasNoWork uint64 = 50_149 + GasNoWork uint64 = 50_155 // Note: about 100 SDK gas (10k wasmer gas) for each round of sha256 - GasWork50 uint64 = 55_818 // this is a little shy of 50k gas - to keep an eye on the limit + GasWork50 uint64 = 55_824 // this is a little shy of 50k gas - to keep an eye on the limit GasReturnUnhashed uint64 = 287 GasReturnHashed uint64 = 262 @@ -225,7 +225,7 @@ func TestLimitRecursiveQueryGas(t *testing.T) { const ( // Note: about 100 SDK gas (10k wasmer gas) for each round of sha256 - GasWork2k uint64 = 278_872 // = InstanceCost + x // we have 6x gas used in cpu than in the instance + GasWork2k uint64 = 278_878 // = InstanceCost + x // we have 6x gas used in cpu than in the instance // This is overhead for calling into a sub-contract GasReturnHashed uint64 = 265 ) diff --git a/x/wasm/internal/keeper/relay_test.go b/x/wasm/internal/keeper/relay_test.go index 63b4d7bb05..dd3bce2c4f 100644 --- a/x/wasm/internal/keeper/relay_test.go +++ b/x/wasm/internal/keeper/relay_test.go @@ -67,7 +67,7 @@ func TestOnOpenChannel(t *testing.T) { } require.NoError(t, err) // verify gas consumed - const storageCosts = sdk.Gas(0x1a61) + const storageCosts = sdk.Gas(0x1a67) assert.Equal(t, spec.contractGas, ctx.GasMeter().GasConsumed()-before-storageCosts) }) } @@ -91,12 +91,12 @@ func TestOnConnectChannel(t *testing.T) { }{ "consume contract gas": { contractAddr: example.Contract, - contractGas: 10, + contractGas: 16, contractResp: &wasmvmtypes.IBCBasicResponse{}, }, "consume gas on error, ignore events + messages": { contractAddr: example.Contract, - contractGas: 20, + contractGas: 26, contractResp: &wasmvmtypes.IBCBasicResponse{ Messages: []wasmvmtypes.CosmosMsg{{Bank: &wasmvmtypes.BankMsg{}}}, Attributes: []wasmvmtypes.EventAttribute{{Key: "Foo", Value: "Bar"}}, @@ -107,14 +107,14 @@ func TestOnConnectChannel(t *testing.T) { }, "dispatch contract messages on success": { contractAddr: example.Contract, - contractGas: 30, + contractGas: 36, contractResp: &wasmvmtypes.IBCBasicResponse{ Messages: []wasmvmtypes.CosmosMsg{{Bank: &wasmvmtypes.BankMsg{}}, {Custom: json.RawMessage(`{"foo":"bar"}`)}}, }, }, "emit contract events on success": { contractAddr: example.Contract, - contractGas: 40, + contractGas: 46, contractResp: &wasmvmtypes.IBCBasicResponse{ Attributes: []wasmvmtypes.EventAttribute{{Key: "Foo", Value: "Bar"}}, }, @@ -122,7 +122,7 @@ func TestOnConnectChannel(t *testing.T) { }, "messenger errors returned, events stored": { contractAddr: example.Contract, - contractGas: 50, + contractGas: 56, contractResp: &wasmvmtypes.IBCBasicResponse{ Messages: []wasmvmtypes.CosmosMsg{{Bank: &wasmvmtypes.BankMsg{}}, {Custom: json.RawMessage(`{"foo":"bar"}`)}}, Attributes: []wasmvmtypes.EventAttribute{{Key: "Foo", Value: "Bar"}}, @@ -174,7 +174,7 @@ func TestOnConnectChannel(t *testing.T) { } require.NoError(t, err) // verify gas consumed - const storageCosts = sdk.Gas(0x1a61) + const storageCosts = sdk.Gas(0x1a67) assert.Equal(t, spec.contractGas, ctx.GasMeter().GasConsumed()-before-storageCosts) // verify msgs dispatched assert.Equal(t, spec.contractResp.Messages, *capturedMsgs) @@ -201,7 +201,7 @@ func TestOnCloseChannel(t *testing.T) { }{ "consume contract gas": { contractAddr: example.Contract, - contractGas: 10, + contractGas: 16, contractResp: &wasmvmtypes.IBCBasicResponse{}, }, "consume gas on error, ignore events + messages": { @@ -217,14 +217,14 @@ func TestOnCloseChannel(t *testing.T) { }, "dispatch contract messages on success": { contractAddr: example.Contract, - contractGas: 30, + contractGas: 36, contractResp: &wasmvmtypes.IBCBasicResponse{ Messages: []wasmvmtypes.CosmosMsg{{Bank: &wasmvmtypes.BankMsg{}}, {Custom: json.RawMessage(`{"foo":"bar"}`)}}, }, }, "emit contract events on success": { contractAddr: example.Contract, - contractGas: 40, + contractGas: 46, contractResp: &wasmvmtypes.IBCBasicResponse{ Attributes: []wasmvmtypes.EventAttribute{{Key: "Foo", Value: "Bar"}}, }, @@ -283,7 +283,7 @@ func TestOnCloseChannel(t *testing.T) { } require.NoError(t, err) // verify gas consumed - const storageCosts = sdk.Gas(0x1a61) + const storageCosts = sdk.Gas(0x1a67) assert.Equal(t, spec.contractGas, ctx.GasMeter().GasConsumed()-before-storageCosts) // verify msgs dispatched assert.Equal(t, spec.contractResp.Messages, *capturedMsgs) @@ -408,7 +408,7 @@ func TestOnRecvPacket(t *testing.T) { require.Equal(t, spec.contractResp.Acknowledgement, gotAck) // verify gas consumed - const storageCosts = sdk.Gas(0x1a61) + const storageCosts = sdk.Gas(0x1a67) assert.Equal(t, spec.contractGas, ctx.GasMeter().GasConsumed()-before-storageCosts) // verify msgs dispatched assert.Equal(t, spec.contractResp.Messages, *capturedMsgs) @@ -436,7 +436,7 @@ func TestOnAckPacket(t *testing.T) { }{ "consume contract gas": { contractAddr: example.Contract, - contractGas: 10, + contractGas: 16, contractResp: &wasmvmtypes.IBCBasicResponse{}, }, "consume gas on error, ignore events + messages": { @@ -452,14 +452,14 @@ func TestOnAckPacket(t *testing.T) { }, "dispatch contract messages on success": { contractAddr: example.Contract, - contractGas: 30, + contractGas: 36, contractResp: &wasmvmtypes.IBCBasicResponse{ Messages: []wasmvmtypes.CosmosMsg{{Bank: &wasmvmtypes.BankMsg{}}, {Custom: json.RawMessage(`{"foo":"bar"}`)}}, }, }, "emit contract events on success": { contractAddr: example.Contract, - contractGas: 40, + contractGas: 46, contractResp: &wasmvmtypes.IBCBasicResponse{ Attributes: []wasmvmtypes.EventAttribute{{Key: "Foo", Value: "Bar"}}, }, @@ -519,7 +519,7 @@ func TestOnAckPacket(t *testing.T) { } require.NoError(t, err) // verify gas consumed - const storageCosts = sdk.Gas(0x1a61) + const storageCosts = sdk.Gas(0x1a67) assert.Equal(t, spec.contractGas, ctx.GasMeter().GasConsumed()-before-storageCosts) // verify msgs dispatched assert.Equal(t, spec.contractResp.Messages, *capturedMsgs) @@ -547,7 +547,7 @@ func TestOnTimeoutPacket(t *testing.T) { }{ "consume contract gas": { contractAddr: example.Contract, - contractGas: 10, + contractGas: 22, contractResp: &wasmvmtypes.IBCBasicResponse{}, }, "consume gas on error, ignore events + messages": { @@ -563,7 +563,7 @@ func TestOnTimeoutPacket(t *testing.T) { }, "dispatch contract messages on success": { contractAddr: example.Contract, - contractGas: 30, + contractGas: 42, contractResp: &wasmvmtypes.IBCBasicResponse{ Messages: []wasmvmtypes.CosmosMsg{{Bank: &wasmvmtypes.BankMsg{}}, {Custom: json.RawMessage(`{"foo":"bar"}`)}}, }, @@ -629,7 +629,7 @@ func TestOnTimeoutPacket(t *testing.T) { } require.NoError(t, err) // verify gas consumed - const storageCosts = sdk.Gas(0x1a61) + const storageCosts = sdk.Gas(0x1a67) assert.Equal(t, spec.contractGas, ctx.GasMeter().GasConsumed()-before-storageCosts) // verify msgs dispatched assert.Equal(t, spec.contractResp.Messages, *capturedMsgs) diff --git a/x/wasm/internal/types/events.go b/x/wasm/internal/types/events.go index 2f48e5847c..b235990d9a 100644 --- a/x/wasm/internal/types/events.go +++ b/x/wasm/internal/types/events.go @@ -1,12 +1,14 @@ package types const ( - EventTypePinCode = "pin_code" - EventTypeUnpinCode = "unpin_code" + EventTypePinCode = "pin_code" + EventTypeUnpinCode = "unpin_code" + EventTypeUpdateContractStatus = "update_contract_status" ) const ( // event attributes - AttributeKeyContract = "contract_address" - AttributeKeyCodeID = "code_id" - AttributeKeyCodeIDs = "code_ids" - AttributeKeySigner = "signer" + AttributeKeyContract = "contract_address" + AttributeKeyCodeID = "code_id" + AttributeKeyCodeIDs = "code_ids" + AttributeKeySigner = "signer" + AttributeKeyContractStatus = "contract_status" ) diff --git a/x/wasm/internal/types/params.go b/x/wasm/internal/types/params.go index 52b7bf6734..9d09e3ced6 100644 --- a/x/wasm/internal/types/params.go +++ b/x/wasm/internal/types/params.go @@ -33,10 +33,12 @@ const ( var ParamStoreKeyUploadAccess = []byte("uploadAccess") var ParamStoreKeyInstantiateAccess = []byte("instantiateAccess") +var ParamStoreKeyContractStatusAccess = []byte("contractStatusAccess") var ParamStoreKeyMaxWasmCodeSize = []byte("maxWasmCodeSize") var ParamStoreKeyGasMultiplier = []byte("gasMultiplier") var ParamStoreKeyInstanceCost = []byte("instanceCost") var ParamStoreKeyCompileCost = []byte("compileCost") + var AllAccessTypes = []AccessType{ AccessTypeNobody, AccessTypeOnlyAddress, @@ -97,9 +99,10 @@ func (a AccessConfig) Equals(o AccessConfig) bool { } var ( - DefaultUploadAccess = AllowEverybody - AllowEverybody = AccessConfig{Permission: AccessTypeEverybody} - AllowNobody = AccessConfig{Permission: AccessTypeNobody} + DefaultUploadAccess = AllowEverybody + DefaultContractStatusAccess = AllowNobody + AllowEverybody = AccessConfig{Permission: AccessTypeEverybody} + AllowNobody = AccessConfig{Permission: AccessTypeNobody} ) // ParamKeyTable returns the parameter key table. @@ -113,6 +116,7 @@ func DefaultParams() Params { CodeUploadAccess: AllowEverybody, InstantiateDefaultPermission: AccessTypeEverybody, MaxWasmCodeSize: DefaultMaxWasmCodeSize, + ContractStatusAccess: DefaultContractStatusAccess, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, CompileCost: DefaultCompileCost, @@ -129,6 +133,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(ParamStoreKeyUploadAccess, &p.CodeUploadAccess, validateAccessConfig), paramtypes.NewParamSetPair(ParamStoreKeyInstantiateAccess, &p.InstantiateDefaultPermission, validateAccessType), + paramtypes.NewParamSetPair(ParamStoreKeyContractStatusAccess, &p.ContractStatusAccess, validateAccessConfig), paramtypes.NewParamSetPair(ParamStoreKeyMaxWasmCodeSize, &p.MaxWasmCodeSize, validateMaxWasmCodeSize), paramtypes.NewParamSetPair(ParamStoreKeyGasMultiplier, &p.GasMultiplier, validateGasMultiplier), paramtypes.NewParamSetPair(ParamStoreKeyInstanceCost, &p.InstanceCost, validateInstanceCost), @@ -144,6 +149,9 @@ func (p Params) ValidateBasic() error { if err := validateAccessConfig(p.CodeUploadAccess); err != nil { return errors.Wrap(err, "upload access") } + if err := validateAccessConfig(p.ContractStatusAccess); err != nil { + return errors.Wrap(err, "contract status access") + } if err := validateMaxWasmCodeSize(p.MaxWasmCodeSize); err != nil { return errors.Wrap(err, "max wasm code size") } diff --git a/x/wasm/internal/types/params_test.go b/x/wasm/internal/types/params_test.go index dbf93a44d4..812ccbbab9 100644 --- a/x/wasm/internal/types/params_test.go +++ b/x/wasm/internal/types/params_test.go @@ -28,6 +28,7 @@ func TestValidateParams(t *testing.T) { src: Params{ CodeUploadAccess: AllowNobody, InstantiateDefaultPermission: AccessTypeNobody, + ContractStatusAccess: AllowNobody, MaxWasmCodeSize: DefaultMaxWasmCodeSize, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, @@ -38,6 +39,7 @@ func TestValidateParams(t *testing.T) { src: Params{ CodeUploadAccess: AllowEverybody, InstantiateDefaultPermission: AccessTypeEverybody, + ContractStatusAccess: AllowEverybody, MaxWasmCodeSize: DefaultMaxWasmCodeSize, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, @@ -48,6 +50,7 @@ func TestValidateParams(t *testing.T) { src: Params{ CodeUploadAccess: AccessTypeOnlyAddress.With(anyAddress), InstantiateDefaultPermission: AccessTypeOnlyAddress, + ContractStatusAccess: AccessTypeOnlyAddress.With(anyAddress), MaxWasmCodeSize: DefaultMaxWasmCodeSize, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, @@ -56,11 +59,12 @@ func TestValidateParams(t *testing.T) { }, "reject empty type in instantiate permission": { src: Params{ - CodeUploadAccess: AllowNobody, - MaxWasmCodeSize: DefaultMaxWasmCodeSize, - GasMultiplier: DefaultGasMultiplier, - InstanceCost: DefaultInstanceCost, - CompileCost: DefaultCompileCost, + CodeUploadAccess: AllowNobody, + ContractStatusAccess: DefaultContractStatusAccess, + MaxWasmCodeSize: DefaultMaxWasmCodeSize, + GasMultiplier: DefaultGasMultiplier, + InstanceCost: DefaultInstanceCost, + CompileCost: DefaultCompileCost, }, expErr: true, }, @@ -68,6 +72,7 @@ func TestValidateParams(t *testing.T) { src: Params{ CodeUploadAccess: AllowNobody, InstantiateDefaultPermission: 1111, + ContractStatusAccess: DefaultContractStatusAccess, MaxWasmCodeSize: DefaultMaxWasmCodeSize, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, @@ -75,10 +80,11 @@ func TestValidateParams(t *testing.T) { }, expErr: true, }, - "reject invalid address in only address": { + "reject CodeUploadAccess invalid address in only address": { src: Params{ CodeUploadAccess: AccessConfig{Permission: AccessTypeOnlyAddress, Address: invalidAddress}, InstantiateDefaultPermission: AccessTypeOnlyAddress, + ContractStatusAccess: DefaultContractStatusAccess, MaxWasmCodeSize: DefaultMaxWasmCodeSize, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, @@ -90,6 +96,7 @@ func TestValidateParams(t *testing.T) { src: Params{ CodeUploadAccess: AccessConfig{Permission: AccessTypeEverybody, Address: anyAddress.String()}, InstantiateDefaultPermission: AccessTypeOnlyAddress, + ContractStatusAccess: DefaultContractStatusAccess, MaxWasmCodeSize: DefaultMaxWasmCodeSize, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, @@ -101,6 +108,7 @@ func TestValidateParams(t *testing.T) { src: Params{ CodeUploadAccess: AccessConfig{Permission: AccessTypeNobody, Address: anyAddress.String()}, InstantiateDefaultPermission: AccessTypeOnlyAddress, + ContractStatusAccess: DefaultContractStatusAccess, MaxWasmCodeSize: DefaultMaxWasmCodeSize, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, @@ -111,6 +119,7 @@ func TestValidateParams(t *testing.T) { "reject empty CodeUploadAccess": { src: Params{ InstantiateDefaultPermission: AccessTypeOnlyAddress, + ContractStatusAccess: DefaultContractStatusAccess, MaxWasmCodeSize: DefaultMaxWasmCodeSize, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, @@ -122,6 +131,7 @@ func TestValidateParams(t *testing.T) { src: Params{ CodeUploadAccess: AccessConfig{Permission: AccessTypeUnspecified}, InstantiateDefaultPermission: AccessTypeOnlyAddress, + ContractStatusAccess: DefaultContractStatusAccess, MaxWasmCodeSize: DefaultMaxWasmCodeSize, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, @@ -133,6 +143,7 @@ func TestValidateParams(t *testing.T) { src: Params{ CodeUploadAccess: AllowNobody, InstantiateDefaultPermission: AccessTypeNobody, + ContractStatusAccess: DefaultContractStatusAccess, GasMultiplier: DefaultGasMultiplier, InstanceCost: DefaultInstanceCost, CompileCost: DefaultCompileCost, @@ -169,6 +180,65 @@ func TestValidateParams(t *testing.T) { }, expErr: true, }, + "reject ContractStatusAccess invalid address in only address": { + src: Params{ + CodeUploadAccess: DefaultUploadAccess, + InstantiateDefaultPermission: AccessTypeOnlyAddress, + ContractStatusAccess: AccessConfig{Permission: AccessTypeOnlyAddress, Address: invalidAddress}, + MaxWasmCodeSize: DefaultMaxWasmCodeSize, + GasMultiplier: DefaultGasMultiplier, + InstanceCost: DefaultInstanceCost, + CompileCost: DefaultCompileCost, + }, + expErr: true, + }, + "reject ContractStatusAccess Everybody with obsolete address": { + src: Params{ + CodeUploadAccess: DefaultUploadAccess, + InstantiateDefaultPermission: AccessTypeOnlyAddress, + ContractStatusAccess: AccessConfig{Permission: AccessTypeEverybody, Address: anyAddress.String()}, + MaxWasmCodeSize: DefaultMaxWasmCodeSize, + GasMultiplier: DefaultGasMultiplier, + InstanceCost: DefaultInstanceCost, + CompileCost: DefaultCompileCost, + }, + expErr: true, + }, + "reject ContractStatusAccess Nobody with obsolete address": { + src: Params{ + CodeUploadAccess: DefaultUploadAccess, + InstantiateDefaultPermission: AccessTypeOnlyAddress, + ContractStatusAccess: AccessConfig{Permission: AccessTypeNobody, Address: anyAddress.String()}, + MaxWasmCodeSize: DefaultMaxWasmCodeSize, + GasMultiplier: DefaultGasMultiplier, + InstanceCost: DefaultInstanceCost, + CompileCost: DefaultCompileCost, + }, + expErr: true, + }, + "reject empty ContractStatusAccess": { + src: Params{ + CodeUploadAccess: DefaultUploadAccess, + InstantiateDefaultPermission: AccessTypeOnlyAddress, + MaxWasmCodeSize: DefaultMaxWasmCodeSize, + GasMultiplier: DefaultGasMultiplier, + InstanceCost: DefaultInstanceCost, + CompileCost: DefaultCompileCost, + }, + expErr: true, + }, + "reject undefined permission in ContractStatusAccess": { + src: Params{ + CodeUploadAccess: DefaultUploadAccess, + InstantiateDefaultPermission: AccessTypeOnlyAddress, + ContractStatusAccess: AccessConfig{Permission: AccessTypeUnspecified}, + MaxWasmCodeSize: DefaultMaxWasmCodeSize, + GasMultiplier: DefaultGasMultiplier, + InstanceCost: DefaultInstanceCost, + CompileCost: DefaultCompileCost, + }, + expErr: true, + }, } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { @@ -231,6 +301,7 @@ func TestParamsUnmarshalJson(t *testing.T) { "defaults": { src: `{"code_upload_access": {"permission": "Everybody"}, "instantiate_default_permission": "Everybody", + "contract_status_access": {"permission": "Nobody"}, "max_wasm_code_size": 614400, "gas_multiplier": 100, "instance_cost": 40000, diff --git a/x/wasm/internal/types/proposal.go b/x/wasm/internal/types/proposal.go index b485f3fe7f..0fbf0ca421 100644 --- a/x/wasm/internal/types/proposal.go +++ b/x/wasm/internal/types/proposal.go @@ -416,6 +416,49 @@ func (p UnpinCodesProposal) String() string { `, p.Title, p.Description, p.CodeIDs) } +// ProposalRoute returns the routing key of a parameter change proposal. +func (p UpdateContractStatusProposal) ProposalRoute() string { return RouterKey } + +// GetTitle returns the title of the proposal +func (p *UpdateContractStatusProposal) GetTitle() string { return p.Title } + +// GetDescription returns the human readable description of the proposal +func (p UpdateContractStatusProposal) GetDescription() string { return p.Description } + +// ProposalType returns the type +func (p UpdateContractStatusProposal) ProposalType() string { return string(ProposalTypeUpdateAdmin) } + +// ValidateBasic validates the proposal +func (p UpdateContractStatusProposal) ValidateBasic() error { + if err := validateProposalCommons(p.Title, p.Description); err != nil { + return err + } + if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { + return sdkerrors.Wrap(err, "contract") + } + found := false + for _, v := range AllContractStatus { + if p.Status == v { + found = true + break + } + } + if !found || p.Status == ContractStatusUnspecified { + return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "invalid status") + } + return nil +} + +// String implements the Stringer interface. +func (p UpdateContractStatusProposal) String() string { + return fmt.Sprintf(`Update Contract Status Proposal: + Title: %s + Description: %s + Contract: %s + Status: %s +`, p.Title, p.Description, p.Contract, p.Status.String()) +} + func validateProposalCommons(title, description string) error { if strings.TrimSpace(title) != title { return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal title must not start/end with white spaces") diff --git a/x/wasm/internal/types/proposal.pb.go b/x/wasm/internal/types/proposal.pb.go index 8a2daacfea..4584fe15d2 100644 --- a/x/wasm/internal/types/proposal.pb.go +++ b/x/wasm/internal/types/proposal.pb.go @@ -347,6 +347,50 @@ func (m *UnpinCodesProposal) XXX_DiscardUnknown() { var xxx_messageInfo_UnpinCodesProposal proto.InternalMessageInfo +// UpdateStatusProposal gov proposal content type to update the contract status. +type UpdateContractStatusProposal struct { + // Title is a short summary + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + // Description is a human readable text + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + // Contract is the address of the smart contract + Contract string `protobuf:"bytes,3,opt,name=contract,proto3" json:"contract,omitempty"` + // Status to be set + Status ContractStatus `protobuf:"varint,4,opt,name=status,proto3,enum=cosmwasm.wasm.v1beta1.ContractStatus" json:"status,omitempty"` +} + +func (m *UpdateContractStatusProposal) Reset() { *m = UpdateContractStatusProposal{} } +func (*UpdateContractStatusProposal) ProtoMessage() {} +func (*UpdateContractStatusProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_c3ac5ce23bf32d05, []int{7} +} +func (m *UpdateContractStatusProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *UpdateContractStatusProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_UpdateContractStatusProposal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *UpdateContractStatusProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateContractStatusProposal.Merge(m, src) +} +func (m *UpdateContractStatusProposal) XXX_Size() int { + return m.Size() +} +func (m *UpdateContractStatusProposal) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateContractStatusProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateContractStatusProposal proto.InternalMessageInfo + func init() { proto.RegisterType((*StoreCodeProposal)(nil), "cosmwasm.wasm.v1beta1.StoreCodeProposal") proto.RegisterType((*InstantiateContractProposal)(nil), "cosmwasm.wasm.v1beta1.InstantiateContractProposal") @@ -355,58 +399,61 @@ func init() { proto.RegisterType((*ClearAdminProposal)(nil), "cosmwasm.wasm.v1beta1.ClearAdminProposal") proto.RegisterType((*PinCodesProposal)(nil), "cosmwasm.wasm.v1beta1.PinCodesProposal") proto.RegisterType((*UnpinCodesProposal)(nil), "cosmwasm.wasm.v1beta1.UnpinCodesProposal") + proto.RegisterType((*UpdateContractStatusProposal)(nil), "cosmwasm.wasm.v1beta1.UpdateContractStatusProposal") } func init() { proto.RegisterFile("proposal.proto", fileDescriptor_c3ac5ce23bf32d05) } var fileDescriptor_c3ac5ce23bf32d05 = []byte{ - // 730 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x95, 0x4d, 0x6b, 0xe3, 0x46, - 0x18, 0xc7, 0xad, 0x38, 0x7e, 0xc9, 0xd8, 0xa4, 0xae, 0xea, 0xb8, 0x22, 0x29, 0x92, 0x51, 0x20, - 0xf8, 0x52, 0xa9, 0x49, 0xa1, 0x6f, 0xd0, 0x83, 0xe5, 0x5e, 0x72, 0x30, 0x04, 0x85, 0xb4, 0x10, - 0x0a, 0x66, 0x24, 0x4d, 0x94, 0x69, 0xa5, 0x19, 0xa1, 0x19, 0xc7, 0xf5, 0xb7, 0xe8, 0x07, 0xe8, - 0x07, 0x08, 0xbd, 0x94, 0x7e, 0x8b, 0x1c, 0x73, 0xd8, 0x43, 0x4e, 0xda, 0x8d, 0x73, 0xd9, 0xb3, - 0x8f, 0x7b, 0x5a, 0x46, 0x23, 0x7b, 0x9d, 0x25, 0x84, 0xc0, 0xbe, 0xc0, 0x5e, 0x8c, 0x1f, 0x3d, - 0xff, 0x79, 0xfe, 0xff, 0xf9, 0xcd, 0xc8, 0x06, 0x9b, 0x49, 0x4a, 0x13, 0xca, 0x60, 0x64, 0x25, - 0x29, 0xe5, 0x54, 0xdd, 0xf2, 0x29, 0x8b, 0x27, 0x90, 0xc5, 0x56, 0xfe, 0x71, 0xb1, 0xef, 0x21, - 0x0e, 0xf7, 0xb7, 0xdb, 0x21, 0x0d, 0x69, 0xae, 0xb0, 0xc5, 0x37, 0x29, 0xde, 0xde, 0x89, 0xbc, - 0xd8, 0xf6, 0x20, 0x43, 0x76, 0xa1, 0xb3, 0x7d, 0x8a, 0x49, 0xd1, 0x6c, 0xf0, 0x69, 0x82, 0x98, - 0x2c, 0xcc, 0xcb, 0x35, 0xf0, 0x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9a, 0xff, 0x75, 0x7c, 0xfb, 0x3a, 0x00, 0x00, - 0xff, 0xff, 0x72, 0x5c, 0xc9, 0xf7, 0xa3, 0x06, 0x00, 0x00, + // 763 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0x4f, 0x6f, 0xe3, 0x44, + 0x14, 0x8f, 0x9b, 0xc6, 0x49, 0x27, 0x51, 0x09, 0x26, 0x0d, 0x56, 0x77, 0x65, 0x47, 0x5e, 0xb1, + 0xca, 0x05, 0x9b, 0x06, 0x89, 0x7f, 0xd2, 0x1e, 0xe2, 0x70, 0xe9, 0x21, 0x52, 0xe5, 0x6a, 0x41, + 0x5a, 0x21, 0x45, 0x63, 0x7b, 0xd6, 0x3b, 0x60, 0xcf, 0x58, 0x9e, 0xc9, 0x86, 0x7c, 0x0b, 0x3e, + 0x00, 0x1f, 0x60, 0xc5, 0x05, 0xf1, 0x2d, 0x7a, 0xdc, 0x03, 0x87, 0x3d, 0x19, 0x9a, 0x5e, 0x38, + 0xe7, 0xc8, 0x09, 0xcd, 0x8c, 0x13, 0x52, 0x54, 0xaa, 0x4a, 0x50, 0x24, 0x2e, 0x51, 0xde, 0xbc, + 0xdf, 0x7b, 0xbf, 0xdf, 0xfc, 0xde, 0xcb, 0x04, 0x1c, 0xe6, 0x05, 0xcd, 0x29, 0x83, 0xa9, 0x9b, + 0x17, 0x94, 0x53, 0xe3, 0x28, 0xa2, 0x2c, 0x5b, 0x40, 0x96, 0xb9, 0xf2, 0xe3, 0xe5, 0x49, 0x88, + 0x38, 0x3c, 0x39, 0xee, 0x25, 0x34, 0xa1, 0x12, 0xe1, 0x89, 0x6f, 0x0a, 0x7c, 0xfc, 0x20, 0x0d, + 0x33, 0x2f, 0x84, 0x0c, 0x79, 0x15, 0xce, 0x8b, 0x28, 0x26, 0x55, 0xb2, 0xcd, 0x97, 0x39, 0x62, + 0x2a, 0x70, 0x5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 0xbf, 0xae, 0x2c, 0xed, 0xbb, 0x2b, 0xab, 0xf6, 0xfa, + 0xca, 0xaa, 0xbd, 0xb9, 0xb2, 0x6a, 0xcf, 0x3e, 0xb8, 0xe5, 0x89, 0xf9, 0xd6, 0x13, 0x3c, 0x1e, + 0x26, 0x1c, 0x15, 0x04, 0xa6, 0xea, 0xc9, 0x09, 0x75, 0xf9, 0x77, 0xf7, 0xe1, 0x1f, 0x01, 0x00, + 0x00, 0xff, 0xff, 0xc8, 0x67, 0x26, 0x46, 0x57, 0x07, 0x00, 0x00, } func (this *StoreCodeProposal) Equal(that interface{}) bool { @@ -673,6 +720,39 @@ func (this *UnpinCodesProposal) Equal(that interface{}) bool { } return true } +func (this *UpdateContractStatusProposal) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*UpdateContractStatusProposal) + if !ok { + that2, ok := that.(UpdateContractStatusProposal) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Title != that1.Title { + return false + } + if this.Description != that1.Description { + return false + } + if this.Contract != that1.Contract { + return false + } + if this.Status != that1.Status { + return false + } + return true +} func (m *StoreCodeProposal) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1102,6 +1182,55 @@ func (m *UnpinCodesProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *UpdateContractStatusProposal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *UpdateContractStatusProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *UpdateContractStatusProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Status != 0 { + i = encodeVarintProposal(dAtA, i, uint64(m.Status)) + i-- + dAtA[i] = 0x20 + } + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintProposal(dAtA []byte, offset int, v uint64) int { offset -= sovProposal(v) base := offset @@ -1318,6 +1447,30 @@ func (m *UnpinCodesProposal) Size() (n int) { return n } +func (m *UpdateContractStatusProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Contract) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + if m.Status != 0 { + n += 1 + sovProposal(uint64(m.Status)) + } + return n +} + func sovProposal(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2836,6 +2989,171 @@ func (m *UnpinCodesProposal) Unmarshal(dAtA []byte) error { } return nil } +func (m *UpdateContractStatusProposal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: UpdateContractStatusProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UpdateContractStatusProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Contract = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + m.Status = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Status |= ContractStatus(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipProposal(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/wasm/internal/types/proposal.proto b/x/wasm/internal/types/proposal.proto index 4ed23ee833..33fb27d9ab 100644 --- a/x/wasm/internal/types/proposal.proto +++ b/x/wasm/internal/types/proposal.proto @@ -106,3 +106,15 @@ message UnpinCodesProposal { // CodeIDs references the WASM codes repeated uint64 code_ids = 3 [(gogoproto.customname) = "CodeIDs", (gogoproto.moretags) = "yaml:\"code_ids\""]; } + +// UpdateStatusProposal gov proposal content type to update the contract status. +message UpdateContractStatusProposal { + // Title is a short summary + string title = 1; + // Description is a human readable text + string description = 2; + // Contract is the address of the smart contract + string contract = 3; + // Status to be set + ContractStatus status = 4; +} diff --git a/x/wasm/internal/types/proposal_test.go b/x/wasm/internal/types/proposal_test.go index c24ba7f4f9..2953d3f776 100644 --- a/x/wasm/internal/types/proposal_test.go +++ b/x/wasm/internal/types/proposal_test.go @@ -430,6 +430,61 @@ func TestValidateClearAdminProposal(t *testing.T) { } } +func TestValidateUpdateContractStatusProposal(t *testing.T) { + var ( + invalidAddress = "invalid address" + ) + + specs := map[string]struct { + src *UpdateContractStatusProposal + expErr bool + }{ + "all good": { + src: UpdateContractStatusProposalFixture(), + }, + "base data missing": { + src: UpdateContractStatusProposalFixture(func(p *UpdateContractStatusProposal) { + p.Title = "" + }), + expErr: true, + }, + "contract missing": { + src: UpdateContractStatusProposalFixture(func(p *UpdateContractStatusProposal) { + p.Contract = "" + }), + expErr: true, + }, + "contract invalid": { + src: UpdateContractStatusProposalFixture(func(p *UpdateContractStatusProposal) { + p.Contract = invalidAddress + }), + expErr: true, + }, + "status missing": { + src: UpdateContractStatusProposalFixture(func(p *UpdateContractStatusProposal) { + p.Status = ContractStatusUnspecified + }), + expErr: true, + }, + "status invalid": { + src: UpdateContractStatusProposalFixture(func(p *UpdateContractStatusProposal) { + p.Status = 3 + }), + expErr: true, + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + err := spec.src.ValidateBasic() + if spec.expErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} + func TestProposalStrings(t *testing.T) { specs := map[string]struct { src govtypes.Content diff --git a/x/wasm/internal/types/test_fixtures.go b/x/wasm/internal/types/test_fixtures.go index fe9ff59ca4..a6b60af7a8 100644 --- a/x/wasm/internal/types/test_fixtures.go +++ b/x/wasm/internal/types/test_fixtures.go @@ -111,6 +111,7 @@ func ContractInfoFixture(mutators ...func(*ContractInfo)) ContractInfo { Creator: anyAddress, Label: "any", Created: &AbsoluteTxPosition{BlockHeight: 1, TxIndex: 1}, + Status: ContractStatusActive, } for _, m := range mutators { @@ -294,3 +295,18 @@ func ClearAdminProposalFixture(mutators ...func(p *ClearAdminProposal)) *ClearAd } return p } + +func UpdateContractStatusProposalFixture(mutators ...func(p *UpdateContractStatusProposal)) *UpdateContractStatusProposal { + const contractAddr = "link1hcttwju93d5m39467gjcq63p5kc4fdcn30dgd8" + + p := &UpdateContractStatusProposal{ + Title: "Foo", + Description: "Bar", + Contract: contractAddr, + Status: ContractStatusActive, + } + for _, m := range mutators { + m(p) + } + return p +} diff --git a/x/wasm/internal/types/tx.go b/x/wasm/internal/types/tx.go index d7e9dcf060..a4add48fd9 100644 --- a/x/wasm/internal/types/tx.go +++ b/x/wasm/internal/types/tx.go @@ -104,6 +104,73 @@ func (msg MsgInstantiateContract) GetSigners() []sdk.AccAddress { } +func (msg MsgStoreCodeAndInstantiateContract) Route() string { + return RouterKey +} + +func (msg MsgStoreCodeAndInstantiateContract) Type() string { + return "store-code-and-instantiate" +} + +func (msg MsgStoreCodeAndInstantiateContract) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { + return err + } + + if err := validateWasmCode(msg.WASMByteCode); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error()) + } + + if err := validateSourceURL(msg.Source); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "source %s", err.Error()) + } + + if err := validateBuilder(msg.Builder); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "builder %s", err.Error()) + } + + if msg.InstantiatePermission != nil { + if err := msg.InstantiatePermission.ValidateBasic(); err != nil { + return sdkerrors.Wrap(err, "instantiate permission") + } + } + + if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { + return sdkerrors.Wrap(err, "sender") + } + + if err := validateLabel(msg.Label); err != nil { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "label is required") + } + + if !msg.Funds.IsValid() { + return sdkerrors.ErrInvalidCoins + } + + if len(msg.Admin) != 0 { + if _, err := sdk.AccAddressFromBech32(msg.Admin); err != nil { + return sdkerrors.Wrap(err, "admin") + } + } + + if !json.Valid(msg.InitMsg) { + return sdkerrors.Wrap(ErrInvalid, "init msg json") + } + return nil +} + +func (msg MsgStoreCodeAndInstantiateContract) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +func (msg MsgStoreCodeAndInstantiateContract) GetSigners() []sdk.AccAddress { + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{senderAddr} +} + func (msg MsgExecuteContract) Route() string { return RouterKey } @@ -252,6 +319,46 @@ func (msg MsgClearAdmin) GetSigners() []sdk.AccAddress { } +func (msg MsgUpdateContractStatus) Route() string { + return RouterKey +} + +func (msg MsgUpdateContractStatus) Type() string { + return "update-contract-status" +} + +func (msg MsgUpdateContractStatus) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { + return sdkerrors.Wrap(err, "sender") + } + if _, err := sdk.AccAddressFromBech32(msg.Contract); err != nil { + return sdkerrors.Wrap(err, "contract") + } + found := false + for _, v := range AllContractStatus { + if msg.Status == v { + found = true + break + } + } + if !found || msg.Status == ContractStatusUnspecified { + return sdkerrors.Wrap(ErrInvalidMsg, "invalid status") + } + return nil +} + +func (msg MsgUpdateContractStatus) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +func (msg MsgUpdateContractStatus) GetSigners() []sdk.AccAddress { + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{senderAddr} +} + func (msg MsgIBCSend) Route() string { return RouterKey } diff --git a/x/wasm/internal/types/tx.pb.go b/x/wasm/internal/types/tx.pb.go index 42fa962bc1..10c79aab71 100644 --- a/x/wasm/internal/types/tx.pb.go +++ b/x/wasm/internal/types/tx.pb.go @@ -207,6 +207,108 @@ func (m *MsgInstantiateContractResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgInstantiateContractResponse proto.InternalMessageInfo +// MsgStoreCodeAndInstantiateContract submit Wasm code to the system and instantiate a contract using it. +type MsgStoreCodeAndInstantiateContract struct { + // Sender is the that actor that signed the messages + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + // WASMByteCode can be raw or gzip compressed + WASMByteCode []byte `protobuf:"bytes,2,opt,name=wasm_byte_code,json=wasmByteCode,proto3" json:"wasm_byte_code,omitempty"` + // Source is a valid absolute HTTPS URI to the contract's source code, optional + Source string `protobuf:"bytes,3,opt,name=source,proto3" json:"source,omitempty"` + // Builder is a valid docker image name with tag, optional + Builder string `protobuf:"bytes,4,opt,name=builder,proto3" json:"builder,omitempty"` + // InstantiatePermission access control to apply on contract creation, optional + InstantiatePermission *AccessConfig `protobuf:"bytes,5,opt,name=instantiate_permission,json=instantiatePermission,proto3" json:"instantiate_permission,omitempty"` + // Admin is an optional address that can execute migrations + Admin string `protobuf:"bytes,6,opt,name=admin,proto3" json:"admin,omitempty"` + // Label is optional metadata to be stored with a contract instance. + Label string `protobuf:"bytes,7,opt,name=label,proto3" json:"label,omitempty"` + // InitMsg json encoded message to be passed to the contract on instantiation + InitMsg encoding_json.RawMessage `protobuf:"bytes,8,opt,name=init_msg,json=initMsg,proto3,casttype=encoding/json.RawMessage" json:"init_msg,omitempty"` + // Funds coins that are transferred to the contract on instantiation + Funds github_com_line_lbm_sdk_v2_types.Coins `protobuf:"bytes,9,rep,name=funds,proto3,castrepeated=github.com/line/lbm-sdk/v2/types.Coins" json:"funds"` +} + +func (m *MsgStoreCodeAndInstantiateContract) Reset() { *m = MsgStoreCodeAndInstantiateContract{} } +func (m *MsgStoreCodeAndInstantiateContract) String() string { return proto.CompactTextString(m) } +func (*MsgStoreCodeAndInstantiateContract) ProtoMessage() {} +func (*MsgStoreCodeAndInstantiateContract) Descriptor() ([]byte, []int) { + return fileDescriptor_0fd2153dc07d3b5c, []int{4} +} +func (m *MsgStoreCodeAndInstantiateContract) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgStoreCodeAndInstantiateContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgStoreCodeAndInstantiateContract.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgStoreCodeAndInstantiateContract) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgStoreCodeAndInstantiateContract.Merge(m, src) +} +func (m *MsgStoreCodeAndInstantiateContract) XXX_Size() int { + return m.Size() +} +func (m *MsgStoreCodeAndInstantiateContract) XXX_DiscardUnknown() { + xxx_messageInfo_MsgStoreCodeAndInstantiateContract.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgStoreCodeAndInstantiateContract proto.InternalMessageInfo + +// MsgStoreCodeAndInstantiateContractResponse returns store and instantiate result data. +type MsgStoreCodeAndInstantiateContractResponse struct { + // CodeID is the reference to the stored WASM code + CodeID uint64 `protobuf:"varint,1,opt,name=code_id,json=codeId,proto3" json:"code_id,omitempty"` + // Address is the bech32 address of the new contract instance. + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + // Data contains base64-encoded bytes to returned from the contract + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *MsgStoreCodeAndInstantiateContractResponse) Reset() { + *m = MsgStoreCodeAndInstantiateContractResponse{} +} +func (m *MsgStoreCodeAndInstantiateContractResponse) String() string { + return proto.CompactTextString(m) +} +func (*MsgStoreCodeAndInstantiateContractResponse) ProtoMessage() {} +func (*MsgStoreCodeAndInstantiateContractResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_0fd2153dc07d3b5c, []int{5} +} +func (m *MsgStoreCodeAndInstantiateContractResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgStoreCodeAndInstantiateContractResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgStoreCodeAndInstantiateContractResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgStoreCodeAndInstantiateContractResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgStoreCodeAndInstantiateContractResponse.Merge(m, src) +} +func (m *MsgStoreCodeAndInstantiateContractResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgStoreCodeAndInstantiateContractResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgStoreCodeAndInstantiateContractResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgStoreCodeAndInstantiateContractResponse proto.InternalMessageInfo + // MsgExecuteContract submits the given message data to a smart contract type MsgExecuteContract struct { // Sender is the that actor that signed the messages @@ -223,7 +325,7 @@ func (m *MsgExecuteContract) Reset() { *m = MsgExecuteContract{} } func (m *MsgExecuteContract) String() string { return proto.CompactTextString(m) } func (*MsgExecuteContract) ProtoMessage() {} func (*MsgExecuteContract) Descriptor() ([]byte, []int) { - return fileDescriptor_0fd2153dc07d3b5c, []int{4} + return fileDescriptor_0fd2153dc07d3b5c, []int{6} } func (m *MsgExecuteContract) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -262,7 +364,7 @@ func (m *MsgExecuteContractResponse) Reset() { *m = MsgExecuteContractRe func (m *MsgExecuteContractResponse) String() string { return proto.CompactTextString(m) } func (*MsgExecuteContractResponse) ProtoMessage() {} func (*MsgExecuteContractResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_0fd2153dc07d3b5c, []int{5} + return fileDescriptor_0fd2153dc07d3b5c, []int{7} } func (m *MsgExecuteContractResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -307,7 +409,7 @@ func (m *MsgMigrateContract) Reset() { *m = MsgMigrateContract{} } func (m *MsgMigrateContract) String() string { return proto.CompactTextString(m) } func (*MsgMigrateContract) ProtoMessage() {} func (*MsgMigrateContract) Descriptor() ([]byte, []int) { - return fileDescriptor_0fd2153dc07d3b5c, []int{6} + return fileDescriptor_0fd2153dc07d3b5c, []int{8} } func (m *MsgMigrateContract) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -347,7 +449,7 @@ func (m *MsgMigrateContractResponse) Reset() { *m = MsgMigrateContractRe func (m *MsgMigrateContractResponse) String() string { return proto.CompactTextString(m) } func (*MsgMigrateContractResponse) ProtoMessage() {} func (*MsgMigrateContractResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_0fd2153dc07d3b5c, []int{7} + return fileDescriptor_0fd2153dc07d3b5c, []int{9} } func (m *MsgMigrateContractResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -390,7 +492,7 @@ func (m *MsgUpdateAdmin) Reset() { *m = MsgUpdateAdmin{} } func (m *MsgUpdateAdmin) String() string { return proto.CompactTextString(m) } func (*MsgUpdateAdmin) ProtoMessage() {} func (*MsgUpdateAdmin) Descriptor() ([]byte, []int) { - return fileDescriptor_0fd2153dc07d3b5c, []int{8} + return fileDescriptor_0fd2153dc07d3b5c, []int{10} } func (m *MsgUpdateAdmin) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -427,7 +529,7 @@ func (m *MsgUpdateAdminResponse) Reset() { *m = MsgUpdateAdminResponse{} func (m *MsgUpdateAdminResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateAdminResponse) ProtoMessage() {} func (*MsgUpdateAdminResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_0fd2153dc07d3b5c, []int{9} + return fileDescriptor_0fd2153dc07d3b5c, []int{11} } func (m *MsgUpdateAdminResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -468,7 +570,7 @@ func (m *MsgClearAdmin) Reset() { *m = MsgClearAdmin{} } func (m *MsgClearAdmin) String() string { return proto.CompactTextString(m) } func (*MsgClearAdmin) ProtoMessage() {} func (*MsgClearAdmin) Descriptor() ([]byte, []int) { - return fileDescriptor_0fd2153dc07d3b5c, []int{10} + return fileDescriptor_0fd2153dc07d3b5c, []int{12} } func (m *MsgClearAdmin) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -505,7 +607,7 @@ func (m *MsgClearAdminResponse) Reset() { *m = MsgClearAdminResponse{} } func (m *MsgClearAdminResponse) String() string { return proto.CompactTextString(m) } func (*MsgClearAdminResponse) ProtoMessage() {} func (*MsgClearAdminResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_0fd2153dc07d3b5c, []int{11} + return fileDescriptor_0fd2153dc07d3b5c, []int{13} } func (m *MsgClearAdminResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -534,11 +636,93 @@ func (m *MsgClearAdminResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgClearAdminResponse proto.InternalMessageInfo +// MsgUpdateContractStatus sets a new status for a smart contract +type MsgUpdateContractStatus struct { + // Sender is the that actor that signed the messages + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + // Contract is the address of the smart contract + Contract string `protobuf:"bytes,2,opt,name=contract,proto3" json:"contract,omitempty"` + // Status to be set + Status ContractStatus `protobuf:"varint,3,opt,name=status,proto3,enum=cosmwasm.wasm.v1beta1.ContractStatus" json:"status,omitempty"` +} + +func (m *MsgUpdateContractStatus) Reset() { *m = MsgUpdateContractStatus{} } +func (m *MsgUpdateContractStatus) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateContractStatus) ProtoMessage() {} +func (*MsgUpdateContractStatus) Descriptor() ([]byte, []int) { + return fileDescriptor_0fd2153dc07d3b5c, []int{14} +} +func (m *MsgUpdateContractStatus) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateContractStatus) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateContractStatus.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateContractStatus) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateContractStatus.Merge(m, src) +} +func (m *MsgUpdateContractStatus) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateContractStatus) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateContractStatus.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateContractStatus proto.InternalMessageInfo + +// MsgUpdateContractStatusResponse returns empty data +type MsgUpdateContractStatusResponse struct { +} + +func (m *MsgUpdateContractStatusResponse) Reset() { *m = MsgUpdateContractStatusResponse{} } +func (m *MsgUpdateContractStatusResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateContractStatusResponse) ProtoMessage() {} +func (*MsgUpdateContractStatusResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_0fd2153dc07d3b5c, []int{15} +} +func (m *MsgUpdateContractStatusResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateContractStatusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateContractStatusResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateContractStatusResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateContractStatusResponse.Merge(m, src) +} +func (m *MsgUpdateContractStatusResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateContractStatusResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateContractStatusResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateContractStatusResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgStoreCode)(nil), "cosmwasm.wasm.v1beta1.MsgStoreCode") proto.RegisterType((*MsgStoreCodeResponse)(nil), "cosmwasm.wasm.v1beta1.MsgStoreCodeResponse") proto.RegisterType((*MsgInstantiateContract)(nil), "cosmwasm.wasm.v1beta1.MsgInstantiateContract") proto.RegisterType((*MsgInstantiateContractResponse)(nil), "cosmwasm.wasm.v1beta1.MsgInstantiateContractResponse") + proto.RegisterType((*MsgStoreCodeAndInstantiateContract)(nil), "cosmwasm.wasm.v1beta1.MsgStoreCodeAndInstantiateContract") + proto.RegisterType((*MsgStoreCodeAndInstantiateContractResponse)(nil), "cosmwasm.wasm.v1beta1.MsgStoreCodeAndInstantiateContractResponse") proto.RegisterType((*MsgExecuteContract)(nil), "cosmwasm.wasm.v1beta1.MsgExecuteContract") proto.RegisterType((*MsgExecuteContractResponse)(nil), "cosmwasm.wasm.v1beta1.MsgExecuteContractResponse") proto.RegisterType((*MsgMigrateContract)(nil), "cosmwasm.wasm.v1beta1.MsgMigrateContract") @@ -547,62 +731,73 @@ func init() { proto.RegisterType((*MsgUpdateAdminResponse)(nil), "cosmwasm.wasm.v1beta1.MsgUpdateAdminResponse") proto.RegisterType((*MsgClearAdmin)(nil), "cosmwasm.wasm.v1beta1.MsgClearAdmin") proto.RegisterType((*MsgClearAdminResponse)(nil), "cosmwasm.wasm.v1beta1.MsgClearAdminResponse") + proto.RegisterType((*MsgUpdateContractStatus)(nil), "cosmwasm.wasm.v1beta1.MsgUpdateContractStatus") + proto.RegisterType((*MsgUpdateContractStatusResponse)(nil), "cosmwasm.wasm.v1beta1.MsgUpdateContractStatusResponse") } func init() { proto.RegisterFile("tx.proto", fileDescriptor_0fd2153dc07d3b5c) } var fileDescriptor_0fd2153dc07d3b5c = []byte{ - // 797 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x96, 0x4f, 0x6f, 0xe3, 0x44, - 0x18, 0xc6, 0xe3, 0xcd, 0xff, 0x37, 0x61, 0x41, 0xa6, 0x0d, 0x96, 0x17, 0x39, 0x51, 0x16, 0x50, - 0x10, 0xd4, 0xde, 0x06, 0x01, 0x07, 0xc4, 0xa1, 0x09, 0x1c, 0x7a, 0xf0, 0x0a, 0x79, 0x85, 0x90, - 0x56, 0xa0, 0x30, 0xb6, 0xa7, 0x66, 0xc0, 0x9e, 0x89, 0x3c, 0x93, 0xa6, 0x15, 0xdf, 0x80, 0x13,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72, 0x81, 0xa8, 0x20, 0x48, 0xe0, 0xd9, 0x1c, 0x87, 0x01, 0xe1, 0x9c, - 0x30, 0xaa, 0xd4, 0x07, 0xd2, 0xa8, 0x33, 0x7e, 0xac, 0xef, 0x45, 0xa1, 0x9f, 0x39, 0x0e, 0xe6, - 0x7c, 0xca, 0xe8, 0x05, 0xf1, 0xac, 0xe3, 0x9c, 0xc5, 0x67, 0x99, 0xc3, 0xf0, 0x23, 0x38, 0xca, - 0x77, 0x6b, 0x61, 0x3e, 0x67, 0x94, 0x63, 0xf9, 0x31, 0x34, 0xa3, 0x9e, 0x66, 0xc4, 0x8d, 0xdb, - 0xae, 0x4d, 0x60, 0xbd, 0xea, 0x37, 0x22, 0xc9, 0xf9, 0x27, 0x56, 0x23, 0x7a, 0x75, 0xee, 0x0e, - 0x7f, 0x7a, 0x00, 0x3d, 0x93, 0x7b, 0xe7, 0x5b, 0xe7, 0x29, 0xa3, 0x22, 0x44, 0x8e, 0x28, 0xa4, - 0x76, 0x04, 0x75, 0xe4, 0x06, 0x84, 0xc6, 0xb0, 0xda, 0x56, 0x52, 0xe4, 0xd3, 0xaa, 0x45, 0x69, - 0xd1, 0x56, 0x1f, 0xd9, 0xd8, 0x4f, 0xf1, 0x24, 0x85, 0xfc, 0x21, 0xb4, 0x08, 0x25, 0x62, 0x16, - 0x70, 0x2f, 0xc6, 0xd1, 0x9d, 0xbc, 0xfe, 0xf7, 0xaa, 0xaf, 0x60, 0xea, 0x30, 0x97, 0x50, 0xcf, - 0xf8, 0x96, 0x33, 0xaa, 0x5b, 0x68, 0x69, 0x62, 0xce, 0x91, 0x87, 0xad, 0x66, 0xa4, 0x36, 0xb9, - 0x27, 0x7f, 0x09, 0xf5, 0x8b, 0x05, 0x75, 0xb9, 0xd2, 0x18, 0x54, 0x47, 0x9d, 0x71, 0x4f, 0xf7, - 0xed, 0x40, 0x8f, 0x06, 0x27, 0xe3, 0x37, 0x65, 0x84, 0x4e, 0xf4, 0x9b, 0x55, 0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, 0x00, 0x00, + // 934 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x57, 0x4d, 0x6f, 0xe3, 0x54, + 0x14, 0x8d, 0x9b, 0x36, 0x1f, 0x37, 0xa1, 0x20, 0xd3, 0x76, 0x2c, 0x0f, 0x4a, 0x8a, 0x87, 0x41, + 0xe5, 0xa3, 0xf6, 0x34, 0x88, 0x41, 0x08, 0xcd, 0x22, 0x09, 0x2c, 0xba, 0xf0, 0x08, 0xb9, 0x42, + 0x48, 0x23, 0x50, 0x78, 0xb6, 0xdf, 0x98, 0x07, 0xf6, 0x7b, 0x91, 0xdf, 0xcb, 0xb4, 0x15, 0x12, + 0xfc, 0x01, 0x16, 0x2c, 0xd9, 0xb1, 0x47, 0xf3, 0x37, 0x90, 0xba, 0x9c, 0x15, 0x62, 0x55, 0x20, + 0xdd, 0xf2, 0x0b, 0x58, 0x21, 0x7f, 0xc4, 0x71, 0x43, 0x9c, 0xba, 0x45, 0xb3, 0x61, 0x53, 0xf9, + 0x26, 0xe7, 0xde, 0x73, 0xef, 0xf1, 0x79, 0xf7, 0x35, 0xd0, 0x10, 0x27, 0xfa, 0x38, 0x64, 0x82, + 0xc9, 0xdb, 0x0e, 0xe3, 0xc1, 0x31, 0xe2, 0x81, 0x1e, 0xff, 0x79, 0x72, 0x60, 0x63, 0x81, 0x0e, + 0xd4, 0xdb, 0xbe, 0x1d, 0x18, 0x36, 0xe2, 0xd8, 0x48, 0x3f, 0x31, 0x1c, 0x46, 0x68, 0x92, 0xa3, + 0x6e, 0x79, 0xcc, 0x63, 0xf1, 0xa3, 0x11, 0x3d, 0xa5, 0x9f, 0xb6, 0xc4, 0xe9, 0x18, 0xf3, 0x24, + 0xd0, 0xfe, 0x92, 0xa0, 0x6d, 0x72, 0xef, 0x48, 0xb0, 0x10, 0x0f, 0x99, 0x8b, 0xe5, 0x1d, 0xa8, + 0x71, 0x4c, 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x4e, 0x61, + 0xde, 0x48, 0x6b, 0xcb, 0x8d, 0x54, 0xcd, 0x19, 0xe9, 0x57, 0x09, 0x64, 0x93, 0x7b, 0x1f, 0x9d, + 0x60, 0x67, 0x52, 0xc2, 0x38, 0x2a, 0x34, 0x9c, 0x14, 0x93, 0x56, 0xcf, 0x62, 0x59, 0x87, 0x6a, + 0xa4, 0x6e, 0xb5, 0x84, 0xba, 0x11, 0x70, 0xae, 0xec, 0xc6, 0xf3, 0x50, 0xf6, 0x1e, 0xa8, 0xff, + 0x9e, 0x2b, 0x53, 0x72, 0x26, 0x85, 0x94, 0x93, 0xe2, 0x69, 0x22, 0x85, 0x49, 0xbc, 0x10, 0xfd, + 0x47, 0x29, 0x4a, 0x2d, 0xb0, 0x07, 0xd0, 0x0a, 0x12, 0xae, 0xd8, 0x95, 0xeb, 0x25, 0x74, 0x83, + 0x34, 0xc1, 0xe4, 0x5e, 0x3a, 0xe0, 0x42, 0xb7, 0x2b, 0x07, 0x44, 0xb0, 0x69, 0x72, 0xef, 0x93, + 0xb1, 0x8b, 0x04, 0xee, 0xc7, 0x67, 0xa5, 0x68, 0xb6, 0xdb, 0xd0, 0xa4, 0xf8, 0x78, 0x94, 0x5f, + 0xcd, 0x0d, 0x8a, 0x8f, 0x93, 0xa4, 0xfc, 0xe0, 0xd5, 0xcb, 0x83, 0x6b, 0x4a, 0x7c, 0x03, 0xe4, + 0x28, 0x66, 0x0d, 0x69, 0x43, 0x78, 0xc1, 0xe4, 0xde, 0xd0, 0xc7, 0x28, 0x5c, 0xcd, 0xbd, 0xaa, + 0xfc, 0x2d, 0xd8, 0xbe, 0x54, 0x24, 0xab, 0xfe, 0xbd, 0x04, 0xb7, 0x32, 0xe2, 0x99, 0x18, 0x47, + 0x02, 0x89, 0x09, 0xbf, 0xd1, 0x0b, 0x7c, 0x00, 0x35, 0x1e, 0x67, 0xc7, 0x2d, 0x6c, 0xf6, 0xee, + 0x16, 0xac, 0xa9, 0xcb, 0x54, 0x56, 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0x06, 0xa1, 0x02, 0x87, 0x14, 0xf9, + 0xc9, 0x5d, 0x65, 0xd7, 0xe2, 0x9f, 0x17, 0xef, 0xfc, 0x13, 0x00, 0x00, 0xff, 0xff, 0x0b, 0x74, + 0x70, 0x20, 0xc1, 0x0c, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -619,8 +814,10 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // StoreCode to submit Wasm code to the system StoreCode(ctx context.Context, in *MsgStoreCode, opts ...grpc.CallOption) (*MsgStoreCodeResponse, error) - // Instantiate creates a new smart contract instance for the given code id. + // Instantiate creates a new smart contract instance for the given code id. InstantiateContract(ctx context.Context, in *MsgInstantiateContract, opts ...grpc.CallOption) (*MsgInstantiateContractResponse, error) + // Store Wasm code and Instantiate a new contract + StoreCodeAndInstantiateContract(ctx context.Context, in *MsgStoreCodeAndInstantiateContract, opts ...grpc.CallOption) (*MsgStoreCodeAndInstantiateContractResponse, error) // Execute submits the given message data to a smart contract ExecuteContract(ctx context.Context, in *MsgExecuteContract, opts ...grpc.CallOption) (*MsgExecuteContractResponse, error) // Migrate runs a code upgrade/ downgrade for a smart contract @@ -629,6 +826,8 @@ type MsgClient interface { UpdateAdmin(ctx context.Context, in *MsgUpdateAdmin, opts ...grpc.CallOption) (*MsgUpdateAdminResponse, error) // ClearAdmin removes any admin stored for a smart contract ClearAdmin(ctx context.Context, in *MsgClearAdmin, opts ...grpc.CallOption) (*MsgClearAdminResponse, error) + // UpdateContractStatus sets a new status for a smart contract + UpdateContractStatus(ctx context.Context, in *MsgUpdateContractStatus, opts ...grpc.CallOption) (*MsgUpdateContractStatusResponse, error) } type msgClient struct { @@ -657,6 +856,15 @@ func (c *msgClient) InstantiateContract(ctx context.Context, in *MsgInstantiateC return out, nil } +func (c *msgClient) StoreCodeAndInstantiateContract(ctx context.Context, in *MsgStoreCodeAndInstantiateContract, opts ...grpc.CallOption) (*MsgStoreCodeAndInstantiateContractResponse, error) { + out := new(MsgStoreCodeAndInstantiateContractResponse) + err := c.cc.Invoke(ctx, "/cosmwasm.wasm.v1beta1.Msg/StoreCodeAndInstantiateContract", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *msgClient) ExecuteContract(ctx context.Context, in *MsgExecuteContract, opts ...grpc.CallOption) (*MsgExecuteContractResponse, error) { out := new(MsgExecuteContractResponse) err := c.cc.Invoke(ctx, "/cosmwasm.wasm.v1beta1.Msg/ExecuteContract", in, out, opts...) @@ -693,12 +901,23 @@ func (c *msgClient) ClearAdmin(ctx context.Context, in *MsgClearAdmin, opts ...g return out, nil } +func (c *msgClient) UpdateContractStatus(ctx context.Context, in *MsgUpdateContractStatus, opts ...grpc.CallOption) (*MsgUpdateContractStatusResponse, error) { + out := new(MsgUpdateContractStatusResponse) + err := c.cc.Invoke(ctx, "/cosmwasm.wasm.v1beta1.Msg/UpdateContractStatus", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // StoreCode to submit Wasm code to the system StoreCode(context.Context, *MsgStoreCode) (*MsgStoreCodeResponse, error) - // Instantiate creates a new smart contract instance for the given code id. + // Instantiate creates a new smart contract instance for the given code id. InstantiateContract(context.Context, *MsgInstantiateContract) (*MsgInstantiateContractResponse, error) + // Store Wasm code and Instantiate a new contract + StoreCodeAndInstantiateContract(context.Context, *MsgStoreCodeAndInstantiateContract) (*MsgStoreCodeAndInstantiateContractResponse, error) // Execute submits the given message data to a smart contract ExecuteContract(context.Context, *MsgExecuteContract) (*MsgExecuteContractResponse, error) // Migrate runs a code upgrade/ downgrade for a smart contract @@ -707,6 +926,8 @@ type MsgServer interface { UpdateAdmin(context.Context, *MsgUpdateAdmin) (*MsgUpdateAdminResponse, error) // ClearAdmin removes any admin stored for a smart contract ClearAdmin(context.Context, *MsgClearAdmin) (*MsgClearAdminResponse, error) + // UpdateContractStatus sets a new status for a smart contract + UpdateContractStatus(context.Context, *MsgUpdateContractStatus) (*MsgUpdateContractStatusResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -719,6 +940,9 @@ func (*UnimplementedMsgServer) StoreCode(ctx context.Context, req *MsgStoreCode) func (*UnimplementedMsgServer) InstantiateContract(ctx context.Context, req *MsgInstantiateContract) (*MsgInstantiateContractResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method InstantiateContract not implemented") } +func (*UnimplementedMsgServer) StoreCodeAndInstantiateContract(ctx context.Context, req *MsgStoreCodeAndInstantiateContract) (*MsgStoreCodeAndInstantiateContractResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method StoreCodeAndInstantiateContract not implemented") +} func (*UnimplementedMsgServer) ExecuteContract(ctx context.Context, req *MsgExecuteContract) (*MsgExecuteContractResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ExecuteContract not implemented") } @@ -731,6 +955,9 @@ func (*UnimplementedMsgServer) UpdateAdmin(ctx context.Context, req *MsgUpdateAd func (*UnimplementedMsgServer) ClearAdmin(ctx context.Context, req *MsgClearAdmin) (*MsgClearAdminResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ClearAdmin not implemented") } +func (*UnimplementedMsgServer) UpdateContractStatus(ctx context.Context, req *MsgUpdateContractStatus) (*MsgUpdateContractStatusResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateContractStatus not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -772,6 +999,24 @@ func _Msg_InstantiateContract_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _Msg_StoreCodeAndInstantiateContract_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgStoreCodeAndInstantiateContract) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).StoreCodeAndInstantiateContract(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmwasm.wasm.v1beta1.Msg/StoreCodeAndInstantiateContract", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).StoreCodeAndInstantiateContract(ctx, req.(*MsgStoreCodeAndInstantiateContract)) + } + return interceptor(ctx, in, info, handler) +} + func _Msg_ExecuteContract_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgExecuteContract) if err := dec(in); err != nil { @@ -844,6 +1089,24 @@ func _Msg_ClearAdmin_Handler(srv interface{}, ctx context.Context, dec func(inte return interceptor(ctx, in, info, handler) } +func _Msg_UpdateContractStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateContractStatus) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateContractStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmwasm.wasm.v1beta1.Msg/UpdateContractStatus", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateContractStatus(ctx, req.(*MsgUpdateContractStatus)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "cosmwasm.wasm.v1beta1.Msg", HandlerType: (*MsgServer)(nil), @@ -856,6 +1119,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "InstantiateContract", Handler: _Msg_InstantiateContract_Handler, }, + { + MethodName: "StoreCodeAndInstantiateContract", + Handler: _Msg_StoreCodeAndInstantiateContract_Handler, + }, { MethodName: "ExecuteContract", Handler: _Msg_ExecuteContract_Handler, @@ -872,6 +1139,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "ClearAdmin", Handler: _Msg_ClearAdmin_Handler, }, + { + MethodName: "UpdateContractStatus", + Handler: _Msg_UpdateContractStatus_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "tx.proto", @@ -1075,7 +1346,7 @@ func (m *MsgInstantiateContractResponse) MarshalToSizedBuffer(dAtA []byte) (int, return len(dAtA) - i, nil } -func (m *MsgExecuteContract) Marshal() (dAtA []byte, err error) { +func (m *MsgStoreCodeAndInstantiateContract) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1085,12 +1356,12 @@ func (m *MsgExecuteContract) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgExecuteContract) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgStoreCodeAndInstantiateContract) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgExecuteContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgStoreCodeAndInstantiateContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1106,20 +1377,60 @@ func (m *MsgExecuteContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintTx(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x2a + dAtA[i] = 0x4a } } - if len(m.Msg) > 0 { - i -= len(m.Msg) - copy(dAtA[i:], m.Msg) - i = encodeVarintTx(dAtA, i, uint64(len(m.Msg))) + if len(m.InitMsg) > 0 { + i -= len(m.InitMsg) + copy(dAtA[i:], m.InitMsg) + i = encodeVarintTx(dAtA, i, uint64(len(m.InitMsg))) + i-- + dAtA[i] = 0x42 + } + if len(m.Label) > 0 { + i -= len(m.Label) + copy(dAtA[i:], m.Label) + i = encodeVarintTx(dAtA, i, uint64(len(m.Label))) + i-- + dAtA[i] = 0x3a + } + if len(m.Admin) > 0 { + i -= len(m.Admin) + copy(dAtA[i:], m.Admin) + i = encodeVarintTx(dAtA, i, uint64(len(m.Admin))) + i-- + dAtA[i] = 0x32 + } + if m.InstantiatePermission != nil { + { + size, err := m.InstantiatePermission.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + if len(m.Builder) > 0 { + i -= len(m.Builder) + copy(dAtA[i:], m.Builder) + i = encodeVarintTx(dAtA, i, uint64(len(m.Builder))) + i-- + dAtA[i] = 0x22 + } + if len(m.Source) > 0 { + i -= len(m.Source) + copy(dAtA[i:], m.Source) + i = encodeVarintTx(dAtA, i, uint64(len(m.Source))) i-- dAtA[i] = 0x1a } - if len(m.Contract) > 0 { - i -= len(m.Contract) - copy(dAtA[i:], m.Contract) - i = encodeVarintTx(dAtA, i, uint64(len(m.Contract))) + if len(m.WASMByteCode) > 0 { + i -= len(m.WASMByteCode) + copy(dAtA[i:], m.WASMByteCode) + i = encodeVarintTx(dAtA, i, uint64(len(m.WASMByteCode))) i-- dAtA[i] = 0x12 } @@ -1133,7 +1444,7 @@ func (m *MsgExecuteContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgExecuteContractResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgStoreCodeAndInstantiateContractResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1143,12 +1454,12 @@ func (m *MsgExecuteContractResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgExecuteContractResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgStoreCodeAndInstantiateContractResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgExecuteContractResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgStoreCodeAndInstantiateContractResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1158,12 +1469,24 @@ func (m *MsgExecuteContractResponse) MarshalToSizedBuffer(dAtA []byte) (int, err copy(dAtA[i:], m.Data) i = encodeVarintTx(dAtA, i, uint64(len(m.Data))) i-- - dAtA[i] = 0xa + dAtA[i] = 0x1a + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTx(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x12 + } + if m.CodeID != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.CodeID)) + i-- + dAtA[i] = 0x8 } return len(dAtA) - i, nil } -func (m *MsgMigrateContract) Marshal() (dAtA []byte, err error) { +func (m *MsgExecuteContract) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1173,24 +1496,112 @@ func (m *MsgMigrateContract) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgMigrateContract) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgExecuteContract) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgMigrateContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgExecuteContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.MigrateMsg) > 0 { - i -= len(m.MigrateMsg) - copy(dAtA[i:], m.MigrateMsg) - i = encodeVarintTx(dAtA, i, uint64(len(m.MigrateMsg))) - i-- - dAtA[i] = 0x22 - } - if m.CodeID != 0 { + if len(m.Funds) > 0 { + for iNdEx := len(m.Funds) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Funds[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if len(m.Msg) > 0 { + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintTx(dAtA, i, uint64(len(m.Msg))) + i-- + dAtA[i] = 0x1a + } + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintTx(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgExecuteContractResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgExecuteContractResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgExecuteContractResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintTx(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgMigrateContract) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgMigrateContract) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgMigrateContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.MigrateMsg) > 0 { + i -= len(m.MigrateMsg) + copy(dAtA[i:], m.MigrateMsg) + i = encodeVarintTx(dAtA, i, uint64(len(m.MigrateMsg))) + i-- + dAtA[i] = 0x22 + } + if m.CodeID != 0 { i = encodeVarintTx(dAtA, i, uint64(m.CodeID)) i-- dAtA[i] = 0x18 @@ -1369,6 +1780,71 @@ func (m *MsgClearAdminResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgUpdateContractStatus) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateContractStatus) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateContractStatus) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Status != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Status)) + i-- + dAtA[i] = 0x18 + } + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintTx(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateContractStatusResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateContractStatusResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateContractStatusResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1472,6 +1948,73 @@ func (m *MsgInstantiateContractResponse) Size() (n int) { return n } +func (m *MsgStoreCodeAndInstantiateContract) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.WASMByteCode) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Source) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Builder) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.InstantiatePermission != nil { + l = m.InstantiatePermission.Size() + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Admin) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Label) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.InitMsg) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Funds) > 0 { + for _, e := range m.Funds { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgStoreCodeAndInstantiateContractResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.CodeID != 0 { + n += 1 + sovTx(uint64(m.CodeID)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + func (m *MsgExecuteContract) Size() (n int) { if m == nil { return 0 @@ -1605,6 +2148,35 @@ func (m *MsgClearAdminResponse) Size() (n int) { return n } +func (m *MsgUpdateContractStatus) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Contract) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Status != 0 { + n += 1 + sovTx(uint64(m.Status)) + } + return n +} + +func (m *MsgUpdateContractStatusResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1927,7 +2499,454 @@ func (m *MsgInstantiateContract) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Admin = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CodeID", wireType) + } + m.CodeID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CodeID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Label", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Label = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InitMsg", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.InitMsg = append(m.InitMsg[:0], dAtA[iNdEx:postIndex]...) + if m.InitMsg == nil { + m.InitMsg = []byte{} + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Funds", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Funds = append(m.Funds, types.Coin{}) + if err := m.Funds[len(m.Funds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgInstantiateContractResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgInstantiateContractResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgInstantiateContractResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgStoreCodeAndInstantiateContract) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgStoreCodeAndInstantiateContract: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgStoreCodeAndInstantiateContract: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WASMByteCode", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WASMByteCode = append(m.WASMByteCode[:0], dAtA[iNdEx:postIndex]...) + if m.WASMByteCode == nil { + m.WASMByteCode = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Source", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Source = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Builder", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1955,13 +2974,13 @@ func (m *MsgInstantiateContract) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Sender = string(dAtA[iNdEx:postIndex]) + m.Builder = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field InstantiatePermission", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1971,29 +2990,33 @@ func (m *MsgInstantiateContract) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Admin = string(dAtA[iNdEx:postIndex]) + if m.InstantiatePermission == nil { + m.InstantiatePermission = &AccessConfig{} + } + if err := m.InstantiatePermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CodeID", wireType) + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) } - m.CodeID = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -2003,12 +3026,25 @@ func (m *MsgInstantiateContract) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.CodeID |= uint64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - case 4: + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Admin = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Label", wireType) } @@ -2040,7 +3076,7 @@ func (m *MsgInstantiateContract) Unmarshal(dAtA []byte) error { } m.Label = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 5: + case 8: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field InitMsg", wireType) } @@ -2074,7 +3110,7 @@ func (m *MsgInstantiateContract) Unmarshal(dAtA []byte) error { m.InitMsg = []byte{} } iNdEx = postIndex - case 6: + case 9: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Funds", wireType) } @@ -2129,7 +3165,7 @@ func (m *MsgInstantiateContract) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgInstantiateContractResponse) Unmarshal(dAtA []byte) error { +func (m *MsgStoreCodeAndInstantiateContractResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2152,13 +3188,32 @@ func (m *MsgInstantiateContractResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgInstantiateContractResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgStoreCodeAndInstantiateContractResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgInstantiateContractResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgStoreCodeAndInstantiateContractResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CodeID", wireType) + } + m.CodeID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CodeID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) } @@ -2190,7 +3245,7 @@ func (m *MsgInstantiateContractResponse) Unmarshal(dAtA []byte) error { } m.Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) } @@ -3122,6 +4177,189 @@ func (m *MsgClearAdminResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateContractStatus) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateContractStatus: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateContractStatus: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Contract = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + m.Status = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Status |= ContractStatus(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateContractStatusResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateContractStatusResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateContractStatusResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/wasm/internal/types/tx.proto b/x/wasm/internal/types/tx.proto index f0bff57f57..9179bd51ec 100644 --- a/x/wasm/internal/types/tx.proto +++ b/x/wasm/internal/types/tx.proto @@ -12,8 +12,11 @@ option (gogoproto.goproto_getters_all) = false; service Msg { // StoreCode to submit Wasm code to the system rpc StoreCode(MsgStoreCode) returns (MsgStoreCodeResponse); - // Instantiate creates a new smart contract instance for the given code id. + // Instantiate creates a new smart contract instance for the given code id. rpc InstantiateContract(MsgInstantiateContract) returns (MsgInstantiateContractResponse); + // Store Wasm code and Instantiate a new contract + rpc StoreCodeAndInstantiateContract(MsgStoreCodeAndInstantiateContract) + returns (MsgStoreCodeAndInstantiateContractResponse); // Execute submits the given message data to a smart contract rpc ExecuteContract(MsgExecuteContract) returns (MsgExecuteContractResponse); // Migrate runs a code upgrade/ downgrade for a smart contract @@ -22,6 +25,8 @@ service Msg { rpc UpdateAdmin(MsgUpdateAdmin) returns (MsgUpdateAdminResponse); // ClearAdmin removes any admin stored for a smart contract rpc ClearAdmin(MsgClearAdmin) returns (MsgClearAdminResponse); + // UpdateContractStatus sets a new status for a smart contract + rpc UpdateContractStatus(MsgUpdateContractStatus) returns (MsgUpdateContractStatusResponse); } // MsgStoreCode submit Wasm code to the system @@ -67,6 +72,38 @@ message MsgInstantiateContractResponse { bytes data = 2; } +// MsgStoreCodeAndInstantiateContract submit Wasm code to the system and instantiate a contract using it. +message MsgStoreCodeAndInstantiateContract { + // Sender is the that actor that signed the messages + string sender = 1; + // WASMByteCode can be raw or gzip compressed + bytes wasm_byte_code = 2 [(gogoproto.customname) = "WASMByteCode"]; + // Source is a valid absolute HTTPS URI to the contract's source code, optional + string source = 3; + // Builder is a valid docker image name with tag, optional + string builder = 4; + // InstantiatePermission access control to apply on contract creation, optional + AccessConfig instantiate_permission = 5; + // Admin is an optional address that can execute migrations + string admin = 6; + // Label is optional metadata to be stored with a contract instance. + string label = 7; + // InitMsg json encoded message to be passed to the contract on instantiation + bytes init_msg = 8 [(gogoproto.casttype) = "encoding/json.RawMessage"]; + // Funds coins that are transferred to the contract on instantiation + repeated lbm.base.v1beta1.Coin funds = 9 + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/line/lbm-sdk/v2/types.Coins"]; +} +// MsgStoreCodeAndInstantiateContractResponse returns store and instantiate result data. +message MsgStoreCodeAndInstantiateContractResponse { + // CodeID is the reference to the stored WASM code + uint64 code_id = 1 [(gogoproto.customname) = "CodeID"]; + // Address is the bech32 address of the new contract instance. + string address = 2; + // Data contains base64-encoded bytes to returned from the contract + bytes data = 3; +} + // MsgExecuteContract submits the given message data to a smart contract message MsgExecuteContract { // Sender is the that actor that signed the messages @@ -128,3 +165,16 @@ message MsgClearAdmin { // MsgClearAdminResponse returns empty data message MsgClearAdminResponse {} + +// MsgUpdateContractStatus sets a new status for a smart contract +message MsgUpdateContractStatus { + // Sender is the that actor that signed the messages + string sender = 1; + // Contract is the address of the smart contract + string contract = 2; + // Status to be set + ContractStatus status = 3; +} + +// MsgUpdateContractStatusResponse returns empty data +message MsgUpdateContractStatusResponse {} diff --git a/x/wasm/internal/types/tx_test.go b/x/wasm/internal/types/tx_test.go index 6630125de6..0c54c3d5d2 100644 --- a/x/wasm/internal/types/tx_test.go +++ b/x/wasm/internal/types/tx_test.go @@ -239,6 +239,156 @@ func TestInstantiateContractValidation(t *testing.T) { } } +func TestStoreCodeAndInstantiateContractValidation(t *testing.T) { + bad, err := sdk.AccAddressFromHex("012345") + require.NoError(t, err) + badAddress := bad.String() + require.NoError(t, err) + // proper address size + goodAddress := sdk.AccAddress(make([]byte, 20)).String() + + cases := map[string]struct { + msg MsgStoreCodeAndInstantiateContract + valid bool + }{ + "empty": { + msg: MsgStoreCodeAndInstantiateContract{}, + valid: false, + }, + "correct minimal": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + WASMByteCode: []byte("foo"), + Label: "foo", + InitMsg: []byte("{}"), + }, + valid: true, + }, + "missing code": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + Label: "foo", + InitMsg: []byte("{}"), + }, + valid: false, + }, + "missing label": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + WASMByteCode: []byte("foo"), + InitMsg: []byte("{}"), + }, + valid: false, + }, + "missing init message": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + WASMByteCode: []byte("foo"), + Label: "foo", + }, + valid: false, + }, + "correct maximal": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + WASMByteCode: []byte("foo"), + Builder: "confio/cosmwasm-opt:0.6.2", + Source: "https://crates.io/api/v1/crates/cw-erc20/0.1.0/download", + Label: "foo", + InitMsg: []byte(`{"some": "data"}`), + Funds: sdk.Coins{sdk.Coin{Denom: "foobar", Amount: sdk.NewInt(200)}}, + }, + valid: true, + }, + "invalid builder": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + WASMByteCode: []byte("foo"), + Builder: "-bad-opt:0.6.2", + Source: "https://crates.io/api/v1/crates/cw-erc20/0.1.0/download", + Label: "foo", + InitMsg: []byte(`{"some": "data"}`), + Funds: sdk.Coins{sdk.Coin{Denom: "foobar", Amount: sdk.NewInt(200)}}, + }, + valid: false, + }, + "invalid source scheme": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + WASMByteCode: []byte("foo"), + Builder: "cosmwasm-opt:0.6.2", + Source: "ftp://crates.io/api/download.tar.gz", + Label: "foo", + InitMsg: []byte(`{"some": "data"}`), + Funds: sdk.Coins{sdk.Coin{Denom: "foobar", Amount: sdk.NewInt(200)}}, + }, + valid: false, + }, + "invalid source format": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + WASMByteCode: []byte("foo"), + Builder: "cosmwasm-opt:0.6.2", + Source: "/api/download-ss", + Label: "foo", + InitMsg: []byte(`{"some": "data"}`), + Funds: sdk.Coins{sdk.Coin{Denom: "foobar", Amount: sdk.NewInt(200)}}, + }, + valid: false, + }, + "invalid InstantiatePermission": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + WASMByteCode: []byte("foo"), + InstantiatePermission: &AccessConfig{Permission: AccessTypeOnlyAddress, Address: badAddress}, + Label: "foo", + InitMsg: []byte(`{"some": "data"}`), + Funds: sdk.Coins{sdk.Coin{Denom: "foobar", Amount: sdk.NewInt(200)}}, + }, + valid: false, + }, + "negative funds": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + WASMByteCode: []byte("foo"), + InitMsg: []byte(`{"some": "data"}`), + // we cannot use sdk.NewCoin() constructors as they panic on creating invalid data (before we can test) + Funds: sdk.Coins{sdk.Coin{Denom: "foobar", Amount: sdk.NewInt(-200)}}, + }, + valid: false, + }, + "non json init msg": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: goodAddress, + WASMByteCode: []byte("foo"), + Label: "foo", + InitMsg: []byte("invalid-json"), + }, + valid: false, + }, + "bad sender minimal": { + msg: MsgStoreCodeAndInstantiateContract{ + Sender: badAddress, + WASMByteCode: []byte("foo"), + Label: "foo", + InitMsg: []byte("{}"), + }, + valid: false, + }, + } + + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + err := tc.msg.ValidateBasic() + if tc.valid { + assert.NoError(t, err) + } else { + assert.Error(t, err) + } + }) + } +} + func TestExecuteContractValidation(t *testing.T) { bad, err := sdk.AccAddressFromHex("012345") require.NoError(t, err) @@ -557,3 +707,66 @@ func TestMsgMigrateContract(t *testing.T) { }) } } + +func TestMsgUpdateContractStatus(t *testing.T) { + bad, err := sdk.AccAddressFromHex("012345") + require.NoError(t, err) + badAddress := bad.String() + // proper address size + goodAddress := sdk.AccAddress(make([]byte, 20)).String() + anotherGoodAddress := sdk.AccAddress(bytes.Repeat([]byte{0x2}, 20)).String() + + specs := map[string]struct { + src MsgUpdateContractStatus + expErr bool + }{ + "all good": { + src: MsgUpdateContractStatus{ + Sender: goodAddress, + Status: ContractStatusInactive, + Contract: anotherGoodAddress, + }, + }, + "status required": { + src: MsgUpdateContractStatus{ + Sender: goodAddress, + Contract: anotherGoodAddress, + }, + expErr: true, + }, + "bad sender": { + src: MsgUpdateContractStatus{ + Sender: badAddress, + Status: ContractStatusInactive, + Contract: anotherGoodAddress, + }, + expErr: true, + }, + "bad status": { + src: MsgUpdateContractStatus{ + Sender: goodAddress, + Status: 3, + Contract: anotherGoodAddress, + }, + expErr: true, + }, + "bad contract addr": { + src: MsgUpdateContractStatus{ + Sender: goodAddress, + Status: ContractStatusInactive, + Contract: badAddress, + }, + expErr: true, + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + err := spec.src.ValidateBasic() + if spec.expErr { + require.Error(t, err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/wasm/internal/types/types.go b/x/wasm/internal/types/types.go index 3ff34206ad..db43e6d419 100644 --- a/x/wasm/internal/types/types.go +++ b/x/wasm/internal/types/types.go @@ -1,9 +1,11 @@ package types import ( + "encoding/json" "fmt" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/gogo/protobuf/jsonpb" sdk "github.com/line/lbm-sdk/v2/types" sdkerrors "github.com/line/lbm-sdk/v2/types/errors" ) @@ -14,6 +16,44 @@ const ( defaultContractDebugMode = false ) +var AllContractStatus = []ContractStatus{ + ContractStatusInactive, + ContractStatusActive, +} + +func (c ContractStatus) String() string { + switch c { + case ContractStatusActive: + return "Active" + case ContractStatusInactive: + return "Inactive" + } + return "Unspecified" +} + +func (c *ContractStatus) UnmarshalText(text []byte) error { + for _, v := range AllContractStatus { + if v.String() == string(text) { + *c = v + return nil + } + } + *c = ContractStatusUnspecified + return nil +} + +func (c ContractStatus) MarshalText() ([]byte, error) { + return []byte(c.String()), nil +} + +func (c *ContractStatus) MarshalJSONPB(_ *jsonpb.Marshaler) ([]byte, error) { + return json.Marshal(c) +} + +func (c *ContractStatus) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, data []byte) error { + return json.Unmarshal(data, c) +} + func (m Model) ValidateBasic() error { if len(m.Key) == 0 { return sdkerrors.Wrap(ErrEmpty, "key") @@ -54,7 +94,7 @@ func NewCodeInfo(codeHash []byte, creator sdk.AccAddress, source string, builder var AllCodeHistoryTypes = []ContractCodeHistoryOperationType{ContractCodeHistoryOperationTypeGenesis, ContractCodeHistoryOperationTypeInit, ContractCodeHistoryOperationTypeMigrate} // NewContractInfo creates a new instance of a given WASM contract info -func NewContractInfo(codeID uint64, creator, admin sdk.AccAddress, label string, createdAt *AbsoluteTxPosition) ContractInfo { +func NewContractInfo(codeID uint64, creator, admin sdk.AccAddress, label string, createdAt *AbsoluteTxPosition, status ContractStatus) ContractInfo { var adminAddr string if !admin.Empty() { adminAddr = admin.String() @@ -65,6 +105,7 @@ func NewContractInfo(codeID uint64, creator, admin sdk.AccAddress, label string, Admin: adminAddr, Label: label, Created: createdAt, + Status: status, } } func (c *ContractInfo) ValidateBasic() error { @@ -82,6 +123,16 @@ func (c *ContractInfo) ValidateBasic() error { if err := validateLabel(c.Label); err != nil { return sdkerrors.Wrap(err, "label") } + found := false + for _, v := range AllContractStatus { + if c.Status == v { + found = true + break + } + } + if !found || c.Status == ContractStatusUnspecified { + return sdkerrors.Wrap(ErrInvalidMsg, "invalid status") + } return nil } diff --git a/x/wasm/internal/types/types.pb.go b/x/wasm/internal/types/types.pb.go index dbc9dd4ef4..c90aa4630b 100644 --- a/x/wasm/internal/types/types.pb.go +++ b/x/wasm/internal/types/types.pb.go @@ -58,6 +58,34 @@ func (AccessType) EnumDescriptor() ([]byte, []int) { return fileDescriptor_d938547f84707355, []int{0} } +// ContractStatus types +type ContractStatus int32 + +const ( + // ContractStatus unspecified + ContractStatusUnspecified ContractStatus = 0 + // ContractStatus active + ContractStatusActive ContractStatus = 1 + // ContractStatus inactive + ContractStatusInactive ContractStatus = 2 +) + +var ContractStatus_name = map[int32]string{ + 0: "CONTRACT_STATUS_UNSPECIFIED", + 1: "CONTRACT_STATUS_ACTIVE", + 2: "CONTRACT_STATUS_INACTIVE", +} + +var ContractStatus_value = map[string]int32{ + "CONTRACT_STATUS_UNSPECIFIED": 0, + "CONTRACT_STATUS_ACTIVE": 1, + "CONTRACT_STATUS_INACTIVE": 2, +} + +func (ContractStatus) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d938547f84707355, []int{1} +} + // ContractCodeHistoryOperationType actions that caused a code change type ContractCodeHistoryOperationType int32 @@ -91,7 +119,7 @@ func (x ContractCodeHistoryOperationType) String() string { } func (ContractCodeHistoryOperationType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_d938547f84707355, []int{1} + return fileDescriptor_d938547f84707355, []int{2} } // AccessTypeParam @@ -175,10 +203,11 @@ var xxx_messageInfo_AccessConfig proto.InternalMessageInfo type Params struct { CodeUploadAccess AccessConfig `protobuf:"bytes,1,opt,name=code_upload_access,json=codeUploadAccess,proto3" json:"code_upload_access" yaml:"code_upload_access"` InstantiateDefaultPermission AccessType `protobuf:"varint,2,opt,name=instantiate_default_permission,json=instantiateDefaultPermission,proto3,enum=cosmwasm.wasm.v1beta1.AccessType" json:"instantiate_default_permission,omitempty" yaml:"instantiate_default_permission"` - MaxWasmCodeSize uint64 `protobuf:"varint,3,opt,name=max_wasm_code_size,json=maxWasmCodeSize,proto3" json:"max_wasm_code_size,omitempty" yaml:"max_wasm_code_size"` - GasMultiplier uint64 `protobuf:"varint,4,opt,name=gas_multiplier,json=gasMultiplier,proto3" json:"gas_multiplier,omitempty" yaml:"max_gas"` - InstanceCost uint64 `protobuf:"varint,5,opt,name=instance_cost,json=instanceCost,proto3" json:"instance_cost,omitempty" yaml:"instance_cost"` - CompileCost uint64 `protobuf:"varint,6,opt,name=compile_cost,json=compileCost,proto3" json:"compile_cost,omitempty" yaml:"compile_cost"` + ContractStatusAccess AccessConfig `protobuf:"bytes,3,opt,name=contract_status_access,json=contractStatusAccess,proto3" json:"contract_status_access" yaml:"contract_status_access"` + MaxWasmCodeSize uint64 `protobuf:"varint,4,opt,name=max_wasm_code_size,json=maxWasmCodeSize,proto3" json:"max_wasm_code_size,omitempty" yaml:"max_wasm_code_size"` + GasMultiplier uint64 `protobuf:"varint,5,opt,name=gas_multiplier,json=gasMultiplier,proto3" json:"gas_multiplier,omitempty" yaml:"max_gas"` + InstanceCost uint64 `protobuf:"varint,6,opt,name=instance_cost,json=instanceCost,proto3" json:"instance_cost,omitempty" yaml:"instance_cost"` + CompileCost uint64 `protobuf:"varint,7,opt,name=compile_cost,json=compileCost,proto3" json:"compile_cost,omitempty" yaml:"compile_cost"` } func (m *Params) Reset() { *m = Params{} } @@ -274,6 +303,8 @@ type ContractInfo struct { // This data should kept internal and not be exposed via query results. Just use for sorting Created *AbsoluteTxPosition `protobuf:"bytes,5,opt,name=created,proto3" json:"created,omitempty"` IBCPortID string `protobuf:"bytes,6,opt,name=ibc_port_id,json=ibcPortId,proto3" json:"ibc_port_id,omitempty"` + // Status is a status of a contract + Status ContractStatus `protobuf:"varint,7,opt,name=status,proto3,enum=cosmwasm.wasm.v1beta1.ContractStatus" json:"status,omitempty"` } func (m *ContractInfo) Reset() { *m = ContractInfo{} } @@ -436,6 +467,7 @@ var xxx_messageInfo_Model proto.InternalMessageInfo func init() { proto.RegisterEnum("cosmwasm.wasm.v1beta1.AccessType", AccessType_name, AccessType_value) + proto.RegisterEnum("cosmwasm.wasm.v1beta1.ContractStatus", ContractStatus_name, ContractStatus_value) proto.RegisterEnum("cosmwasm.wasm.v1beta1.ContractCodeHistoryOperationType", ContractCodeHistoryOperationType_name, ContractCodeHistoryOperationType_value) proto.RegisterType((*AccessTypeParam)(nil), "cosmwasm.wasm.v1beta1.AccessTypeParam") proto.RegisterType((*AccessConfig)(nil), "cosmwasm.wasm.v1beta1.AccessConfig") @@ -450,83 +482,92 @@ func init() { func init() { proto.RegisterFile("types.proto", fileDescriptor_d938547f84707355) } var fileDescriptor_d938547f84707355 = []byte{ - // 1213 bytes of a gzipped FileDescriptorProto + // 1349 bytes of a gzipped FileDesc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0x38, 0x7b, 0x7d, 0xb6, 0xec, 0x2e, 0xa9, 0x7d, 0xce, 0x46, 0x4c, 0x84, - 0x8d, 0x88, 0xce, 0xcf, 0x90, 0x44, 0x1b, 0xea, 0x3f, 0x0a, 0x48, 0x6b, 0xcc, 0x17, 0x01, 0xb6, - 0x85, 0xd4, 0x74, 0x15, 0x2c, 0x49, 0x4d, 0xd4, 0x91, 0x8a, 0x12, 0x55, 0x70, 0x32, 0x2c, 0x24, - 0xa5, 0xe4, 0x1a, 0x4a, 0x86, 0x5b, 0x86, 0xf3, 0x06, 0x6d, 0xab, 0x60, 0x11, 0x3b, 0x1e, 0xf5, - 0xc7, 0xd2, 0xa2, 0x20, 0x5c, 0x75, 0xb1, 0x45, 0xdc, 0xb1, 0xae, 0x28, 0x80, 0xda, 0x98, 0x85, - 0x38, 0x63, 0x29, 0xd7, 0x5e, 0x27, 0xc5, 0xe2, 0xcc, 0xed, 0x09, 0xd2, 0xee, 0x37, 0x19, 0xa7, - 0x82, 0x32, 0x1f, 0x4d, 0x90, 0xf0, 0x26, 0x58, 0xa1, 0x96, 0x6d, 0x76, 0x59, 0x20, 0xc2, 0x33, - 0x27, 0xe5, 0x98, 0x9f, 0x39, 0x19, 0x16, 0x52, 0x46, 0x55, 0x6b, 0xb2, 0x40, 0x18, 0x35, 0x94, - 0xa2, 0x96, 0x2d, 0x1f, 0x9d, 0xad, 0xc4, 0x5f, 0xe1, 0x8c, 0x7f, 0xb3, 0x00, 0xb2, 0x13, 0xd5, - 0xa1, 0xb4, 0x6d, 0xca, 0x05, 0x0b, 0x06, 0xba, 0x2f, 0x82, 0x01, 0xdc, 0x05, 0x29, 0xd6, 0x25, - 0x01, 0x16, 0xd3, 0x7f, 0xa3, 0x3b, 0xaf, 0x39, 0xd8, 0x2b, 0x38, 0x1a, 0x13, 0x68, 0x38, 0x7f, - 0x68, 0xca, 0x34, 0x6b, 0xec, 0xc2, 0x6b, 0x8d, 0xd5, 0xc0, 0x52, 0xaf, 0xe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x8d, 0x0d, 0xbd, 0x52, 0x2d, 0xa3, 0x1d, 0xa3, 0xbc, 0x55, 0x44, 0xb9, + 0xaa, 0x5e, 0x2e, 0xbd, 0xae, 0xcf, 0xd9, 0x6e, 0x2f, 0x7d, 0xfd, 0x24, 0xee, 0x51, 0x17, 0xee, + 0x83, 0xab, 0x63, 0x95, 0xd1, 0x4b, 0x7a, 0x35, 0xa6, 0x24, 0x56, 0xba, 0xbd, 0xf4, 0x3b, 0x27, + 0xf1, 0xeb, 0x0e, 0x15, 0xf0, 0x0b, 0xb0, 0x3a, 0x16, 0xf1, 0xa6, 0x7e, 0x17, 0xe5, 0xaa, 0x9e, + 0x79, 0xd7, 0xbb, 0xbd, 0xf4, 0xbb, 0x27, 0x71, 0x6f, 0xd2, 0xba, 0x8b, 0x05, 0x19, 0x9b, 0xfe, + 0x6e, 0xb1, 0x54, 0xac, 0xe8, 0x95, 0xd8, 0xc4, 0x78, 0xf4, 0x77, 0x89, 0x43, 0x38, 0xe5, 0x89, + 0x49, 0xaf, 0x59, 0x79, 0xf4, 0xf4, 0xef, 0x64, 0xe8, 0xc9, 0x41, 0x52, 0x79, 0x7a, 0x90, 0x54, + 0x9e, 0x1d, 0x24, 0x95, 0xbf, 0x0e, 0x92, 0xca, 0xb7, 0xcf, 0x93, 0xa1, 0x67, 0xcf, 0x93, 0xa1, + 0x3f, 0x9f, 0x27, 0x43, 0x9f, 0xdf, 0x3c, 0x7e, 0x98, 0xed, 0x5a, 0xe3, 0x06, 0xb7, 0x1e, 0x66, + 0xf7, 0xd7, 0xb2, 0xed, 0xac, 0x77, 0x63, 0x65, 0xa9, 0x23, 0x88, 0xeb, 0x60, 0x3b, 0x2b, 0xff, + 0x56, 0xd7, 0x22, 0xf2, 0xaf, 0xf2, 0x7b, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0xac, 0x3d, 0x57, + 0xeb, 0x66, 0x0b, 0x00, 0x00, } func (this *AccessTypeParam) Equal(that interface{}) bool { @@ -605,6 +646,9 @@ func (this *Params) Equal(that interface{}) bool { if this.InstantiateDefaultPermission != that1.InstantiateDefaultPermission { return false } + if !this.ContractStatusAccess.Equal(&that1.ContractStatusAccess) { + return false + } if this.MaxWasmCodeSize != that1.MaxWasmCodeSize { return false } @@ -692,6 +736,9 @@ func (this *ContractInfo) Equal(that interface{}) bool { if this.IBCPortID != that1.IBCPortID { return false } + if this.Status != that1.Status { + return false + } return true } func (this *ContractCodeHistoryEntry) Equal(that interface{}) bool { @@ -867,23 +914,33 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m.CompileCost != 0 { i = encodeVarintTypes(dAtA, i, uint64(m.CompileCost)) i-- - dAtA[i] = 0x30 + dAtA[i] = 0x38 } if m.InstanceCost != 0 { i = encodeVarintTypes(dAtA, i, uint64(m.InstanceCost)) i-- - dAtA[i] = 0x28 + dAtA[i] = 0x30 } if m.GasMultiplier != 0 { i = encodeVarintTypes(dAtA, i, uint64(m.GasMultiplier)) i-- - dAtA[i] = 0x20 + dAtA[i] = 0x28 } if m.MaxWasmCodeSize != 0 { i = encodeVarintTypes(dAtA, i, uint64(m.MaxWasmCodeSize)) i-- - dAtA[i] = 0x18 + dAtA[i] = 0x20 } + { + size, err := m.ContractStatusAccess.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a if m.InstantiateDefaultPermission != 0 { i = encodeVarintTypes(dAtA, i, uint64(m.InstantiateDefaultPermission)) i-- @@ -983,6 +1040,11 @@ func (m *ContractInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Status != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Status)) + i-- + dAtA[i] = 0x38 + } if len(m.IBCPortID) > 0 { i -= len(m.IBCPortID) copy(dAtA[i:], m.IBCPortID) @@ -1203,6 +1265,8 @@ func (m *Params) Size() (n int) { if m.InstantiateDefaultPermission != 0 { n += 1 + sovTypes(uint64(m.InstantiateDefaultPermission)) } + l = m.ContractStatusAccess.Size() + n += 1 + l + sovTypes(uint64(l)) if m.MaxWasmCodeSize != 0 { n += 1 + sovTypes(uint64(m.MaxWasmCodeSize)) } @@ -1274,6 +1338,9 @@ func (m *ContractInfo) Size() (n int) { if l > 0 { n += 1 + l + sovTypes(uint64(l)) } + if m.Status != 0 { + n += 1 + sovTypes(uint64(m.Status)) + } return n } @@ -1590,6 +1657,39 @@ func (m *Params) Unmarshal(dAtA []byte) error { } } case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContractStatusAccess", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ContractStatusAccess.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field MaxWasmCodeSize", wireType) } @@ -1608,7 +1708,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } - case 4: + case 5: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field GasMultiplier", wireType) } @@ -1627,7 +1727,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } - case 5: + case 6: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field InstanceCost", wireType) } @@ -1646,7 +1746,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } - case 6: + case 7: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field CompileCost", wireType) } @@ -2111,6 +2211,25 @@ func (m *ContractInfo) Unmarshal(dAtA []byte) error { } m.IBCPortID = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + m.Status = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Status |= ContractStatus(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) diff --git a/x/wasm/internal/types/types.proto b/x/wasm/internal/types/types.proto index 6b4bfd7379..6751bd6c20 100644 --- a/x/wasm/internal/types/types.proto +++ b/x/wasm/internal/types/types.proto @@ -21,6 +21,19 @@ enum AccessType { ACCESS_TYPE_EVERYBODY = 3 [(gogoproto.enumvalue_customname) = "AccessTypeEverybody"]; } +// ContractStatus types +enum ContractStatus { + option (gogoproto.goproto_enum_prefix) = false; + option (gogoproto.goproto_enum_stringer) = false; + + // ContractStatus unspecified + CONTRACT_STATUS_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "ContractStatusUnspecified"]; + // ContractStatus active + CONTRACT_STATUS_ACTIVE = 1 [(gogoproto.enumvalue_customname) = "ContractStatusActive"]; + // ContractStatus inactive + CONTRACT_STATUS_INACTIVE = 2 [(gogoproto.enumvalue_customname) = "ContractStatusInactive"]; +} + // AccessTypeParam message AccessTypeParam { option (gogoproto.goproto_stringer) = true; @@ -39,11 +52,13 @@ message Params { option (gogoproto.goproto_stringer) = false; AccessConfig code_upload_access = 1 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"code_upload_access\""]; - AccessType instantiate_default_permission = 2 [(gogoproto.moretags) = "yaml:\"instantiate_default_permission\""]; - uint64 max_wasm_code_size = 3 [(gogoproto.moretags) = "yaml:\"max_wasm_code_size\""]; - uint64 gas_multiplier = 4 [(gogoproto.moretags) = "yaml:\"max_gas\""]; - uint64 instance_cost = 5 [(gogoproto.moretags) = "yaml:\"instance_cost\""]; - uint64 compile_cost = 6 [(gogoproto.moretags) = "yaml:\"compile_cost\""]; + AccessType instantiate_default_permission = 2 [(gogoproto.moretags) = "yaml:\"instantiate_default_permission\""]; + AccessConfig contract_status_access = 3 + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"contract_status_access\""]; + uint64 max_wasm_code_size = 4 [(gogoproto.moretags) = "yaml:\"max_wasm_code_size\""]; + uint64 gas_multiplier = 5 [(gogoproto.moretags) = "yaml:\"max_gas\""]; + uint64 instance_cost = 6 [(gogoproto.moretags) = "yaml:\"instance_cost\""]; + uint64 compile_cost = 7 [(gogoproto.moretags) = "yaml:\"compile_cost\""]; } // CodeInfo is data for the uploaded contract WASM code @@ -76,6 +91,8 @@ message ContractInfo { // This data should kept internal and not be exposed via query results. Just use for sorting AbsoluteTxPosition created = 5; string ibc_port_id = 6 [(gogoproto.customname) = "IBCPortID"]; + // Status is a status of a contract + ContractStatus status = 7; } // ContractCodeHistoryOperationType actions that caused a code change diff --git a/x/wasm/internal/types/types_test.go b/x/wasm/internal/types/types_test.go index 53a9d2170a..86da8de7df 100644 --- a/x/wasm/internal/types/types_test.go +++ b/x/wasm/internal/types/types_test.go @@ -41,6 +41,14 @@ func TestContractInfoValidateBasic(t *testing.T) { srcMutator: func(c *ContractInfo) { c.Label = strings.Repeat("a", MaxLabelSize+1) }, expError: true, }, + "empty status": { + srcMutator: func(c *ContractInfo) { c.Status = 0 }, + expError: true, + }, + "invalid status": { + srcMutator: func(c *ContractInfo) { c.Status = 3 }, + expError: true, + }, } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index ce274accad..6594039214 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -134,6 +134,8 @@ type initMsg struct { Beneficiary sdk.AccAddress `json:"beneficiary"` } +type emptyMsg struct{} + type state struct { Verifier wasmvmtypes.CanonicalAddress `json:"verifier"` Beneficiary wasmvmtypes.CanonicalAddress `json:"beneficiary"` @@ -198,6 +200,181 @@ func TestHandleInstantiate(t *testing.T) { }) } +func TestHandleStoreAndInstantiate(t *testing.T) { + data := setupTest(t) + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + creator := createFakeFundedAccount(t, data.ctx, data.acctKeeper, data.bankKeeper, deposit) + + h := data.module.Route().Handler() + q := data.module.LegacyQuerierHandler(nil) + + _, _, bob := keyPubAddr() + _, _, fred := keyPubAddr() + + initMsg := initMsg{ + Verifier: fred, + Beneficiary: bob, + } + initMsgBz, err := json.Marshal(initMsg) + require.NoError(t, err) + + // create with no balance is legal + msg := &MsgStoreCodeAndInstantiateContract{ + Sender: creator.String(), + WASMByteCode: testContract, + InitMsg: initMsgBz, + Label: "contract for test", + Funds: nil, + } + res, err := h(data.ctx, msg) + require.NoError(t, err) + codeID, contractBech32Addr := parseStoreAndInitResponse(t, res.Data) + + require.Equal(t, uint64(1), codeID) + require.Equal(t, "link18vd8fpwxzck93qlwghaj6arh4p7c5n89fvcmzu", contractBech32Addr) + // this should be standard x/wasm init event, nothing from contract + require.Equal(t, 3, len(res.Events), prettyEvents(res.Events)) + assert.Equal(t, "message", res.Events[0].Type) + assertAttribute(t, "module", "wasm", res.Events[0].Attributes[0]) + assertAttribute(t, "code_id", "1", res.Events[0].Attributes[2]) + assert.Equal(t, "wasm", res.Events[1].Type) + assertAttribute(t, "contract_address", contractBech32Addr, res.Events[1].Attributes[0]) + assert.Equal(t, "message", res.Events[2].Type) + assertAttribute(t, "module", "wasm", res.Events[2].Attributes[0]) + assertAttribute(t, "code_id", "1", res.Events[2].Attributes[2]) + assertAttribute(t, "contract_address", contractBech32Addr, res.Events[2].Attributes[3]) + + assertCodeList(t, q, data.ctx, 1) + assertCodeBytes(t, q, data.ctx, 1, testContract) + + assertContractList(t, q, data.ctx, 1, []string{contractBech32Addr}) + assertContractInfo(t, q, data.ctx, contractBech32Addr, 1, creator) + assertContractState(t, q, data.ctx, contractBech32Addr, state{ + Verifier: []byte(fred), + Beneficiary: []byte(bob), + Funder: []byte(creator), + }) +} + +func TestErrorsCreateAndInstantiate(t *testing.T) { + // init messages + _, _, bob := keyPubAddr() + _, _, fred := keyPubAddr() + initMsg := initMsg{ + Verifier: fred, + Beneficiary: bob, + } + validInitMsgBz, err := json.Marshal(initMsg) + require.NoError(t, err) + + invalidInitMsgBz, err := json.Marshal(emptyMsg{}) + + expectedContractBech32Addr := "link18vd8fpwxzck93qlwghaj6arh4p7c5n89fvcmzu" + + // test cases + cases := map[string]struct { + msg sdk.Msg + isValid bool + expectedCodes int + expectedBytes []byte + }{ + "empty": { + msg: &MsgStoreCodeAndInstantiateContract{}, + isValid: false, + expectedCodes: 0, + expectedBytes: nil, + }, + "valid one": { + msg: &MsgStoreCodeAndInstantiateContract{ + Sender: addr1, + WASMByteCode: testContract, + InitMsg: validInitMsgBz, + Label: "foo", + Funds: nil, + }, + isValid: true, + expectedCodes: 1, + expectedBytes: testContract, + }, + "invalid wasm": { + msg: &MsgStoreCodeAndInstantiateContract{ + Sender: addr1, + WASMByteCode: []byte("foobar"), + InitMsg: validInitMsgBz, + Label: "foo", + Funds: nil, + }, + isValid: false, + expectedCodes: 0, + expectedBytes: nil, + }, + "old wasm (0.7)": { + msg: &MsgStoreCodeAndInstantiateContract{ + Sender: addr1, + WASMByteCode: oldContract, + InitMsg: validInitMsgBz, + Label: "foo", + Funds: nil, + }, + isValid: false, + expectedCodes: 0, + expectedBytes: nil, + }, + "invalid init message": { + msg: &MsgStoreCodeAndInstantiateContract{ + Sender: addr1, + WASMByteCode: testContract, + InitMsg: invalidInitMsgBz, + Label: "foo", + Funds: nil, + }, + isValid: false, + expectedCodes: 1, + expectedBytes: testContract, + }, + } + + for name, tc := range cases { + tc := tc + t.Run(name, func(t *testing.T) { + data := setupTest(t) + + h := data.module.Route().Handler() + q := data.module.LegacyQuerierHandler(nil) + + // asserting response + res, err := h(data.ctx, tc.msg) + if tc.isValid { + require.NoError(t, err) + codeID, contractBech32Addr := parseStoreAndInitResponse(t, res.Data) + require.Equal(t, uint64(1), codeID) + require.Equal(t, expectedContractBech32Addr, contractBech32Addr) + + } else { + require.Error(t, err, "%#v", res) + } + + // asserting code state + assertCodeList(t, q, data.ctx, tc.expectedCodes) + assertCodeBytes(t, q, data.ctx, 1, tc.expectedBytes) + + // asserting contract state + if tc.isValid { + assertContractList(t, q, data.ctx, 1, []string{expectedContractBech32Addr}) + assertContractInfo(t, q, data.ctx, expectedContractBech32Addr, 1, addrAcc1) + assertContractState(t, q, data.ctx, expectedContractBech32Addr, state{ + Verifier: []byte(fred), + Beneficiary: []byte(bob), + Funder: []byte(addrAcc1), + }) + } else { + assertContractList(t, q, data.ctx, 0, []string{}) + } + }) + } +} + func TestHandleExecute(t *testing.T) { data := setupTest(t)