diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 4388d8d3..7e234129 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -41,10 +41,8 @@ import ( govv1betatypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "github.com/cosmos/cosmos-sdk/x/params" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -362,7 +360,6 @@ func NewAppKeeper( govRouter := govv1betatypes.NewRouter() govRouter. AddRoute(govtypes.RouterKey, govv1betatypes.ProposalHandler). - AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(appKeepers.ParamsKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper)). AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)). AddRoute(erc20types.RouterKey, erc20.NewErc20ProposalHandler(&appKeepers.Erc20Keeper)). @@ -422,7 +419,6 @@ func NewAppKeeper( ) // RouterKeeper must be created before TransferKeeper - authority := authtypes.NewModuleAddress(govtypes.ModuleName).String() appKeepers.PFMRouterKeeper = pfmrouterkeeper.NewKeeper( appCodec, appKeepers.keys[pfmroutertypes.StoreKey], nil, // Will be zero-value here. Reference is set later on with SetTransferKeeper. @@ -431,7 +427,7 @@ func NewAppKeeper( appKeepers.BankKeeper, // The ICS4Wrapper is replaced by the IBCFeeKeeper instead of the channel so that sending can be overridden by the middleware &appKeepers.IBCFeeKeeper, - authority, + govModAddress, ) appKeepers.IBCFeeKeeper = ibcfeekeeper.NewKeeper( @@ -526,12 +522,12 @@ func NewAppKeeper( appKeepers.RewardKeeper = rewardkeeper.NewKeeper( appCodec, appKeepers.keys[rewardtypes.StoreKey], - appKeepers.GetSubspace(rewardtypes.ModuleName), appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.StakingKeeper, appKeepers.DistrKeeper, appKeepers.MintKeeper, + govModAddress, ) return appKeepers diff --git a/app/modules.go b/app/modules.go index 227c8aaf..1fe6a035 100644 --- a/app/modules.go +++ b/app/modules.go @@ -34,7 +34,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/mint" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/cosmos/cosmos-sdk/x/params" - paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/slashing" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" @@ -95,7 +94,6 @@ func getGovProposalHandlers() []govclient.ProposalHandler { govProposalHandlers := volunteerclient.ProposalHandler return append(govProposalHandlers, []govclient.ProposalHandler{ - paramsclient.ProposalHandler, upgradeclient.LegacyProposalHandler, upgradeclient.LegacyCancelProposalHandler, ibcclientclient.UpdateClientProposalHandler, @@ -180,7 +178,7 @@ func appModules( xplaevm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.GetSubspace(evmtypes.ModuleName)), feemarket.NewAppModule(app.FeeMarketKeeper, app.GetSubspace(feemarkettypes.ModuleName)), erc20.NewAppModule(app.Erc20Keeper, app.AccountKeeper, app.GetSubspace(erc20types.ModuleName)), - reward.NewAppModule(appCodec, app.RewardKeeper, app.BankKeeper, app.StakingKeeper, app.DistrKeeper), + reward.NewAppModule(appCodec, app.RewardKeeper, app.BankKeeper, app.StakingKeeper, app.DistrKeeper, app.GetSubspace(rewardtypes.ModuleName)), volunteer.NewAppModule(appCodec, app.VolunteerKeeper), } } diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 69e38fed..752902d2 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -21,6 +21,8 @@ - [xpla/reward/v1beta1/tx.proto](#xpla/reward/v1beta1/tx.proto) - [MsgFundFeeCollector](#xpla.reward.v1beta1.MsgFundFeeCollector) - [MsgFundFeeCollectorResponse](#xpla.reward.v1beta1.MsgFundFeeCollectorResponse) + - [MsgUpdateParams](#xpla.reward.v1beta1.MsgUpdateParams) + - [MsgUpdateParamsResponse](#xpla.reward.v1beta1.MsgUpdateParamsResponse) - [Msg](#xpla.reward.v1beta1.Msg) @@ -224,6 +226,35 @@ MsgFundFeeCollectorResponse defines the Msg/FundFeeCollector response type. + + + +### MsgUpdateParams +MsgUpdateParams is the Msg/UpdateParams request type for reward parameters. +Since: cosmos-sdk 0.47 + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `authority` | [string](#string) | | authority is the address of the governance account. | +| `params` | [Params](#xpla.reward.v1beta1.Params) | | params defines the x/evm parameters to update. NOTE: All parameters must be supplied. | + + + + + + + + +### MsgUpdateParamsResponse +MsgUpdateParamsResponse defines the response structure for executing a +MsgUpdateParams message. +Since: cosmos-sdk 0.47 + + + + + @@ -239,6 +270,7 @@ Msg defines the reawrd Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | | `FundFeeCollector` | [MsgFundFeeCollector](#xpla.reward.v1beta1.MsgFundFeeCollector) | [MsgFundFeeCollectorResponse](#xpla.reward.v1beta1.MsgFundFeeCollectorResponse) | FundFeeCollector defines a method to allow an account to directly fund the fee collector. | | +| `UpdateParams` | [MsgUpdateParams](#xpla.reward.v1beta1.MsgUpdateParams) | [MsgUpdateParamsResponse](#xpla.reward.v1beta1.MsgUpdateParamsResponse) | UpdateParams defined a governance operation for updating the x/reward module parameters. The authority is hard-coded to the Cosmos SDK x/gov module account | | diff --git a/proto/xpla/reward/v1beta1/tx.proto b/proto/xpla/reward/v1beta1/tx.proto index 3643a7f2..5cd7c9a7 100644 --- a/proto/xpla/reward/v1beta1/tx.proto +++ b/proto/xpla/reward/v1beta1/tx.proto @@ -5,6 +5,9 @@ option go_package = "github.com/xpladev/xpla/x/reward/types"; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; +import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; +import "xpla/reward/v1beta1/reward.proto"; import "amino/amino.proto"; // Msg defines the reawrd Msg service. @@ -13,6 +16,11 @@ service Msg { // fund the fee collector. rpc FundFeeCollector(MsgFundFeeCollector) returns (MsgFundFeeCollectorResponse); + + // UpdateParams defined a governance operation for updating the x/reward + // module parameters. The authority is hard-coded to the Cosmos SDK x/gov + // module account + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); } // MsgFundFeeCollector allows an account to directly @@ -31,3 +39,21 @@ message MsgFundFeeCollector { // MsgFundFeeCollectorResponse defines the Msg/FundFeeCollector response type. message MsgFundFeeCollectorResponse {} + +// MsgUpdateParams is the Msg/UpdateParams request type for reward parameters. +// Since: cosmos-sdk 0.47 +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address of the governance account. + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // params defines the x/evm parameters to update. + // NOTE: All parameters must be supplied. + Params params = 2 [ (gogoproto.nullable) = false ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// Since: cosmos-sdk 0.47 +message MsgUpdateParamsResponse {} \ No newline at end of file diff --git a/tests/integration/testutil/common.go b/tests/integration/testutil/common.go index 8dda1738..baae106a 100644 --- a/tests/integration/testutil/common.go +++ b/tests/integration/testutil/common.go @@ -35,7 +35,6 @@ import ( mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" params "github.com/cosmos/cosmos-sdk/x/params" - paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/slashing" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" @@ -166,7 +165,6 @@ func CreateTestInput(t *testing.T) TestInput { govModAddress := authtypes.NewModuleAddress(govtypes.ModuleName).String() - paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, keyParams, tKeyParams) accountKeeper := authkeeper.NewAccountKeeper(appCodec, keyAcc, etherminttypes.ProtoAccount, maccPerms, sdk.GetConfig().GetBech32AccountAddrPrefix(), govModAddress) bankKeeper := bankkeeper.NewBaseKeeper(appCodec, keyBank, accountKeeper, blackListAddrs, govModAddress) @@ -219,12 +217,12 @@ func CreateTestInput(t *testing.T) TestInput { keeper := rewardkeeper.NewKeeper( appCodec, keyReward, - paramsKeeper.Subspace(rewardtypes.ModuleName), accountKeeper, bankKeeper, stakingKeeper, distrKeeper, mintKeeper, + govModAddress, ) defaults := rewardtypes.Params{ diff --git a/x/reward/exported/exported.go b/x/reward/exported/exported.go new file mode 100644 index 00000000..000114e6 --- /dev/null +++ b/x/reward/exported/exported.go @@ -0,0 +1,18 @@ +package exported + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +type ( + ParamSet = paramtypes.ParamSet + + // Subspace defines an interface that implements the legacy x/params Subspace + // type. + // + // NOTE: This is used solely for migration of x/params managed parameters. + Subspace interface { + GetParamSet(ctx sdk.Context, ps ParamSet) + } +) diff --git a/x/reward/keeper/genesis.go b/x/reward/keeper/genesis.go index 67829d7e..b9c272aa 100644 --- a/x/reward/keeper/genesis.go +++ b/x/reward/keeper/genesis.go @@ -1,12 +1,17 @@ package keeper import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/xpladev/xpla/x/reward/types" ) func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { - k.SetParams(ctx, data.Params) + err := k.SetParams(ctx, data.Params) + if err != nil { + panic(fmt.Errorf("error setting params %s", err)) + } } func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { diff --git a/x/reward/keeper/grpc_query.go b/x/reward/keeper/grpc_query.go index 55aa2324..061874ef 100644 --- a/x/reward/keeper/grpc_query.go +++ b/x/reward/keeper/grpc_query.go @@ -12,13 +12,12 @@ var _ types.QueryServer = Keeper{} // Params queries params of reward module func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { ctx := sdk.UnwrapSDKContext(c) - var params types.Params - k.paramSpace.GetParamSet(ctx, ¶ms) + params := k.GetParams(ctx) return &types.QueryParamsResponse{Params: params}, nil } -// RewardPool queries the community pool coins +// RewardPool queries the reward pool coins func (k Keeper) Pool(c context.Context, req *types.QueryPoolRequest) (*types.QueryPoolResponse, error) { ctx := sdk.UnwrapSDKContext(c) pool := k.PoolBalances(ctx) diff --git a/x/reward/keeper/keeper.go b/x/reward/keeper/keeper.go index 275a83d6..c01095f8 100644 --- a/x/reward/keeper/keeper.go +++ b/x/reward/keeper/keeper.go @@ -1,21 +1,24 @@ package keeper import ( + "fmt" + "github.com/cometbft/cometbft/libs/log" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/xpladev/xpla/x/reward/types" ) type Keeper struct { - storeKey storetypes.StoreKey - cdc codec.BinaryCodec - paramSpace paramtypes.Subspace + storeKey storetypes.StoreKey + cdc codec.BinaryCodec + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string authKeeper types.AccountKeeper bankKeeper types.BankKeeper @@ -25,26 +28,32 @@ type Keeper struct { } func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, + cdc codec.BinaryCodec, key storetypes.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, dk types.DistributionKeeper, mk types.MintKeeper, + authority string, ) Keeper { - // set KeyTable if it has not already been set - if !paramSpace.HasKeyTable() { - paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) + // ensure reward module account is set + if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { + panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) } return Keeper{ storeKey: key, cdc: cdc, - paramSpace: paramSpace, authKeeper: ak, bankKeeper: bk, stakingKeeper: sk, distKeeper: dk, mintKeeper: mk, + authority: authority, } } +// GetAuthority returns the x/reward module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} + // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+types.ModuleName) diff --git a/x/reward/keeper/migrations.go b/x/reward/keeper/migrations.go new file mode 100644 index 00000000..8f96bac7 --- /dev/null +++ b/x/reward/keeper/migrations.go @@ -0,0 +1,26 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/xpladev/xpla/x/reward/exported" + v2 "github.com/xpladev/xpla/x/reward/migrations/v2" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper Keeper + legacySubspace exported.Subspace +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper, legacySubspace exported.Subspace) Migrator { + return Migrator{keeper: keeper, legacySubspace: legacySubspace} +} + +// Migrate1to2 migrates the x/reward module state from the consensus +// version 1 to version 2. Specifically, it takes the parameters that are currently stored +// and managed by the x/params module and stores them directly into the x/reward +// module state. +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + return v2.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc) +} diff --git a/x/reward/keeper/msg_server.go b/x/reward/keeper/msg_server.go index 75847e81..11079557 100644 --- a/x/reward/keeper/msg_server.go +++ b/x/reward/keeper/msg_server.go @@ -3,7 +3,9 @@ package keeper import ( context "context" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/xpladev/xpla/x/reward/types" ) @@ -42,3 +44,19 @@ func (k msgServer) FundFeeCollector(goCtx context.Context, msg *types.MsgFundFee return &types.MsgFundFeeCollectorResponse{}, nil } + +// UpdateParams implements the gRPC MsgServer interface. After a successful governance vote +// it updates the parameters in the keeper only if the requested authority +// is the Cosmos SDK governance module account +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if k.authority != req.Authority { + return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := k.SetParams(ctx, req.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/reward/keeper/params.go b/x/reward/keeper/params.go index 4b437203..2df3743f 100644 --- a/x/reward/keeper/params.go +++ b/x/reward/keeper/params.go @@ -6,20 +6,35 @@ import ( ) func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { - k.paramSpace.GetParamSet(ctx, ¶ms) + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return params + } + + k.cdc.MustUnmarshal(bz, ¶ms) return params } -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - k.paramSpace.SetParamSet(ctx, ¶ms) +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + if err := params.ValidateBasic(); err != nil { + return err + } + + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + store.Set(types.ParamsKey, bz) + + return nil } func (k Keeper) GetReserveAccount(ctx sdk.Context) (reserveAccount string) { - k.paramSpace.Get(ctx, types.ParamStoreKeyReserveAccount, &reserveAccount) - return reserveAccount + return k.GetParams(ctx).ReserveAccount } func (k Keeper) GetRewardDistributeAccount(ctx sdk.Context) (rewardDistributeAccount string) { - k.paramSpace.Get(ctx, types.ParamStoreKeyRewardDistributeAccount, &rewardDistributeAccount) - return rewardDistributeAccount + return k.GetParams(ctx).RewardDistributeAccount } diff --git a/x/reward/migrations/v2/migrate.go b/x/reward/migrations/v2/migrate.go new file mode 100644 index 00000000..0d6161cb --- /dev/null +++ b/x/reward/migrations/v2/migrate.go @@ -0,0 +1,28 @@ +package v2 + +import ( + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/xpladev/xpla/x/reward/exported" + "github.com/xpladev/xpla/x/reward/types" +) + +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { + store := ctx.KVStore(storeKey) + var currParams types.Params + legacySubspace.GetParamSet(ctx, &currParams) + + if err := currParams.ValidateBasic(); err != nil { + return err + } + + bz, err := cdc.Marshal(&currParams) + if err != nil { + return err + } + + store.Set(types.ParamsKey, bz) + + return nil +} diff --git a/x/reward/module.go b/x/reward/module.go index 98432f38..ba8aaec3 100644 --- a/x/reward/module.go +++ b/x/reward/module.go @@ -16,6 +16,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/xpladev/xpla/x/reward/client/cli" + "github.com/xpladev/xpla/x/reward/exported" "github.com/xpladev/xpla/x/reward/keeper" "github.com/xpladev/xpla/x/reward/types" ) @@ -87,12 +88,15 @@ type AppModule struct { bankKeeper types.BankKeeper stakingKeeper types.StakingKeeper distKeeper types.DistributionKeeper + + // legacySubspace is used solely for migration of x/params managed parameters + legacySubspace exported.Subspace } // NewAppModule creates a new AppModule object func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, - bankKeeper types.BankKeeper, stakingKeeper types.StakingKeeper, distKeeper types.DistributionKeeper, + bankKeeper types.BankKeeper, stakingKeeper types.StakingKeeper, distKeeper types.DistributionKeeper, ss exported.Subspace, ) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, @@ -100,6 +104,7 @@ func NewAppModule( bankKeeper: bankKeeper, stakingKeeper: stakingKeeper, distKeeper: distKeeper, + legacySubspace: ss, } } @@ -117,6 +122,11 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + + m := keeper.NewMigrator(am.keeper, am.legacySubspace) + if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil { + panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err)) + } } // InitGenesis performs genesis initialization for the reward module. It returns @@ -136,7 +146,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 1 } +func (AppModule) ConsensusVersion() uint64 { return 2 } // BeginBlock returns the begin blocker for the reward module. func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { diff --git a/x/reward/types/codec.go b/x/reward/types/codec.go index 2c279413..dcefda26 100644 --- a/x/reward/types/codec.go +++ b/x/reward/types/codec.go @@ -10,12 +10,14 @@ import ( func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgFundFeeCollector{}, "xpladev/MsgFundFeeCollector", nil) + cdc.RegisterConcrete(&MsgUpdateParams{}, "xpladev/reward/MsgUpdateParams", nil) } func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgFundFeeCollector{}, + &MsgUpdateParams{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/reward/types/keys.go b/x/reward/types/keys.go index 9e953313..ebd99af5 100644 --- a/x/reward/types/keys.go +++ b/x/reward/types/keys.go @@ -10,3 +10,7 @@ const ( // RouterKey is the message route for reward RouterKey = ModuleName ) + +var ( + ParamsKey = []byte{0x01} // key for reward module params +) diff --git a/x/reward/types/msg.go b/x/reward/types/msg.go index 09083969..631adcaf 100644 --- a/x/reward/types/msg.go +++ b/x/reward/types/msg.go @@ -7,6 +7,7 @@ import ( const ( TypeMsgFundFeeCollector = "fund_fee_collector" + TypeMsgUpdateParams = "update_params" ) // NewMsgFundFeeCollector returns a new MsgFundFeeCollector with a sender and @@ -52,3 +53,24 @@ func (msg MsgFundFeeCollector) ValidateBasic() error { return nil } + +// GetSigners returns the expected signers for a MsgUpdateParams message. +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr := sdk.MustAccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + +// ValidateBasic does a sanity check of the provided data +func (msg *MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "Invalid authority address") + } + + return msg.Params.ValidateBasic() +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgUpdateParams) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(&msg) + return sdk.MustSortJSON(bz) +} diff --git a/x/reward/types/msg_test.go b/x/reward/types/msg_test.go index c2a869c3..fcc4d9e8 100644 --- a/x/reward/types/msg_test.go +++ b/x/reward/types/msg_test.go @@ -4,6 +4,8 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/stretchr/testify/require" "github.com/xpladev/xpla/x/reward/types" ) @@ -28,3 +30,37 @@ func TestMsgFundFeeCollector(t *testing.T) { } } } + +func TestMsgUpdateValidateBasic(t *testing.T) { + testCases := []struct { + name string + msgUpdate *types.MsgUpdateParams + expPass bool + }{ + { + "fail - invalid authority address", + &types.MsgUpdateParams{ + Authority: "invalid", + Params: types.DefaultParams(), + }, + false, + }, + { + "pass - valid msg", + &types.MsgUpdateParams{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + Params: types.DefaultParams(), + }, + true, + }, + } + + for i, tc := range testCases { + if tc.expPass { + require.Nil(t, tc.msgUpdate.ValidateBasic(), "test index: %v", i) + } else { + require.NotNil(t, tc.msgUpdate.ValidateBasic(), "test index: %v", i) + } + + } +} diff --git a/x/reward/types/params.go b/x/reward/types/params.go index 11715258..1c6ac2cc 100644 --- a/x/reward/types/params.go +++ b/x/reward/types/params.go @@ -6,7 +6,6 @@ import ( yaml "gopkg.in/yaml.v2" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) const ( @@ -20,20 +19,6 @@ var ( DefaultRateReserve = sdk.NewDecWithPrec(0, 2) // 0% ) -// Parameter keys -var ( - ParamStoreKeyFeePoolRate = []byte("feepoolrate") - ParamStoreKeyCommunityPoolRate = []byte("communitypoolrate") - ParamStoreKeyReserveRate = []byte("reserverate") - ParamStoreKeyReserveAccount = []byte("reserveaccount") - ParamStoreKeyRewardDistributeAccount = []byte("rewarddistributeaccount") -) - -// ParamKeyTable - Key declaration for parameters -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - // DefaultParams returns default reward parameters func DefaultParams() Params { return Params{ @@ -50,17 +35,6 @@ func (p Params) String() string { return string(out) } -// ParamSetPairs returns the parameter set pairs. -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(ParamStoreKeyFeePoolRate, &p.FeePoolRate, validateFeePoolRate), - paramtypes.NewParamSetPair(ParamStoreKeyCommunityPoolRate, &p.CommunityPoolRate, validateCommunityPoolRate), - paramtypes.NewParamSetPair(ParamStoreKeyReserveRate, &p.ReserveRate, validateReserveRate), - paramtypes.NewParamSetPair(ParamStoreKeyReserveAccount, &p.ReserveAccount, validateAccount), - paramtypes.NewParamSetPair(ParamStoreKeyRewardDistributeAccount, &p.RewardDistributeAccount, validateAccount), - } -} - func (p Params) TotalRate() sdk.Dec { return p.CommunityPoolRate.Add(p.FeePoolRate).Add(p.ReserveRate) } diff --git a/x/reward/types/params_legacy.go b/x/reward/types/params_legacy.go new file mode 100644 index 00000000..56fbf25a --- /dev/null +++ b/x/reward/types/params_legacy.go @@ -0,0 +1,30 @@ +package types + +import ( + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// Parameter keys +var ( + ParamStoreKeyFeePoolRate = []byte("feepoolrate") + ParamStoreKeyCommunityPoolRate = []byte("communitypoolrate") + ParamStoreKeyReserveRate = []byte("reserverate") + ParamStoreKeyReserveAccount = []byte("reserveaccount") + ParamStoreKeyRewardDistributeAccount = []byte("rewarddistributeaccount") +) + +// ParamKeyTable - Key declaration for parameters +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// ParamSetPairs returns the parameter set pairs. +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(ParamStoreKeyFeePoolRate, &p.FeePoolRate, validateFeePoolRate), + paramtypes.NewParamSetPair(ParamStoreKeyCommunityPoolRate, &p.CommunityPoolRate, validateCommunityPoolRate), + paramtypes.NewParamSetPair(ParamStoreKeyReserveRate, &p.ReserveRate, validateReserveRate), + paramtypes.NewParamSetPair(ParamStoreKeyReserveAccount, &p.ReserveAccount, validateAccount), + paramtypes.NewParamSetPair(ParamStoreKeyRewardDistributeAccount, &p.RewardDistributeAccount, validateAccount), + } +} diff --git a/x/reward/types/tx.pb.go b/x/reward/types/tx.pb.go index a7fa43e9..96246f6c 100644 --- a/x/reward/types/tx.pb.go +++ b/x/reward/types/tx.pb.go @@ -6,8 +6,10 @@ package types import ( context "context" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" @@ -108,37 +110,144 @@ func (m *MsgFundFeeCollectorResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgFundFeeCollectorResponse proto.InternalMessageInfo +// MsgUpdateParams is the Msg/UpdateParams request type for reward parameters. +// Since: cosmos-sdk 0.47 +type MsgUpdateParams struct { + // authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/evm parameters to update. + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_9ab6178765eaaaf2, []int{2} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// Since: cosmos-sdk 0.47 +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9ab6178765eaaaf2, []int{3} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgFundFeeCollector)(nil), "xpla.reward.v1beta1.MsgFundFeeCollector") proto.RegisterType((*MsgFundFeeCollectorResponse)(nil), "xpla.reward.v1beta1.MsgFundFeeCollectorResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "xpla.reward.v1beta1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "xpla.reward.v1beta1.MsgUpdateParamsResponse") } func init() { proto.RegisterFile("xpla/reward/v1beta1/tx.proto", fileDescriptor_9ab6178765eaaaf2) } var fileDescriptor_9ab6178765eaaaf2 = []byte{ - // 341 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xa9, 0x28, 0xc8, 0x49, - 0xd4, 0x2f, 0x4a, 0x2d, 0x4f, 0x2c, 0x4a, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, - 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x06, 0xc9, 0xea, 0x41, 0x64, 0xf5, - 0xa0, 0xb2, 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x79, 0x7d, 0x10, 0x0b, 0xa2, 0x54, 0x4a, - 0x2e, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x58, 0x3f, 0x29, 0xb1, 0x38, 0x15, 0x6e, 0x50, 0x72, 0x7e, - 0x66, 0x1e, 0x54, 0x5e, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0x84, 0x94, 0x0e, - 0x31, 0x72, 0x09, 0xfb, 0x16, 0xa7, 0xbb, 0x95, 0xe6, 0xa5, 0xb8, 0xa5, 0xa6, 0x3a, 0xe7, 0xe7, - 0xe4, 0xa4, 0x26, 0x97, 0xe4, 0x17, 0x09, 0x25, 0x73, 0xb1, 0x25, 0xe6, 0xe6, 0x97, 0xe6, 0x95, - 0x48, 0x30, 0x2a, 0x30, 0x6b, 0x70, 0x1b, 0x49, 0xea, 0x41, 0xcc, 0xd6, 0x03, 0x99, 0x0d, 0x73, - 0x86, 0x9e, 0x73, 0x7e, 0x66, 0x9e, 0x93, 0xc1, 0x89, 0x7b, 0xf2, 0x0c, 0xab, 0xee, 0xcb, 0x6b, - 0xa4, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x43, 0x1d, 0x02, 0xa1, 0x74, - 0x8b, 0x53, 0xb2, 0xf5, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0xc1, 0x1a, 0x8a, 0x83, 0xa0, 0x46, 0x0b, - 0xc9, 0x70, 0x71, 0xa6, 0xa4, 0x16, 0xe4, 0x17, 0x67, 0x96, 0xe4, 0x17, 0x49, 0x30, 0x29, 0x30, - 0x6a, 0x70, 0x06, 0x21, 0x04, 0xac, 0x34, 0x3a, 0x16, 0xc8, 0x33, 0xbc, 0x58, 0x20, 0xcf, 0xd0, - 0xf5, 0x7c, 0x83, 0x96, 0x34, 0x28, 0x14, 0x52, 0x52, 0xcb, 0xf4, 0xb1, 0x38, 0x56, 0x49, 0x96, - 0x4b, 0x1a, 0x8b, 0x70, 0x50, 0x6a, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0x51, 0x29, 0x17, 0xb3, - 0x6f, 0x71, 0xba, 0x50, 0x1e, 0x97, 0x00, 0x86, 0x37, 0x35, 0xf4, 0xb0, 0x84, 0xae, 0x1e, 0x16, - 0xc3, 0xa4, 0x0c, 0x88, 0x55, 0x09, 0xb3, 0xd6, 0xc9, 0xe1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, - 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, - 0x8f, 0xe5, 0x18, 0xa2, 0xd4, 0x90, 0x42, 0x0a, 0xe6, 0x2f, 0x70, 0x1a, 0xa8, 0x80, 0xa5, 0x02, - 0x70, 0x68, 0x25, 0xb1, 0x81, 0xe3, 0xc8, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x8e, 0x61, 0x2a, - 0x7a, 0x21, 0x02, 0x00, 0x00, + // 488 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xbf, 0x6f, 0xd3, 0x40, + 0x14, 0xf6, 0x51, 0x14, 0x29, 0x57, 0xc4, 0x0f, 0xb7, 0x52, 0xf3, 0xa3, 0x38, 0x51, 0x84, 0x90, + 0x55, 0x51, 0x5f, 0x13, 0x24, 0x24, 0x3a, 0x41, 0x2a, 0x75, 0x8b, 0x84, 0x8c, 0x58, 0x58, 0xd0, + 0xd9, 0x3e, 0xb9, 0x16, 0xb1, 0x9f, 0x75, 0xef, 0x12, 0xd2, 0x95, 0x09, 0x31, 0x31, 0xf0, 0x07, + 0x74, 0x66, 0xea, 0xc0, 0x5f, 0xc0, 0xd4, 0xb1, 0x62, 0x82, 0x05, 0x50, 0x32, 0x94, 0x3f, 0x03, + 0xd9, 0x3e, 0x93, 0x02, 0x46, 0xca, 0x92, 0x8b, 0xdf, 0xf7, 0xdd, 0xf7, 0x7d, 0xef, 0xde, 0xa3, + 0xdb, 0xb3, 0x74, 0xcc, 0x99, 0x14, 0xaf, 0xb8, 0x0c, 0xd8, 0xb4, 0xef, 0x09, 0xc5, 0xfb, 0x4c, + 0xcd, 0x9c, 0x54, 0x82, 0x02, 0x73, 0x23, 0x43, 0x9d, 0x02, 0x75, 0x34, 0xda, 0xda, 0x0c, 0x21, + 0x84, 0x1c, 0x67, 0xd9, 0xbf, 0x82, 0xda, 0xb2, 0x7c, 0xc0, 0x18, 0x90, 0x79, 0x1c, 0xc5, 0x6f, + 0x21, 0x1f, 0xa2, 0x44, 0xe3, 0x5b, 0x1a, 0x8f, 0x31, 0x64, 0xd3, 0x7e, 0x76, 0x68, 0xa0, 0x59, + 0x00, 0x2f, 0x0a, 0xc5, 0xe2, 0x43, 0x43, 0xdd, 0xaa, 0x70, 0x3a, 0x4d, 0xc1, 0xb8, 0xc5, 0xe3, + 0x28, 0x01, 0x96, 0xff, 0x16, 0xa5, 0xde, 0x27, 0x42, 0x37, 0x46, 0x18, 0x1e, 0x4e, 0x92, 0xe0, + 0x50, 0x88, 0x03, 0x18, 0x8f, 0x85, 0xaf, 0x40, 0x9a, 0x3e, 0xad, 0xf1, 0x18, 0x26, 0x89, 0x6a, + 0x90, 0xee, 0x9a, 0xbd, 0x3e, 0x68, 0x3a, 0xda, 0x2b, 0x4b, 0x5c, 0x36, 0xe7, 0x1c, 0x40, 0x94, + 0x0c, 0xf7, 0xce, 0xbe, 0x75, 0x8c, 0x0f, 0xdf, 0x3b, 0x76, 0x18, 0xa9, 0xa3, 0x89, 0xe7, 0xf8, + 0x10, 0xeb, 0x60, 0xfa, 0xd8, 0xc5, 0xe0, 0x25, 0x53, 0xc7, 0xa9, 0xc0, 0xfc, 0x02, 0xba, 0x5a, + 0xda, 0xdc, 0xa6, 0xf5, 0x40, 0xa4, 0x80, 0x91, 0x02, 0xd9, 0xb8, 0xd2, 0x25, 0x76, 0xdd, 0x5d, + 0x16, 0xf6, 0xed, 0x37, 0x27, 0x1d, 0xe3, 0xe7, 0x49, 0xc7, 0x78, 0x7b, 0x71, 0xba, 0xd3, 0xce, + 0x9a, 0x0b, 0xc4, 0x94, 0x55, 0x84, 0xed, 0xdd, 0xa6, 0xed, 0x8a, 0xb2, 0x2b, 0x30, 0x85, 0x04, + 0x45, 0xef, 0x3d, 0xa1, 0x37, 0x46, 0x18, 0x3e, 0x4b, 0x03, 0xae, 0xc4, 0x13, 0x2e, 0x79, 0x8c, + 0xe6, 0x03, 0x5a, 0xe7, 0x13, 0x75, 0x04, 0x32, 0x52, 0xc7, 0x0d, 0x92, 0x59, 0x0f, 0x1b, 0x9f, + 0x3f, 0xee, 0x6e, 0xea, 0x2e, 0x1f, 0x07, 0x81, 0x14, 0x88, 0x4f, 0x95, 0x8c, 0x92, 0xd0, 0x5d, + 0x52, 0xcd, 0x87, 0xb4, 0x96, 0xe6, 0x0a, 0x79, 0xde, 0xf5, 0x41, 0xdb, 0xa9, 0x18, 0xba, 0x53, + 0x98, 0x0c, 0xaf, 0x66, 0x2f, 0xe3, 0xea, 0x0b, 0xfb, 0xd7, 0x5f, 0x5f, 0x9c, 0xee, 0x2c, 0xa5, + 0x7a, 0x4d, 0xba, 0xf5, 0x57, 0xaa, 0x32, 0xf1, 0xe0, 0x2b, 0xa1, 0x6b, 0x23, 0x0c, 0xcd, 0x84, + 0xde, 0xfc, 0x67, 0x32, 0x76, 0xa5, 0x63, 0x45, 0xff, 0xad, 0xbd, 0x55, 0x99, 0xa5, 0xaf, 0xe9, + 0xd1, 0x6b, 0x7f, 0xbc, 0xd2, 0x9d, 0xff, 0x29, 0x5c, 0x66, 0xb5, 0xee, 0xad, 0xc2, 0x2a, 0x3d, + 0x86, 0x8f, 0xce, 0xe6, 0x16, 0x39, 0x9f, 0x5b, 0xe4, 0xc7, 0xdc, 0x22, 0xef, 0x16, 0x96, 0x71, + 0xbe, 0xb0, 0x8c, 0x2f, 0x0b, 0xcb, 0x78, 0x7e, 0xf7, 0xd2, 0x02, 0x95, 0xe3, 0xce, 0x77, 0x7a, + 0x56, 0x6e, 0x75, 0xbe, 0x44, 0x5e, 0x2d, 0x5f, 0xdd, 0xfb, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, + 0x69, 0x2f, 0x59, 0x50, 0x8e, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -156,6 +265,10 @@ type MsgClient interface { // FundFeeCollector defines a method to allow an account to directly // fund the fee collector. FundFeeCollector(ctx context.Context, in *MsgFundFeeCollector, opts ...grpc.CallOption) (*MsgFundFeeCollectorResponse, error) + // UpdateParams defined a governance operation for updating the x/reward + // module parameters. The authority is hard-coded to the Cosmos SDK x/gov + // module account + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -175,11 +288,24 @@ func (c *msgClient) FundFeeCollector(ctx context.Context, in *MsgFundFeeCollecto return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/xpla.reward.v1beta1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // FundFeeCollector defines a method to allow an account to directly // fund the fee collector. FundFeeCollector(context.Context, *MsgFundFeeCollector) (*MsgFundFeeCollectorResponse, error) + // UpdateParams defined a governance operation for updating the x/reward + // module parameters. The authority is hard-coded to the Cosmos SDK x/gov + // module account + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -189,6 +315,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) FundFeeCollector(ctx context.Context, req *MsgFundFeeCollector) (*MsgFundFeeCollectorResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method FundFeeCollector not implemented") } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -212,6 +341,24 @@ func _Msg_FundFeeCollector_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/xpla.reward.v1beta1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "xpla.reward.v1beta1.Msg", HandlerType: (*MsgServer)(nil), @@ -220,6 +367,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "FundFeeCollector", Handler: _Msg_FundFeeCollector_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "xpla/reward/v1beta1/tx.proto", @@ -292,6 +443,69 @@ func (m *MsgFundFeeCollectorResponse) MarshalToSizedBuffer(dAtA []byte) (int, er return len(dAtA) - i, nil } +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) 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 @@ -331,6 +545,30 @@ func (m *MsgFundFeeCollectorResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) 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 } @@ -503,6 +741,171 @@ func (m *MsgFundFeeCollectorResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", 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.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", 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 + } + if err := m.Params.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 *MsgUpdateParamsResponse) 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: 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