diff --git a/proto/cosmos/feegrant/v1beta1/feegrant.proto b/proto/cosmos/feegrant/v1beta1/feegrant.proto index 4fddf904c733..d5a642dacebc 100644 --- a/proto/cosmos/feegrant/v1beta1/feegrant.proto +++ b/proto/cosmos/feegrant/v1beta1/feegrant.proto @@ -8,7 +8,7 @@ import "cosmos/base/v1beta1/coin.proto"; import "google/protobuf/timestamp.proto"; import "google/protobuf/duration.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant"; // BasicAllowance implements Allowance with a one-time grant of tokens // that optionally expires. The grantee can use up to SpendLimit to cover fees. diff --git a/proto/cosmos/feegrant/v1beta1/genesis.proto b/proto/cosmos/feegrant/v1beta1/genesis.proto index 67d9098d3301..4c1e51fdd2c2 100644 --- a/proto/cosmos/feegrant/v1beta1/genesis.proto +++ b/proto/cosmos/feegrant/v1beta1/genesis.proto @@ -4,7 +4,7 @@ package cosmos.feegrant.v1beta1; import "gogoproto/gogo.proto"; import "cosmos/feegrant/v1beta1/feegrant.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant"; // GenesisState contains a set of fee allowances, persisted from the store message GenesisState { diff --git a/proto/cosmos/feegrant/v1beta1/query.proto b/proto/cosmos/feegrant/v1beta1/query.proto index 59d390bd1d01..00ea598b1c75 100644 --- a/proto/cosmos/feegrant/v1beta1/query.proto +++ b/proto/cosmos/feegrant/v1beta1/query.proto @@ -5,7 +5,7 @@ import "cosmos/feegrant/v1beta1/feegrant.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; import "google/api/annotations.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant"; // Query defines the gRPC querier service. service Query { diff --git a/proto/cosmos/feegrant/v1beta1/tx.proto b/proto/cosmos/feegrant/v1beta1/tx.proto index a9678d0c3c66..159d73ca9a8d 100644 --- a/proto/cosmos/feegrant/v1beta1/tx.proto +++ b/proto/cosmos/feegrant/v1beta1/tx.proto @@ -5,7 +5,7 @@ import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; import "cosmos_proto/cosmos.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant"; // Msg defines the feegrant msg service. service Msg { diff --git a/simapp/app.go b/simapp/app.go index 95692e701e3f..8e4c1e3d6a18 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -58,9 +58,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/evidence" evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" - feegrant "github.com/cosmos/cosmos-sdk/x/feegrant" + "github.com/cosmos/cosmos-sdk/x/feegrant" feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" - feegranttypes "github.com/cosmos/cosmos-sdk/x/feegrant/types" + feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/gov" @@ -112,7 +112,7 @@ var ( params.AppModuleBasic{}, crisis.AppModuleBasic{}, slashing.AppModuleBasic{}, - feegrant.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, upgrade.AppModuleBasic{}, evidence.AppModuleBasic{}, authz_m.AppModuleBasic{}, @@ -205,7 +205,7 @@ func NewSimApp( keys := sdk.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegranttypes.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, ) @@ -255,7 +255,7 @@ func NewSimApp( app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName, ) - app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegranttypes.StoreKey], app.AccountKeeper) + app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp) // register the staking hooks @@ -308,7 +308,7 @@ func NewSimApp( bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), capability.NewAppModule(appCodec, *app.CapabilityKeeper), crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), - feegrant.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), @@ -339,7 +339,7 @@ func NewSimApp( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, - feegranttypes.ModuleName, + feegrant.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) @@ -358,7 +358,7 @@ func NewSimApp( auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), capability.NewAppModule(appCodec, *app.CapabilityKeeper), - feegrant.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), diff --git a/simapp/app_test.go b/simapp/app_test.go index 7d4d144a72e9..ceb998e34b3b 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -25,7 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/crisis" "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/evidence" - feegrant "github.com/cosmos/cosmos-sdk/x/feegrant" + feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/mint" @@ -177,7 +177,7 @@ func TestRunMigrations(t *testing.T) { "params": params.AppModule{}.ConsensusVersion(), "upgrade": upgrade.AppModule{}.ConsensusVersion(), "vesting": vesting.AppModule{}.ConsensusVersion(), - "feegrant": feegrant.AppModule{}.ConsensusVersion(), + "feegrant": feegrantmodule.AppModule{}.ConsensusVersion(), "evidence": evidence.AppModule{}.ConsensusVersion(), "crisis": crisis.AppModule{}.ConsensusVersion(), "genutil": genutil.AppModule{}.ConsensusVersion(), @@ -228,7 +228,7 @@ func TestInitGenesisOnMigration(t *testing.T) { "params": params.AppModule{}.ConsensusVersion(), "upgrade": upgrade.AppModule{}.ConsensusVersion(), "vesting": vesting.AppModule{}.ConsensusVersion(), - "feegrant": feegrant.AppModule{}.ConsensusVersion(), + "feegrant": feegrantmodule.AppModule{}.ConsensusVersion(), "evidence": evidence.AppModule{}.ConsensusVersion(), "crisis": crisis.AppModule{}.ConsensusVersion(), "genutil": genutil.AppModule{}.ConsensusVersion(), diff --git a/simapp/params/weights.go b/simapp/params/weights.go index 81400a2fc2af..746e304de2be 100644 --- a/simapp/params/weights.go +++ b/simapp/params/weights.go @@ -23,6 +23,6 @@ const ( DefaultWeightParamChangeProposal int = 5 // feegrant - DefaultWeightGrantFeeAllowance int = 100 - DefaultWeightRevokeFeeAllowance int = 100 + DefaultWeightGrantAllowance int = 100 + DefaultWeightRevokeAllowance int = 100 ) diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index 4ef728c4bdec..448f49fea76c 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -21,7 +21,7 @@ import ( authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) func (suite *AnteTestSuite) TestDeductFeesNoDelegation() { @@ -54,13 +54,13 @@ func (suite *AnteTestSuite) TestDeductFeesNoDelegation() { suite.Require().NoError(err) // grant fee allowance from `addr2` to `addr3` (plenty to pay) - err = app.FeeGrantKeeper.GrantAllowance(ctx, addr2, addr3, &types.BasicAllowance{ + err = app.FeeGrantKeeper.GrantAllowance(ctx, addr2, addr3, &feegrant.BasicAllowance{ SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 500)), }) suite.Require().NoError(err) // grant low fee allowance (20atom), to check the tx requesting more than allowed. - err = app.FeeGrantKeeper.GrantAllowance(ctx, addr2, addr4, &types.BasicAllowance{ + err = app.FeeGrantKeeper.GrantAllowance(ctx, addr2, addr4, &feegrant.BasicAllowance{ SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 20)), }) suite.Require().NoError(err) diff --git a/x/feegrant/types/basic_fee.go b/x/feegrant/basic_fee.go similarity index 94% rename from x/feegrant/types/basic_fee.go rename to x/feegrant/basic_fee.go index d48823af9c59..85ba8ab2564a 100644 --- a/x/feegrant/types/basic_fee.go +++ b/x/feegrant/basic_fee.go @@ -1,4 +1,4 @@ -package types +package feegrant import ( sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,7 +16,7 @@ var _ FeeAllowanceI = (*BasicAllowance)(nil) // and will be saved again after an acceptance. // // If remove is true (regardless of the error), the FeeAllowance will be deleted from storage -// (eg. when it is used up). (See call to RevokeFeeAllowance in Keeper.UseGrantedFees) +// (eg. when it is used up). (See call to RevokeAllowance in Keeper.UseGrantedFees) func (a *BasicAllowance) Accept(ctx sdk.Context, fee sdk.Coins, _ []sdk.Msg) (bool, error) { if a.Expiration != nil && a.Expiration.Before(ctx.BlockTime()) { return true, sdkerrors.Wrap(ErrFeeLimitExpired, "basic allowance") diff --git a/x/feegrant/types/basic_fee_test.go b/x/feegrant/basic_fee_test.go similarity index 85% rename from x/feegrant/types/basic_fee_test.go rename to x/feegrant/basic_fee_test.go index 818c48f2df2c..98df14ef7e4e 100644 --- a/x/feegrant/types/basic_fee_test.go +++ b/x/feegrant/basic_fee_test.go @@ -1,4 +1,4 @@ -package types_test +package feegrant_test import ( "testing" @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) func TestBasicFeeValidAllow(t *testing.T) { @@ -18,7 +18,7 @@ func TestBasicFeeValidAllow(t *testing.T) { ctx := app.BaseApp.NewContext(false, tmproto.Header{}) badTime := ctx.BlockTime().AddDate(0, 0, -1) - allowace := &types.BasicAllowance{ + allowace := &feegrant.BasicAllowance{ Expiration: &badTime, } require.Error(t, allowace.ValidateBasic()) @@ -35,7 +35,7 @@ func TestBasicFeeValidAllow(t *testing.T) { oneHour := now.Add(1 * time.Hour) cases := map[string]struct { - allowance *types.BasicAllowance + allowance *feegrant.BasicAllowance // all other checks are ignored if valid=false fee sdk.Coins blockTime time.Time @@ -45,11 +45,11 @@ func TestBasicFeeValidAllow(t *testing.T) { remains sdk.Coins }{ "empty": { - allowance: &types.BasicAllowance{}, + allowance: &feegrant.BasicAllowance{}, accept: true, }, "small fee without expire": { - allowance: &types.BasicAllowance{ + allowance: &feegrant.BasicAllowance{ SpendLimit: atom, }, fee: smallAtom, @@ -58,7 +58,7 @@ func TestBasicFeeValidAllow(t *testing.T) { remains: leftAtom, }, "all fee without expire": { - allowance: &types.BasicAllowance{ + allowance: &feegrant.BasicAllowance{ SpendLimit: smallAtom, }, fee: smallAtom, @@ -66,14 +66,14 @@ func TestBasicFeeValidAllow(t *testing.T) { remove: true, }, "wrong fee": { - allowance: &types.BasicAllowance{ + allowance: &feegrant.BasicAllowance{ SpendLimit: smallAtom, }, fee: eth, accept: false, }, "non-expired": { - allowance: &types.BasicAllowance{ + allowance: &feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &oneHour, }, @@ -85,7 +85,7 @@ func TestBasicFeeValidAllow(t *testing.T) { remains: leftAtom, }, "expired": { - allowance: &types.BasicAllowance{ + allowance: &feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &now, }, @@ -96,7 +96,7 @@ func TestBasicFeeValidAllow(t *testing.T) { remove: true, }, "fee more than allowed": { - allowance: &types.BasicAllowance{ + allowance: &feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &oneHour, }, @@ -106,7 +106,7 @@ func TestBasicFeeValidAllow(t *testing.T) { accept: false, }, "with out spend limit": { - allowance: &types.BasicAllowance{ + allowance: &feegrant.BasicAllowance{ Expiration: &oneHour, }, valid: true, @@ -115,7 +115,7 @@ func TestBasicFeeValidAllow(t *testing.T) { accept: true, }, "expired no spend limit": { - allowance: &types.BasicAllowance{ + allowance: &feegrant.BasicAllowance{ Expiration: &now, }, valid: true, diff --git a/x/feegrant/client/cli/query.go b/x/feegrant/client/cli/query.go index a03ec59c6dce..93aab3765c37 100644 --- a/x/feegrant/client/cli/query.go +++ b/x/feegrant/client/cli/query.go @@ -10,13 +10,13 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) // GetQueryCmd returns the cli query commands for this module func GetQueryCmd() *cobra.Command { feegrantQueryCmd := &cobra.Command{ - Use: types.ModuleName, + Use: feegrant.ModuleName, Short: "Querying commands for the feegrant module", DisableFlagParsing: true, SuggestionsMinimumDistance: 2, @@ -47,7 +47,7 @@ $ %s query feegrant grant [granter] [grantee] ), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) + queryClient := feegrant.NewQueryClient(clientCtx) granterAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { @@ -61,7 +61,7 @@ $ %s query feegrant grant [granter] [grantee] res, err := queryClient.Allowance( cmd.Context(), - &types.QueryAllowanceRequest{ + &feegrant.QueryAllowanceRequest{ Granter: granterAddr.String(), Grantee: granteeAddr.String(), }, @@ -95,7 +95,7 @@ $ %s query feegrant grants [grantee] ), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) + queryClient := feegrant.NewQueryClient(clientCtx) granteeAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { @@ -109,7 +109,7 @@ $ %s query feegrant grants [grantee] res, err := queryClient.Allowances( cmd.Context(), - &types.QueryAllowancesRequest{ + &feegrant.QueryAllowancesRequest{ Grantee: granteeAddr.String(), Pagination: pageReq, }, diff --git a/x/feegrant/client/cli/tx.go b/x/feegrant/client/cli/tx.go index ce4920bc0676..ba6da5a6045c 100644 --- a/x/feegrant/client/cli/tx.go +++ b/x/feegrant/client/cli/tx.go @@ -13,7 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) // flag for feegrant module @@ -28,7 +28,7 @@ const ( // GetTxCmd returns the transaction commands for this module func GetTxCmd() *cobra.Command { feegrantTxCmd := &cobra.Command{ - Use: types.ModuleName, + Use: feegrant.ModuleName, Short: "Feegrant transactions subcommands", Long: "Grant and revoke fee allowance for a grantee by a granter", DisableFlagParsing: true, @@ -44,7 +44,7 @@ func GetTxCmd() *cobra.Command { return feegrantTxCmd } -// NewCmdFeeGrant returns a CLI command handler for creating a MsgGrantFeeAllowance transaction. +// NewCmdFeeGrant returns a CLI command handler for creating a MsgGrantAllowance transaction. func NewCmdFeeGrant() *cobra.Command { cmd := &cobra.Command{ Use: "grant [granter] [grantee]", @@ -59,7 +59,7 @@ Examples: %s tx %s grant cosmos1skjw... cosmos1skjw... --spend-limit 100stake --period 3600 --period-limit 10stake --expiration 36000 or %s tx %s grant cosmos1skjw... cosmos1skjw... --spend-limit 100stake --expiration 2022-01-30T15:04:05Z --allowed-messages "/cosmos.gov.v1beta1.MsgSubmitProposal,/cosmos.gov.v1beta1.MsgVote" - `, version.AppName, types.ModuleName, version.AppName, types.ModuleName, version.AppName, types.ModuleName, + `, version.AppName, feegrant.ModuleName, version.AppName, feegrant.ModuleName, version.AppName, feegrant.ModuleName, ), ), Args: cobra.ExactArgs(2), @@ -97,7 +97,7 @@ Examples: return err } - basic := types.BasicAllowance{ + basic := feegrant.BasicAllowance{ SpendLimit: limit, } @@ -110,7 +110,7 @@ Examples: basic.Expiration = &expiresAtTime } - var grant types.FeeAllowanceI + var grant feegrant.FeeAllowanceI grant = &basic periodClock, err := cmd.Flags().GetInt64(FlagPeriod) @@ -136,7 +136,7 @@ Examples: return fmt.Errorf("period(%d) cannot reset after expiration(%v)", periodClock, exp) } - periodic := types.PeriodicAllowance{ + periodic := feegrant.PeriodicAllowance{ Basic: basic, Period: getPeriod(periodClock), PeriodReset: getPeriodReset(periodClock), @@ -157,19 +157,19 @@ Examples: } if len(allowedMsgs) > 0 { - grant, err = types.NewAllowedMsgAllowance(grant, allowedMsgs) + grant, err = feegrant.NewAllowedMsgAllowance(grant, allowedMsgs) if err != nil { return err } } - msg, err := types.NewMsgGrantAllowance(grant, granter, grantee) + msg, err := feegrant.NewMsgGrantAllowance(grant, granter, grantee) if err != nil { return err } svcMsgClientConn := &msgservice.ServiceMsgClientConn{} - msgClient := types.NewMsgClient(svcMsgClientConn) + msgClient := feegrant.NewMsgClient(svcMsgClientConn) _, err = msgClient.GrantAllowance(cmd.Context(), msg) if err != nil { return err @@ -189,7 +189,7 @@ Examples: return cmd } -// NewCmdRevokeFeegrant returns a CLI command handler for creating a MsgRevokeFeeAllowance transaction. +// NewCmdRevokeFeegrant returns a CLI command handler for creating a MsgRevokeAllowance transaction. func NewCmdRevokeFeegrant() *cobra.Command { cmd := &cobra.Command{ Use: "revoke [granter] [grantee]", @@ -200,7 +200,7 @@ func NewCmdRevokeFeegrant() *cobra.Command { Example: $ %s tx %s revoke cosmos1skj.. cosmos1skj.. - `, version.AppName, types.ModuleName), + `, version.AppName, feegrant.ModuleName), ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { @@ -215,9 +215,9 @@ Example: return err } - msg := types.NewMsgRevokeAllowance(clientCtx.GetFromAddress(), grantee) + msg := feegrant.NewMsgRevokeAllowance(clientCtx.GetFromAddress(), grantee) svcMsgClientConn := &msgservice.ServiceMsgClientConn{} - msgClient := types.NewMsgClient(svcMsgClientConn) + msgClient := feegrant.NewMsgClient(svcMsgClientConn) _, err = msgClient.RevokeAllowance(cmd.Context(), &msg) if err != nil { return err diff --git a/x/feegrant/client/testutil/suite.go b/x/feegrant/client/testutil/suite.go index fa7682b49c66..013a44286334 100644 --- a/x/feegrant/client/testutil/suite.go +++ b/x/feegrant/client/testutil/suite.go @@ -17,8 +17,8 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" "github.com/cosmos/cosmos-sdk/x/feegrant/client/cli" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" govtestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -36,7 +36,7 @@ type IntegrationTestSuite struct { network *network.Network addedGranter sdk.AccAddress addedGrantee sdk.AccAddress - addedGrant types.Grant + addedGrant feegrant.Grant } func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { @@ -89,7 +89,7 @@ func (s *IntegrationTestSuite) SetupSuite() { s.addedGranter = granter s.addedGrantee = grantee - grant, err := types.NewGrant(granter, grantee, &types.BasicAllowance{ + grant, err := feegrant.NewGrant(granter, grantee, &feegrant.BasicAllowance{ SpendLimit: sdk.NewCoins(fee), }) s.Require().NoError(err) @@ -113,8 +113,8 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrant() { args []string expectErrMsg string expectErr bool - respType *types.Grant - resp *types.Grant + respType *feegrant.Grant + resp *feegrant.Grant }{ { "wrong granter", @@ -155,7 +155,7 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrant() { }, "", false, - &types.Grant{}, + &feegrant.Grant{}, &s.addedGrant, }, } @@ -180,8 +180,8 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrant() { grant1, err1 := tc.resp.GetGrant() s.Require().NoError(err1) s.Require().Equal( - grant.(*types.BasicAllowance).SpendLimit, - grant1.(*types.BasicAllowance).SpendLimit, + grant.(*feegrant.BasicAllowance).SpendLimit, + grant1.(*feegrant.BasicAllowance).SpendLimit, ) } }) @@ -197,7 +197,7 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrants() { name string args []string expectErr bool - resp *types.QueryAllowancesResponse + resp *feegrant.QueryAllowancesResponse expectLength int }{ { @@ -214,7 +214,7 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrants() { "cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl", fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, - false, &types.QueryAllowancesResponse{}, 0, + false, &feegrant.QueryAllowancesResponse{}, 0, }, { "valid req", @@ -222,7 +222,7 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrants() { grantee.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, - false, &types.QueryAllowancesResponse{}, 1, + false, &feegrant.QueryAllowancesResponse{}, 1, }, } @@ -733,7 +733,7 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() { out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) - resp := &types.Grant{} + resp := &feegrant.Grant{} s.Require().NoError(clientCtx.JSONCodec.UnmarshalJSON(out.Bytes(), resp), out.String()) s.Require().Equal(resp.Grantee, resp.Grantee) @@ -742,11 +742,11 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() { grant, err := resp.GetGrant() s.Require().NoError(err) - filteredFeeGrant, err := grant.(*types.AllowedMsgAllowance).GetAllowance() + filteredFeeGrant, err := grant.(*feegrant.AllowedMsgAllowance).GetAllowance() s.Require().NoError(err) s.Require().Equal( - filteredFeeGrant.(*types.BasicAllowance).SpendLimit.String(), + filteredFeeGrant.(*feegrant.BasicAllowance).SpendLimit.String(), spendLimit.String(), ) diff --git a/x/feegrant/types/codec.go b/x/feegrant/codec.go similarity index 97% rename from x/feegrant/types/codec.go rename to x/feegrant/codec.go index 7b354ffcbe02..7e307f42197d 100644 --- a/x/feegrant/types/codec.go +++ b/x/feegrant/codec.go @@ -1,4 +1,4 @@ -package types +package feegrant import ( "github.com/cosmos/cosmos-sdk/codec/types" diff --git a/x/feegrant/doc.go b/x/feegrant/doc.go index 0407937917ba..514d079c074d 100644 --- a/x/feegrant/doc.go +++ b/x/feegrant/doc.go @@ -10,7 +10,7 @@ provides ways for specifying fee allowances such that authorizing fee payment to another account can be done with clear and safe restrictions. A user would authorize granting fee payment to another user using -MsgDelegateFeeAllowance and revoke that delegation using MsgRevokeFeeAllowance. +MsgGrantAllowance and revoke that delegation using MsgRevokeAllowance. In both cases, Granter is the one who is authorizing fee payment and Grantee is the one who is receiving the fee payment authorization. So grantee would correspond to the one who is signing a transaction and the granter would be the address that @@ -18,6 +18,6 @@ pays the fees. The fee allowance that a grantee receives is specified by an implementation of the FeeAllowance interface. Two FeeAllowance implementations are provided in -this package: BasicFeeAllowance and PeriodicFeeAllowance. +this package: BasicAllowance and PeriodicAllowance. */ package feegrant diff --git a/x/feegrant/types/errors.go b/x/feegrant/errors.go similarity index 98% rename from x/feegrant/types/errors.go rename to x/feegrant/errors.go index d3234f8cd2d0..232020e6a24e 100644 --- a/x/feegrant/types/errors.go +++ b/x/feegrant/errors.go @@ -1,4 +1,4 @@ -package types +package feegrant import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" diff --git a/x/feegrant/types/events.go b/x/feegrant/events.go similarity index 94% rename from x/feegrant/types/events.go rename to x/feegrant/events.go index b82ccb7b1cd8..a4470b82704e 100644 --- a/x/feegrant/types/events.go +++ b/x/feegrant/events.go @@ -1,4 +1,4 @@ -package types +package feegrant // evidence module events const ( diff --git a/x/feegrant/types/expected_keepers.go b/x/feegrant/expected_keepers.go similarity index 97% rename from x/feegrant/types/expected_keepers.go rename to x/feegrant/expected_keepers.go index 25dc974d2ec7..eb5d4bf04465 100644 --- a/x/feegrant/types/expected_keepers.go +++ b/x/feegrant/expected_keepers.go @@ -1,4 +1,4 @@ -package types +package feegrant import ( sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/feegrant/types/feegrant.pb.go b/x/feegrant/feegrant.pb.go similarity index 91% rename from x/feegrant/types/feegrant.pb.go rename to x/feegrant/feegrant.pb.go index e12af45e464e..a76572321924 100644 --- a/x/feegrant/types/feegrant.pb.go +++ b/x/feegrant/feegrant.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cosmos/feegrant/v1beta1/feegrant.proto -package types +package feegrant import ( fmt "fmt" @@ -294,43 +294,43 @@ func init() { } var fileDescriptor_7279582900c30aea = []byte{ - // 564 bytes of a gzipped FileDescriptorProto + // 562 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x3f, 0x6f, 0xd3, 0x40, - 0x14, 0x8f, 0x9b, 0xa4, 0x90, 0x0b, 0x94, 0xc6, 0x14, 0xe1, 0x64, 0x70, 0xa2, 0x0e, 0x10, 0x86, - 0x9c, 0x69, 0xd9, 0xca, 0x42, 0x1d, 0x20, 0x42, 0xa2, 0x12, 0x32, 0x4c, 0x2c, 0xd1, 0xd9, 0x79, - 0x35, 0x27, 0x62, 0x9f, 0xe5, 0xbb, 0x40, 0xb3, 0x32, 0x31, 0x76, 0x64, 0x42, 0xcc, 0xcc, 0x7c, - 0x88, 0x8a, 0xa9, 0x82, 0x85, 0x89, 0xa2, 0xe4, 0x8b, 0x20, 0xdf, 0x9d, 0x93, 0x90, 0xf0, 0x47, - 0x42, 0x9d, 0xe2, 0xbb, 0xf7, 0x7e, 0xff, 0xde, 0x3b, 0x05, 0xdd, 0x08, 0x18, 0x8f, 0x18, 0x77, - 0x0e, 0x01, 0xc2, 0x94, 0xc4, 0xc2, 0x79, 0xb5, 0xe3, 0x83, 0x20, 0x3b, 0xb3, 0x0b, 0x9c, 0xa4, - 0x4c, 0x30, 0xf3, 0xba, 0xea, 0xc3, 0xb3, 0x6b, 0xdd, 0xd7, 0xd8, 0x0a, 0x59, 0xc8, 0x64, 0x8f, - 0x93, 0x7d, 0xa9, 0xf6, 0x46, 0x3d, 0x64, 0x2c, 0x1c, 0x82, 0x23, 0x4f, 0xfe, 0xe8, 0xd0, 0x21, - 0xf1, 0x38, 0x2f, 0x29, 0xa6, 0xbe, 0xc2, 0x68, 0x5a, 0x55, 0xb2, 0xb5, 0x19, 0x9f, 0x70, 0x98, - 0x19, 0x09, 0x18, 0x8d, 0x75, 0xbd, 0xb9, 0xcc, 0x2a, 0x68, 0x04, 0x5c, 0x90, 0x28, 0xc9, 0x09, - 0x96, 0x1b, 0x06, 0xa3, 0x94, 0x08, 0xca, 0x34, 0xc1, 0xf6, 0x57, 0x03, 0x6d, 0xb8, 0x84, 0xd3, - 0x60, 0x7f, 0x38, 0x64, 0xaf, 0x49, 0x1c, 0x80, 0x39, 0x44, 0x55, 0x9e, 0x40, 0x3c, 0xe8, 0x0f, - 0x69, 0x44, 0x85, 0x65, 0xb4, 0x8a, 0xed, 0xea, 0x6e, 0x1d, 0x6b, 0x5f, 0x99, 0x93, 0x3c, 0x2a, - 0xee, 0x32, 0x1a, 0xbb, 0xb7, 0x4f, 0xbe, 0x37, 0x0b, 0x1f, 0xcf, 0x9a, 0xed, 0x90, 0x8a, 0x17, - 0x23, 0x1f, 0x07, 0x2c, 0xd2, 0x21, 0xf4, 0x4f, 0x87, 0x0f, 0x5e, 0x3a, 0x62, 0x9c, 0x00, 0x97, - 0x00, 0xee, 0x21, 0xc9, 0xff, 0x38, 0xa3, 0x37, 0xef, 0x21, 0x04, 0x47, 0x09, 0x55, 0xa6, 0xac, - 0xb5, 0x96, 0xd1, 0xae, 0xee, 0x36, 0xb0, 0x72, 0x8d, 0x73, 0xd7, 0xf8, 0x59, 0x1e, 0xcb, 0x2d, - 0x1d, 0x9f, 0x35, 0x0d, 0x6f, 0x01, 0xb3, 0x57, 0xfb, 0xf2, 0xa9, 0x73, 0xf9, 0x21, 0xc0, 0x2c, - 0xc1, 0xa3, 0xed, 0x69, 0x11, 0xd5, 0x9e, 0x40, 0x4a, 0xd9, 0x60, 0x31, 0x58, 0x17, 0x95, 0xfd, - 0x2c, 0xaa, 0x65, 0x48, 0x95, 0x9b, 0xf8, 0x0f, 0x1b, 0xc4, 0xbf, 0x0e, 0xc4, 0x2d, 0x65, 0x01, - 0x3d,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xa6, 0x76, 0x3a, 0x31, 0xb5, 0x9f, 0x13, 0x53, 0x3b, 0x9e, 0x9a, 0xa5, + 0xd3, 0xa9, 0x59, 0xfa, 0x3e, 0x35, 0x4b, 0x2f, 0xb6, 0xfe, 0xb9, 0xd5, 0xa3, 0xe2, 0x0f, 0xcf, + 0x5b, 0x15, 0x72, 0x77, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0xd0, 0x08, 0x9a, 0x3d, 0x1b, 0x05, + 0x00, 0x00, } func (m *BasicAllowance) Marshal() (dAtA []byte, err error) { diff --git a/x/feegrant/types/fees.go b/x/feegrant/fees.go similarity index 90% rename from x/feegrant/types/fees.go rename to x/feegrant/fees.go index 33073929c7cd..bd8c682608fd 100644 --- a/x/feegrant/types/fees.go +++ b/x/feegrant/fees.go @@ -1,4 +1,4 @@ -package types +package feegrant import ( sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,7 +16,7 @@ type FeeAllowanceI interface { // and will be saved again after an acceptance. // // If remove is true (regardless of the error), the FeeAllowance will be deleted from storage - // (eg. when it is used up). (See call to RevokeFeeAllowance in Keeper.UseGrantedFees) + // (eg. when it is used up). (See call to RevokeAllowance in Keeper.UseGrantedFees) Accept(ctx sdk.Context, fee sdk.Coins, msgs []sdk.Msg) (remove bool, err error) // ValidateBasic should evaluate this FeeAllowance for internal consistency. diff --git a/x/feegrant/types/filtered_fee.go b/x/feegrant/filtered_fee.go similarity index 99% rename from x/feegrant/types/filtered_fee.go rename to x/feegrant/filtered_fee.go index b9da865d0f8f..01a4afd98101 100644 --- a/x/feegrant/types/filtered_fee.go +++ b/x/feegrant/filtered_fee.go @@ -1,4 +1,4 @@ -package types +package feegrant import ( "github.com/cosmos/cosmos-sdk/codec/types" diff --git a/x/feegrant/genesis.go b/x/feegrant/genesis.go index d5cec0aacaf0..83b29baeb85d 100644 --- a/x/feegrant/genesis.go +++ b/x/feegrant/genesis.go @@ -1,29 +1,26 @@ package feegrant import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/codec/types" ) -// InitGenesis will initialize the keeper from a *previously validated* GenesisState -func InitGenesis(ctx sdk.Context, k keeper.Keeper, data *types.GenesisState) error { - for _, f := range data.Allowances { - granter, err := sdk.AccAddressFromBech32(f.Granter) - if err != nil { - return err - } - grantee, err := sdk.AccAddressFromBech32(f.Grantee) - if err != nil { - return err - } +var _ types.UnpackInterfacesMessage = GenesisState{} + +// NewGenesisState creates new GenesisState object +func NewGenesisState(entries []Grant) *GenesisState { + return &GenesisState{ + Allowances: entries, + } +} +// ValidateGenesis ensures all grants in the genesis state are valid +func ValidateGenesis(data GenesisState) error { + for _, f := range data.Allowances { grant, err := f.GetGrant() if err != nil { return err } - - err = k.GrantAllowance(ctx, granter, grantee, grant) + err = grant.ValidateBasic() if err != nil { return err } @@ -31,16 +28,19 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, data *types.GenesisState) err return nil } -// ExportGenesis will dump the contents of the keeper into a serializable GenesisState. -func ExportGenesis(ctx sdk.Context, k keeper.Keeper) (*types.GenesisState, error) { - var grants []types.Grant +// DefaultGenesisState returns default state for feegrant module. +func DefaultGenesisState() *GenesisState { + return &GenesisState{} +} - err := k.IterateAllFeeAllowances(ctx, func(grant types.Grant) bool { - grants = append(grants, grant) - return false - }) +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (data GenesisState) UnpackInterfaces(unpacker types.AnyUnpacker) error { + for _, f := range data.Allowances { + err := f.UnpackInterfaces(unpacker) + if err != nil { + return err + } + } - return &types.GenesisState{ - Allowances: grants, - }, err + return nil } diff --git a/x/feegrant/types/genesis.pb.go b/x/feegrant/genesis.pb.go similarity index 95% rename from x/feegrant/types/genesis.pb.go rename to x/feegrant/genesis.pb.go index 3a9a99102482..36593a2c8ec4 100644 --- a/x/feegrant/types/genesis.pb.go +++ b/x/feegrant/genesis.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cosmos/feegrant/v1beta1/genesis.proto -package types +package feegrant import ( fmt "fmt" @@ -77,7 +77,7 @@ func init() { } var fileDescriptor_ac719d2d0954d1bf = []byte{ - // 208 bytes of a gzipped FileDescriptorProto + // 203 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4d, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x4b, 0x4d, 0x4d, 0x2f, 0x4a, 0xcc, 0x2b, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, @@ -86,11 +86,11 @@ var fileDescriptor_ac719d2d0954d1bf = []byte{ 0xa7, 0x14, 0xc2, 0xc5, 0xe3, 0x0e, 0xb1, 0x27, 0xb8, 0x24, 0xb1, 0x24, 0x55, 0xc8, 0x85, 0x8b, 0x2b, 0x31, 0x27, 0x27, 0xbf, 0x3c, 0x31, 0x2f, 0x39, 0xb5, 0x58, 0x82, 0x51, 0x81, 0x59, 0x83, 0xdb, 0x48, 0x4e, 0x0f, 0x87, 0xdd, 0x7a, 0xee, 0x20, 0x9e, 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, - 0x41, 0x48, 0xfa, 0x9c, 0xdc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, + 0x41, 0x48, 0xfa, 0x9c, 0x1c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, - 0x37, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0xea, 0x44, 0x08, 0xa5, - 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x81, 0x70, 0x6f, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, - 0x95, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8b, 0xe8, 0xa0, 0x07, 0x25, 0x01, 0x00, 0x00, + 0x3d, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0xea, 0x44, 0x08, 0xa5, + 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x01, 0x77, 0x5e, 0x12, 0x1b, 0xd8, 0x7d, 0xc6, 0x80, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x3e, 0xdc, 0xb9, 0x91, 0x1f, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { diff --git a/x/feegrant/types/grant.go b/x/feegrant/grant.go similarity index 99% rename from x/feegrant/types/grant.go rename to x/feegrant/grant.go index 2f2dffde3335..a51e65ab5e1d 100644 --- a/x/feegrant/types/grant.go +++ b/x/feegrant/grant.go @@ -1,4 +1,4 @@ -package types +package feegrant import ( "github.com/gogo/protobuf/proto" diff --git a/x/feegrant/types/grant_test.go b/x/feegrant/grant_test.go similarity index 92% rename from x/feegrant/types/grant_test.go rename to x/feegrant/grant_test.go index 17b3b5f229d1..5fbbd8190e6f 100644 --- a/x/feegrant/types/grant_test.go +++ b/x/feegrant/grant_test.go @@ -1,4 +1,4 @@ -package types_test +package feegrant_test import ( "testing" @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) func TestGrant(t *testing.T) { @@ -75,7 +75,7 @@ func TestGrant(t *testing.T) { for name, tc := range cases { tc := tc t.Run(name, func(t *testing.T) { - grant, err := types.NewGrant(tc.granter, tc.grantee, &types.BasicAllowance{ + grant, err := feegrant.NewGrant(tc.granter, tc.grantee, &feegrant.BasicAllowance{ SpendLimit: tc.limit, Expiration: &tc.expires, }) @@ -91,7 +91,7 @@ func TestGrant(t *testing.T) { // if it is valid, let's try to serialize, deserialize, and make sure it matches bz, err := cdc.Marshal(&grant) require.NoError(t, err) - var loaded types.Grant + var loaded feegrant.Grant err = cdc.Unmarshal(bz, &loaded) require.NoError(t, err) diff --git a/x/feegrant/genesis_test.go b/x/feegrant/keeper/genesis_test.go similarity index 79% rename from x/feegrant/genesis_test.go rename to x/feegrant/keeper/genesis_test.go index ffccd4663d70..51203dbb6a77 100644 --- a/x/feegrant/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -1,4 +1,4 @@ -package feegrant_test +package keeper_test import ( "testing" @@ -11,9 +11,8 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" - feegrant "github.com/cosmos/cosmos-sdk/x/feegrant" + "github.com/cosmos/cosmos-sdk/x/feegrant" "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" ) type GenesisTestSuite struct { @@ -42,22 +41,22 @@ func (suite *GenesisTestSuite) TestImportExportGenesis() { oneYear := now.AddDate(1, 0, 0) msgSrvr := keeper.NewMsgServerImpl(suite.keeper) - allowance := &types.BasicAllowance{SpendLimit: coins, Expiration: &oneYear} + allowance := &feegrant.BasicAllowance{SpendLimit: coins, Expiration: &oneYear} err := suite.keeper.GrantAllowance(suite.ctx, granterAddr, granteeAddr, allowance) suite.Require().NoError(err) - genesis, err := feegrant.ExportGenesis(suite.ctx, suite.keeper) + genesis, err := suite.keeper.ExportGenesis(suite.ctx) suite.Require().NoError(err) // revoke fee allowance - _, err = msgSrvr.RevokeAllowance(sdk.WrapSDKContext(suite.ctx), &types.MsgRevokeAllowance{ + _, err = msgSrvr.RevokeAllowance(sdk.WrapSDKContext(suite.ctx), &feegrant.MsgRevokeAllowance{ Granter: granterAddr.String(), Grantee: granteeAddr.String(), }) suite.Require().NoError(err) - err = feegrant.InitGenesis(suite.ctx, suite.keeper, genesis) + err = suite.keeper.InitGenesis(suite.ctx, genesis) suite.Require().NoError(err) - newGenesis, err := feegrant.ExportGenesis(suite.ctx, suite.keeper) + newGenesis, err := suite.keeper.ExportGenesis(suite.ctx) suite.Require().NoError(err) suite.Require().Equal(genesis, newGenesis) } @@ -68,11 +67,11 @@ func (suite *GenesisTestSuite) TestInitGenesis() { testCases := []struct { name string - feeAllowances []types.Grant + feeAllowances []feegrant.Grant }{ { "invalid granter", - []types.Grant{ + []feegrant.Grant{ { Granter: "invalid granter", Grantee: granteeAddr.String(), @@ -81,7 +80,7 @@ func (suite *GenesisTestSuite) TestInitGenesis() { }, { "invalid grantee", - []types.Grant{ + []feegrant.Grant{ { Granter: granterAddr.String(), Grantee: "invalid grantee", @@ -90,7 +89,7 @@ func (suite *GenesisTestSuite) TestInitGenesis() { }, { "invalid allowance", - []types.Grant{ + []feegrant.Grant{ { Granter: granterAddr.String(), Grantee: granteeAddr.String(), @@ -103,7 +102,7 @@ func (suite *GenesisTestSuite) TestInitGenesis() { for _, tc := range testCases { tc := tc suite.Run(tc.name, func() { - err := feegrant.InitGenesis(suite.ctx, suite.keeper, &types.GenesisState{Allowances: tc.feeAllowances}) + err := suite.keeper.InitGenesis(suite.ctx, &feegrant.GenesisState{Allowances: tc.feeAllowances}) suite.Require().Error(err) }) } diff --git a/x/feegrant/keeper/grpc_query.go b/x/feegrant/keeper/grpc_query.go index 2730c3032725..d8c23d0313cf 100644 --- a/x/feegrant/keeper/grpc_query.go +++ b/x/feegrant/keeper/grpc_query.go @@ -11,13 +11,13 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) -var _ types.QueryServer = Keeper{} +var _ feegrant.QueryServer = Keeper{} // Allowance returns fee granted to the grantee by the granter. -func (q Keeper) Allowance(c context.Context, req *types.QueryAllowanceRequest) (*types.QueryAllowanceResponse, error) { +func (q Keeper) Allowance(c context.Context, req *feegrant.QueryAllowanceRequest) (*feegrant.QueryAllowanceResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -49,8 +49,8 @@ func (q Keeper) Allowance(c context.Context, req *types.QueryAllowanceRequest) ( return nil, status.Errorf(codes.Internal, err.Error()) } - return &types.QueryAllowanceResponse{ - Allowance: &types.Grant{ + return &feegrant.QueryAllowanceResponse{ + Allowance: &feegrant.Grant{ Granter: granterAddr.String(), Grantee: granteeAddr.String(), Allowance: feeAllowanceAny, @@ -59,7 +59,7 @@ func (q Keeper) Allowance(c context.Context, req *types.QueryAllowanceRequest) ( } // Allowances queries all the allowances granted to the given grantee. -func (q Keeper) Allowances(c context.Context, req *types.QueryAllowancesRequest) (*types.QueryAllowancesResponse, error) { +func (q Keeper) Allowances(c context.Context, req *feegrant.QueryAllowancesRequest) (*feegrant.QueryAllowancesResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -71,13 +71,13 @@ func (q Keeper) Allowances(c context.Context, req *types.QueryAllowancesRequest) ctx := sdk.UnwrapSDKContext(c) - var grants []*types.Grant + var grants []*feegrant.Grant store := ctx.KVStore(q.storeKey) - grantsStore := prefix.NewStore(store, types.FeeAllowancePrefixByGrantee(granteeAddr)) + grantsStore := prefix.NewStore(store, feegrant.FeeAllowancePrefixByGrantee(granteeAddr)) pageRes, err := query.Paginate(grantsStore, req.Pagination, func(key []byte, value []byte) error { - var grant types.Grant + var grant feegrant.Grant if err := q.cdc.Unmarshal(value, &grant); err != nil { return err @@ -91,5 +91,5 @@ func (q Keeper) Allowances(c context.Context, req *types.QueryAllowancesRequest) return nil, status.Error(codes.Internal, err.Error()) } - return &types.QueryAllowancesResponse{Allowances: grants, Pagination: pageRes}, nil + return &feegrant.QueryAllowancesResponse{Allowances: grants, Pagination: pageRes}, nil } diff --git a/x/feegrant/keeper/grpc_query_test.go b/x/feegrant/keeper/grpc_query_test.go index 55432ae0cba2..299b1b121eed 100644 --- a/x/feegrant/keeper/grpc_query_test.go +++ b/x/feegrant/keeper/grpc_query_test.go @@ -2,58 +2,58 @@ package keeper_test import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) func (suite *KeeperTestSuite) TestFeeAllowance() { testCases := []struct { name string - req *types.QueryAllowanceRequest + req *feegrant.QueryAllowanceRequest expectErr bool preRun func() - postRun func(_ *types.QueryAllowanceResponse) + postRun func(_ *feegrant.QueryAllowanceResponse) }{ { "nil request", nil, true, func() {}, - func(*types.QueryAllowanceResponse) {}, + func(*feegrant.QueryAllowanceResponse) {}, }, { "fail: invalid granter", - &types.QueryAllowanceRequest{ + &feegrant.QueryAllowanceRequest{ Granter: "invalid_granter", Grantee: suite.addrs[0].String(), }, true, func() {}, - func(*types.QueryAllowanceResponse) {}, + func(*feegrant.QueryAllowanceResponse) {}, }, { "fail: invalid grantee", - &types.QueryAllowanceRequest{ + &feegrant.QueryAllowanceRequest{ Granter: suite.addrs[0].String(), Grantee: "invalid_grantee", }, true, func() {}, - func(*types.QueryAllowanceResponse) {}, + func(*feegrant.QueryAllowanceResponse) {}, }, { "fail: no grants", - &types.QueryAllowanceRequest{ + &feegrant.QueryAllowanceRequest{ Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String(), }, true, func() {}, - func(*types.QueryAllowanceResponse) {}, + func(*feegrant.QueryAllowanceResponse) {}, }, { "valid query: expect single grant", - &types.QueryAllowanceRequest{ + &feegrant.QueryAllowanceRequest{ Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String(), }, @@ -61,7 +61,7 @@ func (suite *KeeperTestSuite) TestFeeAllowance() { func() { grantFeeAllowance(suite) }, - func(response *types.QueryAllowanceResponse) { + func(response *feegrant.QueryAllowanceResponse) { suite.Require().Equal(response.Allowance.Granter, suite.addrs[0].String()) suite.Require().Equal(response.Allowance.Grantee, suite.addrs[1].String()) }, @@ -85,48 +85,48 @@ func (suite *KeeperTestSuite) TestFeeAllowance() { func (suite *KeeperTestSuite) TestFeeAllowances() { testCases := []struct { name string - req *types.QueryAllowancesRequest + req *feegrant.QueryAllowancesRequest expectErr bool preRun func() - postRun func(_ *types.QueryAllowancesResponse) + postRun func(_ *feegrant.QueryAllowancesResponse) }{ { "nil request", nil, true, func() {}, - func(*types.QueryAllowancesResponse) {}, + func(*feegrant.QueryAllowancesResponse) {}, }, { "fail: invalid grantee", - &types.QueryAllowancesRequest{ + &feegrant.QueryAllowancesRequest{ Grantee: "invalid_grantee", }, true, func() {}, - func(*types.QueryAllowancesResponse) {}, + func(*feegrant.QueryAllowancesResponse) {}, }, { "no grants", - &types.QueryAllowancesRequest{ + &feegrant.QueryAllowancesRequest{ Grantee: suite.addrs[1].String(), }, false, func() {}, - func(resp *types.QueryAllowancesResponse) { + func(resp *feegrant.QueryAllowancesResponse) { suite.Require().Equal(len(resp.Allowances), 0) }, }, { "valid query: expect single grant", - &types.QueryAllowancesRequest{ + &feegrant.QueryAllowancesRequest{ Grantee: suite.addrs[1].String(), }, false, func() { grantFeeAllowance(suite) }, - func(resp *types.QueryAllowancesResponse) { + func(resp *feegrant.QueryAllowancesResponse) { suite.Require().Equal(len(resp.Allowances), 1) suite.Require().Equal(resp.Allowances[0].Granter, suite.addrs[0].String()) suite.Require().Equal(resp.Allowances[0].Grantee, suite.addrs[1].String()) @@ -150,7 +150,7 @@ func (suite *KeeperTestSuite) TestFeeAllowances() { func grantFeeAllowance(suite *KeeperTestSuite) { exp := suite.sdkCtx.BlockTime().AddDate(1, 0, 0) - err := suite.app.FeeGrantKeeper.GrantAllowance(suite.sdkCtx, suite.addrs[0], suite.addrs[1], &types.BasicAllowance{ + err := suite.app.FeeGrantKeeper.GrantAllowance(suite.sdkCtx, suite.addrs[0], suite.addrs[1], &feegrant.BasicAllowance{ SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 555)), Expiration: &exp, }) diff --git a/x/feegrant/keeper/keeper.go b/x/feegrant/keeper/keeper.go index 70545631220d..fd2614ccf72e 100644 --- a/x/feegrant/keeper/keeper.go +++ b/x/feegrant/keeper/keeper.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) // Keeper manages state of all fee grants, as well as calculating approval. @@ -17,13 +17,13 @@ import ( type Keeper struct { cdc codec.BinaryCodec storeKey sdk.StoreKey - authKeeper types.AccountKeeper + authKeeper feegrant.AccountKeeper } var _ ante.FeegrantKeeper = &Keeper{} // NewKeeper creates a fee grant Keeper -func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, ak types.AccountKeeper) Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, ak feegrant.AccountKeeper) Keeper { return Keeper{ cdc: cdc, storeKey: storeKey, @@ -33,11 +33,11 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, ak types.AccountKee // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s", feegrant.ModuleName)) } // GrantAllowance creates a new grant -func (k Keeper) GrantAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress, feeAllowance types.FeeAllowanceI) error { +func (k Keeper) GrantAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress, feeAllowance feegrant.FeeAllowanceI) error { // create the account if it is not in account state granteeAcc := k.authKeeper.GetAccount(ctx, grantee) @@ -47,8 +47,8 @@ func (k Keeper) GrantAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress, } store := ctx.KVStore(k.storeKey) - key := types.FeeAllowanceKey(granter, grantee) - grant, err := types.NewGrant(granter, grantee, feeAllowance) + key := feegrant.FeeAllowanceKey(granter, grantee) + grant, err := feegrant.NewGrant(granter, grantee, feeAllowance) if err != nil { return err } @@ -62,9 +62,9 @@ func (k Keeper) GrantAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress, ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeSetFeeGrant, - sdk.NewAttribute(types.AttributeKeyGranter, grant.Granter), - sdk.NewAttribute(types.AttributeKeyGrantee, grant.Grantee), + feegrant.EventTypeSetFeeGrant, + sdk.NewAttribute(feegrant.AttributeKeyGranter, grant.Granter), + sdk.NewAttribute(feegrant.AttributeKeyGrantee, grant.Grantee), ), ) @@ -79,14 +79,14 @@ func (k Keeper) revokeAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress } store := ctx.KVStore(k.storeKey) - key := types.FeeAllowanceKey(granter, grantee) + key := feegrant.FeeAllowanceKey(granter, grantee) store.Delete(key) ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeRevokeFeeGrant, - sdk.NewAttribute(types.AttributeKeyGranter, granter.String()), - sdk.NewAttribute(types.AttributeKeyGrantee, grantee.String()), + feegrant.EventTypeRevokeFeeGrant, + sdk.NewAttribute(feegrant.AttributeKeyGranter, granter.String()), + sdk.NewAttribute(feegrant.AttributeKeyGrantee, grantee.String()), ), ) return nil @@ -95,7 +95,7 @@ func (k Keeper) revokeAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress // GetAllowance returns the allowance between the granter and grantee. // If there is none, it returns nil, nil. // Returns an error on parsing issues -func (k Keeper) GetAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress) (types.FeeAllowanceI, error) { +func (k Keeper) GetAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress) (feegrant.FeeAllowanceI, error) { grant, err := k.getGrant(ctx, granter, grantee) if err != nil { return nil, err @@ -105,15 +105,15 @@ func (k Keeper) GetAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress) ( } // getGrant returns entire grant between both accounts -func (k Keeper) getGrant(ctx sdk.Context, granter sdk.AccAddress, grantee sdk.AccAddress) (*types.Grant, error) { +func (k Keeper) getGrant(ctx sdk.Context, granter sdk.AccAddress, grantee sdk.AccAddress) (*feegrant.Grant, error) { store := ctx.KVStore(k.storeKey) - key := types.FeeAllowanceKey(granter, grantee) + key := feegrant.FeeAllowanceKey(granter, grantee) bz := store.Get(key) if len(bz) == 0 { return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "fee-grant not found") } - var feegrant types.Grant + var feegrant feegrant.Grant if err := k.cdc.Unmarshal(bz, &feegrant); err != nil { return nil, err } @@ -124,15 +124,15 @@ func (k Keeper) getGrant(ctx sdk.Context, granter sdk.AccAddress, grantee sdk.Ac // IterateAllFeeAllowances iterates over all the grants in the store. // Callback to get all data, returns true to stop, false to keep reading // Calling this without pagination is very expensive and only designed for export genesis -func (k Keeper) IterateAllFeeAllowances(ctx sdk.Context, cb func(grant types.Grant) bool) error { +func (k Keeper) IterateAllFeeAllowances(ctx sdk.Context, cb func(grant feegrant.Grant) bool) error { store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.FeeAllowanceKeyPrefix) + iter := sdk.KVStorePrefixIterator(store, feegrant.FeeAllowanceKeyPrefix) defer iter.Close() stop := false for ; iter.Valid() && !stop; iter.Next() { bz := iter.Value() - var feeGrant types.Grant + var feeGrant feegrant.Grant if err := k.cdc.Unmarshal(bz, &feeGrant); err != nil { return err } @@ -182,9 +182,48 @@ func (k Keeper) UseGrantedFees(ctx sdk.Context, granter, grantee sdk.AccAddress, func emitUseGrantEvent(ctx sdk.Context, granter, grantee string) { ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeUseFeeGrant, - sdk.NewAttribute(types.AttributeKeyGranter, granter), - sdk.NewAttribute(types.AttributeKeyGrantee, grantee), + feegrant.EventTypeUseFeeGrant, + sdk.NewAttribute(feegrant.AttributeKeyGranter, granter), + sdk.NewAttribute(feegrant.AttributeKeyGrantee, grantee), ), ) } + +// InitGenesis will initialize the keeper from a *previously validated* GenesisState +func (k Keeper) InitGenesis(ctx sdk.Context, data *feegrant.GenesisState) error { + for _, f := range data.Allowances { + granter, err := sdk.AccAddressFromBech32(f.Granter) + if err != nil { + return err + } + grantee, err := sdk.AccAddressFromBech32(f.Grantee) + if err != nil { + return err + } + + grant, err := f.GetGrant() + if err != nil { + return err + } + + err = k.GrantAllowance(ctx, granter, grantee, grant) + if err != nil { + return err + } + } + return nil +} + +// ExportGenesis will dump the contents of the keeper into a serializable GenesisState. +func (k Keeper) ExportGenesis(ctx sdk.Context) (*feegrant.GenesisState, error) { + var grants []feegrant.Grant + + err := k.IterateAllFeeAllowances(ctx, func(grant feegrant.Grant) bool { + grants = append(grants, grant) + return false + }) + + return &feegrant.GenesisState{ + Allowances: grants, + }, err +} diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index 4c63b1b917ae..b2e08734bad4 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -9,8 +9,8 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" ) type KeeperTestSuite struct { @@ -19,7 +19,7 @@ type KeeperTestSuite struct { app *simapp.SimApp sdkCtx sdk.Context addrs []sdk.AccAddress - msgSrvr types.MsgServer + msgSrvr feegrant.MsgServer ctx context.Context atom sdk.Coins keeper keeper.Keeper @@ -46,12 +46,12 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { // some helpers eth := sdk.NewCoins(sdk.NewInt64Coin("eth", 123)) exp := suite.sdkCtx.BlockTime().AddDate(1, 0, 0) - basic := &types.BasicAllowance{ + basic := &feegrant.BasicAllowance{ SpendLimit: suite.atom, Expiration: &exp, } - basic2 := &types.BasicAllowance{ + basic2 := &feegrant.BasicAllowance{ SpendLimit: eth, Expiration: &exp, } @@ -73,13 +73,13 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { suite.Require().NoError(err) // remove some, overwrite other - _, err = suite.msgSrvr.RevokeAllowance(suite.ctx, &types.MsgRevokeAllowance{Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String()}) + _, err = suite.msgSrvr.RevokeAllowance(suite.ctx, &feegrant.MsgRevokeAllowance{Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String()}) suite.Require().NoError(err) - _, err = suite.msgSrvr.RevokeAllowance(suite.ctx, &types.MsgRevokeAllowance{Granter: suite.addrs[0].String(), Grantee: suite.addrs[2].String()}) + _, err = suite.msgSrvr.RevokeAllowance(suite.ctx, &feegrant.MsgRevokeAllowance{Granter: suite.addrs[0].String(), Grantee: suite.addrs[2].String()}) suite.Require().NoError(err) // revoke non-exist fee allowance - _, err = suite.msgSrvr.RevokeAllowance(suite.ctx, &types.MsgRevokeAllowance{Granter: suite.addrs[0].String(), Grantee: suite.addrs[2].String()}) + _, err = suite.msgSrvr.RevokeAllowance(suite.ctx, &feegrant.MsgRevokeAllowance{Granter: suite.addrs[0].String(), Grantee: suite.addrs[2].String()}) suite.Require().Error(err) err = suite.keeper.GrantAllowance(suite.sdkCtx, suite.addrs[0], suite.addrs[2], basic) @@ -97,7 +97,7 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { cases := map[string]struct { grantee sdk.AccAddress granter sdk.AccAddress - allowance types.FeeAllowanceI + allowance feegrant.FeeAllowanceI }{ "addr revoked": { granter: suite.addrs[0], @@ -142,7 +142,7 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { _, err = suite.keeper.GetAllowance(suite.sdkCtx, suite.addrs[3], accAddr) suite.Require().NoError(err) - _, err = suite.msgSrvr.RevokeAllowance(suite.ctx, &types.MsgRevokeAllowance{Granter: suite.addrs[3].String(), Grantee: accAddr.String()}) + _, err = suite.msgSrvr.RevokeAllowance(suite.ctx, &feegrant.MsgRevokeAllowance{Granter: suite.addrs[3].String(), Grantee: accAddr.String()}) suite.Require().NoError(err) } @@ -152,7 +152,7 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() { blockTime := suite.sdkCtx.BlockTime() oneYear := blockTime.AddDate(1, 0, 0) - future := &types.BasicAllowance{ + future := &feegrant.BasicAllowance{ SpendLimit: suite.atom, Expiration: &oneYear, } @@ -160,7 +160,7 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() { // for testing limits of the contract hugeAtom := sdk.NewCoins(sdk.NewInt64Coin("atom", 9999)) smallAtom := sdk.NewCoins(sdk.NewInt64Coin("atom", 1)) - futureAfterSmall := &types.BasicAllowance{ + futureAfterSmall := &feegrant.BasicAllowance{ SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 554)), Expiration: &oneYear, } @@ -171,7 +171,7 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() { granter sdk.AccAddress fee sdk.Coins allowed bool - final types.FeeAllowanceI + final feegrant.FeeAllowanceI }{ "use entire pot": { granter: suite.addrs[0], @@ -214,7 +214,7 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() { }) } - expired := &types.BasicAllowance{ + expired := &feegrant.BasicAllowance{ SpendLimit: eth, Expiration: &blockTime, } @@ -239,12 +239,12 @@ func (suite *KeeperTestSuite) TestIterateGrants() { eth := sdk.NewCoins(sdk.NewInt64Coin("eth", 123)) exp := suite.sdkCtx.BlockTime().AddDate(1, 0, 0) - allowance := &types.BasicAllowance{ + allowance := &feegrant.BasicAllowance{ SpendLimit: suite.atom, Expiration: &exp, } - allowance1 := &types.BasicAllowance{ + allowance1 := &feegrant.BasicAllowance{ SpendLimit: eth, Expiration: &exp, } @@ -252,7 +252,7 @@ func (suite *KeeperTestSuite) TestIterateGrants() { suite.keeper.GrantAllowance(suite.sdkCtx, suite.addrs[0], suite.addrs[1], allowance) suite.keeper.GrantAllowance(suite.sdkCtx, suite.addrs[2], suite.addrs[1], allowance1) - suite.keeper.IterateAllFeeAllowances(suite.sdkCtx, func(grant types.Grant) bool { + suite.keeper.IterateAllFeeAllowances(suite.sdkCtx, func(grant feegrant.Grant) bool { suite.Require().Equal(suite.addrs[1].String(), grant.Grantee) suite.Require().Contains([]string{suite.addrs[0].String(), suite.addrs[2].String()}, grant.Granter) return true diff --git a/x/feegrant/keeper/msg_server.go b/x/feegrant/keeper/msg_server.go index ea5ab277ccb6..044e7b57e170 100644 --- a/x/feegrant/keeper/msg_server.go +++ b/x/feegrant/keeper/msg_server.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) type msgServer struct { @@ -15,16 +15,16 @@ type msgServer struct { // NewMsgServerImpl returns an implementation of the feegrant MsgServer interface // for the provided Keeper. -func NewMsgServerImpl(k Keeper) types.MsgServer { +func NewMsgServerImpl(k Keeper) feegrant.MsgServer { return &msgServer{ Keeper: k, } } -var _ types.MsgServer = msgServer{} +var _ feegrant.MsgServer = msgServer{} // GrantAllowance grants an allowance from the granter's funds to be used by the grantee. -func (k msgServer) GrantAllowance(goCtx context.Context, msg *types.MsgGrantAllowance) (*types.MsgGrantAllowanceResponse, error) { +func (k msgServer) GrantAllowance(goCtx context.Context, msg *feegrant.MsgGrantAllowance) (*feegrant.MsgGrantAllowanceResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) @@ -52,11 +52,11 @@ func (k msgServer) GrantAllowance(goCtx context.Context, msg *types.MsgGrantAllo return nil, err } - return &types.MsgGrantAllowanceResponse{}, nil + return &feegrant.MsgGrantAllowanceResponse{}, nil } // RevokeAllowance revokes a fee allowance between a granter and grantee. -func (k msgServer) RevokeAllowance(goCtx context.Context, msg *types.MsgRevokeAllowance) (*types.MsgRevokeAllowanceResponse, error) { +func (k msgServer) RevokeAllowance(goCtx context.Context, msg *feegrant.MsgRevokeAllowance) (*feegrant.MsgRevokeAllowanceResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := sdk.AccAddressFromBech32(msg.Grantee) @@ -74,5 +74,5 @@ func (k msgServer) RevokeAllowance(goCtx context.Context, msg *types.MsgRevokeAl return nil, err } - return &types.MsgRevokeAllowanceResponse{}, nil + return &feegrant.MsgRevokeAllowanceResponse{}, nil } diff --git a/x/feegrant/keeper/msg_server_test.go b/x/feegrant/keeper/msg_server_test.go index e00f618ffd7c..40d3443973bc 100644 --- a/x/feegrant/keeper/msg_server_test.go +++ b/x/feegrant/keeper/msg_server_test.go @@ -3,24 +3,24 @@ package keeper_test import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) -func (suite *KeeperTestSuite) TestGrantFeeAllowance() { +func (suite *KeeperTestSuite) TestGrantAllowance() { oneYear := suite.sdkCtx.BlockTime().AddDate(1, 0, 0) testCases := []struct { name string - req func() *types.MsgGrantAllowance + req func() *feegrant.MsgGrantAllowance expectErr bool errMsg string }{ { "invalid granter address", - func() *types.MsgGrantAllowance { - any, err := codectypes.NewAnyWithValue(&types.BasicAllowance{}) + func() *feegrant.MsgGrantAllowance { + any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{}) suite.Require().NoError(err) - return &types.MsgGrantAllowance{ + return &feegrant.MsgGrantAllowance{ Granter: "invalid-granter", Grantee: suite.addrs[1].String(), Allowance: any, @@ -31,10 +31,10 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() { }, { "invalid grantee address", - func() *types.MsgGrantAllowance { - any, err := codectypes.NewAnyWithValue(&types.BasicAllowance{}) + func() *feegrant.MsgGrantAllowance { + any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{}) suite.Require().NoError(err) - return &types.MsgGrantAllowance{ + return &feegrant.MsgGrantAllowance{ Granter: suite.addrs[0].String(), Grantee: "invalid-grantee", Allowance: any, @@ -45,13 +45,13 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() { }, { "valid: basic fee allowance", - func() *types.MsgGrantAllowance { - any, err := codectypes.NewAnyWithValue(&types.BasicAllowance{ + func() *feegrant.MsgGrantAllowance { + any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{ SpendLimit: suite.atom, Expiration: &oneYear, }) suite.Require().NoError(err) - return &types.MsgGrantAllowance{ + return &feegrant.MsgGrantAllowance{ Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String(), Allowance: any, @@ -62,13 +62,13 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() { }, { "fail: fee allowance exists", - func() *types.MsgGrantAllowance { - any, err := codectypes.NewAnyWithValue(&types.BasicAllowance{ + func() *feegrant.MsgGrantAllowance { + any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{ SpendLimit: suite.atom, Expiration: &oneYear, }) suite.Require().NoError(err) - return &types.MsgGrantAllowance{ + return &feegrant.MsgGrantAllowance{ Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String(), Allowance: any, @@ -79,15 +79,15 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() { }, { "valid: periodic fee allowance", - func() *types.MsgGrantAllowance { - any, err := codectypes.NewAnyWithValue(&types.PeriodicAllowance{ - Basic: types.BasicAllowance{ + func() *feegrant.MsgGrantAllowance { + any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ SpendLimit: suite.atom, Expiration: &oneYear, }, }) suite.Require().NoError(err) - return &types.MsgGrantAllowance{ + return &feegrant.MsgGrantAllowance{ Granter: suite.addrs[1].String(), Grantee: suite.addrs[2].String(), Allowance: any, @@ -98,15 +98,15 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() { }, { "error: fee allowance exists", - func() *types.MsgGrantAllowance { - any, err := codectypes.NewAnyWithValue(&types.PeriodicAllowance{ - Basic: types.BasicAllowance{ + func() *feegrant.MsgGrantAllowance { + any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ SpendLimit: suite.atom, Expiration: &oneYear, }, }) suite.Require().NoError(err) - return &types.MsgGrantAllowance{ + return &feegrant.MsgGrantAllowance{ Granter: suite.addrs[1].String(), Grantee: suite.addrs[2].String(), Allowance: any, @@ -127,19 +127,19 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() { } } -func (suite *KeeperTestSuite) TestRevokeFeeAllowance() { +func (suite *KeeperTestSuite) TestRevokeAllowance() { oneYear := suite.sdkCtx.BlockTime().AddDate(1, 0, 0) testCases := []struct { name string - request *types.MsgRevokeAllowance + request *feegrant.MsgRevokeAllowance preRun func() expectErr bool errMsg string }{ { "error: invalid granter", - &types.MsgRevokeAllowance{ + &feegrant.MsgRevokeAllowance{ Granter: "invalid-granter", Grantee: suite.addrs[1].String(), }, @@ -149,7 +149,7 @@ func (suite *KeeperTestSuite) TestRevokeFeeAllowance() { }, { "error: invalid grantee", - &types.MsgRevokeAllowance{ + &feegrant.MsgRevokeAllowance{ Granter: suite.addrs[0].String(), Grantee: "invalid-grantee", }, @@ -159,7 +159,7 @@ func (suite *KeeperTestSuite) TestRevokeFeeAllowance() { }, { "error: fee allowance not found", - &types.MsgRevokeAllowance{ + &feegrant.MsgRevokeAllowance{ Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String(), }, @@ -169,24 +169,24 @@ func (suite *KeeperTestSuite) TestRevokeFeeAllowance() { }, { "success: revoke fee allowance", - &types.MsgRevokeAllowance{ + &feegrant.MsgRevokeAllowance{ Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String(), }, func() { // removing fee allowance from previous tests if exists - suite.msgSrvr.RevokeAllowance(suite.ctx, &types.MsgRevokeAllowance{ + suite.msgSrvr.RevokeAllowance(suite.ctx, &feegrant.MsgRevokeAllowance{ Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String(), }) - any, err := codectypes.NewAnyWithValue(&types.PeriodicAllowance{ - Basic: types.BasicAllowance{ + any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ SpendLimit: suite.atom, Expiration: &oneYear, }, }) suite.Require().NoError(err) - req := &types.MsgGrantAllowance{ + req := &feegrant.MsgGrantAllowance{ Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String(), Allowance: any, @@ -199,7 +199,7 @@ func (suite *KeeperTestSuite) TestRevokeFeeAllowance() { }, { "error: check fee allowance revoked", - &types.MsgRevokeAllowance{ + &feegrant.MsgRevokeAllowance{ Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String(), }, diff --git a/x/feegrant/types/key.go b/x/feegrant/key.go similarity index 98% rename from x/feegrant/types/key.go rename to x/feegrant/key.go index 7cd1ce4f8c8f..cfc885d9a7a1 100644 --- a/x/feegrant/types/key.go +++ b/x/feegrant/key.go @@ -1,4 +1,4 @@ -package types +package feegrant import ( sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/feegrant/module.go b/x/feegrant/module/module.go similarity index 85% rename from x/feegrant/module.go rename to x/feegrant/module/module.go index c50547433581..4690aea250ef 100644 --- a/x/feegrant/module.go +++ b/x/feegrant/module/module.go @@ -1,4 +1,4 @@ -package feegrant +package module import ( "context" @@ -18,10 +18,10 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/feegrant" "github.com/cosmos/cosmos-sdk/x/feegrant/client/cli" "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" "github.com/cosmos/cosmos-sdk/x/feegrant/simulation" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" ) var ( @@ -41,14 +41,14 @@ type AppModuleBasic struct { // Name returns the feegrant module's name. func (AppModuleBasic) Name() string { - return types.ModuleName + return feegrant.ModuleName } // RegisterServices registers a gRPC query service to respond to the // module-specific gRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) - types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + feegrant.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + feegrant.RegisterQueryServer(cfg.QueryServer(), am.keeper) } // RegisterLegacyAminoCodec registers the feegrant module's types for the given codec. @@ -57,7 +57,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // RegisterInterfaces registers the feegrant module's interface types func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - types.RegisterInterfaces(registry) + feegrant.RegisterInterfaces(registry) } // LegacyQuerierHandler returns the feegrant module sdk.Querier. @@ -68,17 +68,17 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd // DefaultGenesis returns default genesis state as raw bytes for the feegrant // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) + return cdc.MustMarshalJSON(feegrant.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the feegrant module. func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error { - var data types.GenesisState + var data feegrant.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { - sdkerrors.Wrapf(err, "failed to unmarshal %s genesis state", types.ModuleName) + sdkerrors.Wrapf(err, "failed to unmarshal %s genesis state", feegrant.ModuleName) } - return types.ValidateGenesis(data) + return feegrant.ValidateGenesis(data) } // RegisterRESTRoutes registers the REST routes for the feegrant module. @@ -86,7 +86,7 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx sdkclient.Context, rtr *mux.Router) // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the feegrant module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + feegrant.RegisterQueryHandlerClient(context.Background(), mux, feegrant.NewQueryClient(clientCtx)) } // GetTxCmd returns the root tx command for the feegrant module. @@ -107,13 +107,13 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { type AppModule struct { AppModuleBasic keeper keeper.Keeper - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper + accountKeeper feegrant.AccountKeeper + bankKeeper feegrant.BankKeeper registry cdctypes.InterfaceRegistry } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, ak types.AccountKeeper, bk types.BankKeeper, keeper keeper.Keeper, registry cdctypes.InterfaceRegistry) AppModule { +func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, keeper keeper.Keeper, registry cdctypes.InterfaceRegistry) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, @@ -125,7 +125,7 @@ func NewAppModule(cdc codec.Codec, ak types.AccountKeeper, bk types.BankKeeper, // Name returns the feegrant module's name. func (AppModule) Name() string { - return types.ModuleName + return feegrant.ModuleName } // RegisterInvariants registers the feegrant module invariants. @@ -133,7 +133,7 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} // Route returns the message routing key for the feegrant module. func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(types.RouterKey, nil) + return sdk.NewRoute(feegrant.RouterKey, nil) } // NewHandler returns an sdk.Handler for the feegrant module. @@ -149,10 +149,10 @@ func (AppModule) QuerierRoute() string { // InitGenesis performs genesis initialization for the feegrant module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { - var gs types.GenesisState + var gs feegrant.GenesisState cdc.MustUnmarshalJSON(bz, &gs) - err := InitGenesis(ctx, am.keeper, &gs) + err := am.keeper.InitGenesis(ctx, &gs) if err != nil { panic(err) } @@ -162,7 +162,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.Ra // ExportGenesis returns the exported genesis state as raw bytes for the feegrant // module. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs, err := ExportGenesis(ctx, am.keeper) + gs, err := am.keeper.ExportGenesis(ctx) if err != nil { panic(err) } @@ -202,7 +202,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { // RegisterStoreDecoder registers a decoder for feegrant module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { - sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) + sdr[feegrant.StoreKey] = simulation.NewDecodeStore(am.cdc) } // WeightedOperations returns all the feegrant module operations with their respective weights. diff --git a/x/feegrant/types/msgs.go b/x/feegrant/msgs.go similarity index 97% rename from x/feegrant/types/msgs.go rename to x/feegrant/msgs.go index 6beb20154438..3731668a91a5 100644 --- a/x/feegrant/types/msgs.go +++ b/x/feegrant/msgs.go @@ -1,4 +1,4 @@ -package types +package feegrant import ( "github.com/gogo/protobuf/proto" @@ -13,7 +13,7 @@ var ( _ types.UnpackInterfacesMessage = &MsgGrantAllowance{} ) -// NewMsgGrantAllowance creates a new MsgGrantFeeAllowance. +// NewMsgGrantAllowance creates a new MsgGrantAllowance. //nolint:interfacer func NewMsgGrantAllowance(feeAllowance FeeAllowanceI, granter, grantee sdk.AccAddress) (*MsgGrantAllowance, error) { msg, ok := feeAllowance.(proto.Message) diff --git a/x/feegrant/types/msgs_test.go b/x/feegrant/msgs_test.go similarity index 85% rename from x/feegrant/types/msgs_test.go rename to x/feegrant/msgs_test.go index 344a97003938..30319da2b442 100644 --- a/x/feegrant/types/msgs_test.go +++ b/x/feegrant/msgs_test.go @@ -1,4 +1,4 @@ -package types_test +package feegrant_test import ( "testing" @@ -7,17 +7,17 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" "github.com/stretchr/testify/require" ) -func TestMsgGrantFeeAllowance(t *testing.T) { +func TestMsgGrantAllowance(t *testing.T) { cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) addr, _ := sdk.AccAddressFromBech32("cosmos1aeuqja06474dfrj7uqsvukm6rael982kk89mqr") addr2, _ := sdk.AccAddressFromBech32("cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl") atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555)) threeHours := time.Now().Add(3 * time.Hour) - basic := &types.BasicAllowance{ + basic := &feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &threeHours, } @@ -25,7 +25,7 @@ func TestMsgGrantFeeAllowance(t *testing.T) { cases := map[string]struct { grantee sdk.AccAddress granter sdk.AccAddress - grant *types.BasicAllowance + grant *feegrant.BasicAllowance valid bool }{ "valid": { @@ -55,7 +55,7 @@ func TestMsgGrantFeeAllowance(t *testing.T) { } for _, tc := range cases { - msg, err := types.NewMsgGrantAllowance(tc.grant, tc.granter, tc.grantee) + msg, err := feegrant.NewMsgGrantAllowance(tc.grant, tc.granter, tc.grantee) require.NoError(t, err) err = msg.ValidateBasic() @@ -77,20 +77,20 @@ func TestMsgGrantFeeAllowance(t *testing.T) { } } -func TestMsgRevokeFeeAllowance(t *testing.T) { +func TestMsgRevokeAllowance(t *testing.T) { addr, _ := sdk.AccAddressFromBech32("cosmos1aeuqja06474dfrj7uqsvukm6rael982kk89mqr") addr2, _ := sdk.AccAddressFromBech32("cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl") atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555)) threeHours := time.Now().Add(3 * time.Hour) - basic := &types.BasicAllowance{ + basic := &feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &threeHours, } cases := map[string]struct { grantee sdk.AccAddress granter sdk.AccAddress - grant *types.BasicAllowance + grant *feegrant.BasicAllowance valid bool }{ "valid": { @@ -120,7 +120,7 @@ func TestMsgRevokeFeeAllowance(t *testing.T) { } for _, tc := range cases { - msg := types.NewMsgRevokeAllowance(tc.granter, tc.grantee) + msg := feegrant.NewMsgRevokeAllowance(tc.granter, tc.grantee) err := msg.ValidateBasic() if tc.valid { require.NoError(t, err) diff --git a/x/feegrant/types/periodic_fee.go b/x/feegrant/periodic_fee.go similarity index 97% rename from x/feegrant/types/periodic_fee.go rename to x/feegrant/periodic_fee.go index eb1edd044edf..63c9e748526f 100644 --- a/x/feegrant/types/periodic_fee.go +++ b/x/feegrant/periodic_fee.go @@ -1,4 +1,4 @@ -package types +package feegrant import ( "time" @@ -18,7 +18,7 @@ var _ FeeAllowanceI = (*PeriodicAllowance)(nil) // and will be saved again after an acceptance. // // If remove is true (regardless of the error), the FeeAllowance will be deleted from storage -// (eg. when it is used up). (See call to RevokeFeeAllowance in Keeper.UseGrantedFees) +// (eg. when it is used up). (See call to RevokeAllowance in Keeper.UseGrantedFees) func (a *PeriodicAllowance) Accept(ctx sdk.Context, fee sdk.Coins, _ []sdk.Msg) (bool, error) { blockTime := ctx.BlockTime() diff --git a/x/feegrant/types/periodic_fee_test.go b/x/feegrant/periodic_fee_test.go similarity index 86% rename from x/feegrant/types/periodic_fee_test.go rename to x/feegrant/periodic_fee_test.go index 8d5273f9ac5b..a09459cb722e 100644 --- a/x/feegrant/types/periodic_fee_test.go +++ b/x/feegrant/periodic_fee_test.go @@ -1,4 +1,4 @@ -package types_test +package feegrant_test import ( "testing" @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) func TestPeriodicFeeValidAllow(t *testing.T) { @@ -31,7 +31,7 @@ func TestPeriodicFeeValidAllow(t *testing.T) { tenMinutes := time.Duration(10) * time.Minute cases := map[string]struct { - allow types.PeriodicAllowance + allow feegrant.PeriodicAllowance // all other checks are ignored if valid=false fee sdk.Coins blockTime time.Time @@ -43,12 +43,12 @@ func TestPeriodicFeeValidAllow(t *testing.T) { periodReset time.Time }{ "empty": { - allow: types.PeriodicAllowance{}, + allow: feegrant.PeriodicAllowance{}, valid: false, }, "only basic": { - allow: types.PeriodicAllowance{ - Basic: types.BasicAllowance{ + allow: feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &oneHour, }, @@ -56,7 +56,7 @@ func TestPeriodicFeeValidAllow(t *testing.T) { valid: false, }, "empty basic": { - allow: types.PeriodicAllowance{ + allow: feegrant.PeriodicAllowance{ Period: tenMinutes, PeriodSpendLimit: smallAtom, PeriodReset: now.Add(30 * time.Minute), @@ -68,8 +68,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) { periodReset: now.Add(30 * time.Minute), }, "mismatched currencies": { - allow: types.PeriodicAllowance{ - Basic: types.BasicAllowance{ + allow: feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &oneHour, }, @@ -79,8 +79,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) { valid: false, }, "same period": { - allow: types.PeriodicAllowance{ - Basic: types.BasicAllowance{ + allow: feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &twoHours, }, @@ -99,8 +99,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) { periodReset: now.Add(1 * time.Hour), }, "step one period": { - allow: types.PeriodicAllowance{ - Basic: types.BasicAllowance{ + allow: feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &twoHours, }, @@ -118,8 +118,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) { periodReset: oneHour.Add(10 * time.Minute), // one step from last reset, not now }, "step limited by global allowance": { - allow: types.PeriodicAllowance{ - Basic: types.BasicAllowance{ + allow: feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ SpendLimit: smallAtom, Expiration: &twoHours, }, @@ -137,8 +137,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) { periodReset: oneHour.Add(10 * time.Minute), // one step from last reset, not now }, "expired": { - allow: types.PeriodicAllowance{ - Basic: types.BasicAllowance{ + allow: feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &now, }, @@ -152,8 +152,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) { remove: true, }, "over period limit": { - allow: types.PeriodicAllowance{ - Basic: types.BasicAllowance{ + allow: feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ SpendLimit: atom, Expiration: &now, }, diff --git a/x/feegrant/types/query.pb.go b/x/feegrant/query.pb.go similarity index 91% rename from x/feegrant/types/query.pb.go rename to x/feegrant/query.pb.go index 874226e365b6..94368d66649b 100644 --- a/x/feegrant/types/query.pb.go +++ b/x/feegrant/query.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cosmos/feegrant/v1beta1/query.proto -package types +package feegrant import ( context "context" @@ -251,34 +251,34 @@ func init() { } var fileDescriptor_59efc303945de53f = []byte{ - // 432 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xc1, 0xca, 0xd3, 0x40, - 0x10, 0xc7, 0xbb, 0x15, 0x95, 0x6e, 0x6f, 0x0b, 0xda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0xbf, 0xad, 0xd3, 0x78, 0xd3, 0x0f, 0x42, 0xf5, 0x7e, 0xe1, 0xd3, 0x89, 0x98, 0x19, - 0xcb, 0xf4, 0xd1, 0x97, 0x6f, 0x3f, 0xb0, 0xcf, 0x85, 0xbf, 0x5a, 0xc6, 0x20, 0xfd, 0x6b, 0xfa, - 0xbf, 0x7b, 0x70, 0x11, 0x00, 0x00, 0xff, 0xff, 0x86, 0xb1, 0x57, 0xa8, 0x29, 0x04, 0x00, 0x00, + // 430 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4e, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x4b, 0x4d, 0x4d, 0x2f, 0x4a, 0xcc, 0x2b, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, + 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, + 0x12, 0x87, 0x28, 0xd2, 0x83, 0x29, 0xd2, 0x83, 0x2a, 0x92, 0x52, 0xc3, 0xa5, 0x1b, 0xae, 0x12, + 0x6c, 0x80, 0x94, 0x16, 0x54, 0x5d, 0x52, 0x62, 0x71, 0x2a, 0xc4, 0x64, 0xb8, 0xca, 0x82, 0xc4, + 0xf4, 0xcc, 0xbc, 0xc4, 0x92, 0xcc, 0xfc, 0x3c, 0xa8, 0x5a, 0x99, 0xf4, 0xfc, 0xfc, 0xf4, 0x9c, + 0x54, 0xfd, 0xc4, 0x82, 0x4c, 0xfd, 0xc4, 0xbc, 0xbc, 0xfc, 0x12, 0xb0, 0x64, 0x31, 0x44, 0x56, + 0xc9, 0x9b, 0x4b, 0x34, 0x10, 0xa4, 0xdf, 0x31, 0x27, 0x27, 0xbf, 0x3c, 0x31, 0x2f, 0x39, 0x35, + 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0x44, 0x48, 0x82, 0x8b, 0x1d, 0x6c, 0x63, 0x6a, 0x91, 0x04, + 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x8c, 0x8b, 0x90, 0x49, 0x95, 0x60, 0x42, 0x96, 0x49, 0x55, + 0x0a, 0xe3, 0x12, 0x43, 0x37, 0xac, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0xc8, 0x86, 0x8b, 0x33, + 0x11, 0x26, 0x08, 0x36, 0x8f, 0xdb, 0x48, 0x4e, 0x0f, 0x47, 0x28, 0xe8, 0xb9, 0x83, 0x78, 0x41, + 0x08, 0x0d, 0x4a, 0x55, 0xe8, 0xe6, 0x16, 0x63, 0xb8, 0x32, 0x15, 0xd5, 0x95, 0xa9, 0x42, 0x6e, + 0x5c, 0x5c, 0x88, 0xa0, 0x00, 0x3b, 0x94, 0xdb, 0x48, 0x0d, 0x66, 0x25, 0x28, 0xdc, 0xf4, 0x20, + 0x31, 0x02, 0xb3, 0x34, 0x20, 0x31, 0x1d, 0xe6, 0xf7, 0x20, 0x24, 0x9d, 0x4a, 0x8b, 0x18, 0xb9, + 0xc4, 0x31, 0x2c, 0x87, 0xfa, 0xca, 0x8e, 0x8b, 0x0b, 0xee, 0xc8, 0x62, 0x09, 0x46, 0x05, 0x66, + 0x22, 0xbc, 0x85, 0xa4, 0x43, 0xc8, 0x1d, 0x8b, 0x1b, 0xd5, 0x09, 0xba, 0x11, 0x62, 0x39, 0xb2, + 0x23, 0x8d, 0xee, 0x33, 0x71, 0xb1, 0x82, 0x1d, 0x29, 0xb4, 0x86, 0x91, 0x8b, 0x13, 0xee, 0x52, + 0x21, 0x3d, 0x9c, 0x8e, 0xc1, 0x1a, 0xe9, 0x52, 0xfa, 0x44, 0xab, 0x87, 0x38, 0x42, 0xc9, 0xae, + 0xe9, 0xf2, 0x93, 0xc9, 0x4c, 0x16, 0x42, 0x66, 0xfa, 0xb8, 0x52, 0x2e, 0xdc, 0xbb, 0xfa, 0xd5, + 0xd0, 0x04, 0x54, 0x0b, 0x63, 0xa5, 0xd6, 0x0a, 0x2d, 0x63, 0xe4, 0xe2, 0x42, 0x04, 0xac, 0x10, + 0xb1, 0xf6, 0xc3, 0xe2, 0x5f, 0xca, 0x80, 0x78, 0x0d, 0x50, 0x17, 0x9b, 0x82, 0x5d, 0xac, 0x2f, + 0xa4, 0x4b, 0xd8, 0xc5, 0xc5, 0x08, 0x87, 0x3a, 0x39, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, + 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, + 0xb1, 0x1c, 0x43, 0x94, 0x7a, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0x2e, 0xcc, + 0x48, 0x08, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x01, 0x37, 0x3f, 0x89, 0x0d, 0x9c, 0xe3, 0x8c, + 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x19, 0x08, 0xf0, 0xae, 0x23, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/feegrant/types/query.pb.gw.go b/x/feegrant/query.pb.gw.go similarity index 99% rename from x/feegrant/types/query.pb.gw.go rename to x/feegrant/query.pb.gw.go index 876ec84df691..06689435e071 100644 --- a/x/feegrant/types/query.pb.gw.go +++ b/x/feegrant/query.pb.gw.go @@ -2,11 +2,11 @@ // source: cosmos/feegrant/v1beta1/query.proto /* -Package types is a reverse proxy. +Package feegrant is a reverse proxy. It translates gRPC into RESTful JSON APIs. */ -package types +package feegrant import ( "context" diff --git a/x/feegrant/simulation/decoder.go b/x/feegrant/simulation/decoder.go index 5e09222899ba..bc0cc1fed623 100644 --- a/x/feegrant/simulation/decoder.go +++ b/x/feegrant/simulation/decoder.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's @@ -14,8 +14,8 @@ import ( func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { return func(kvA, kvB kv.Pair) string { switch { - case bytes.Equal(kvA.Key[:1], types.FeeAllowanceKeyPrefix): - var grantA, grantB types.Grant + case bytes.Equal(kvA.Key[:1], feegrant.FeeAllowanceKeyPrefix): + var grantA, grantB feegrant.Grant cdc.MustUnmarshal(kvA.Value, &grantA) cdc.MustUnmarshal(kvB.Value, &grantB) return fmt.Sprintf("%v\n%v", grantA, grantB) diff --git a/x/feegrant/simulation/decoder_test.go b/x/feegrant/simulation/decoder_test.go index 74de5f77dfb2..57ed0dfa1a17 100644 --- a/x/feegrant/simulation/decoder_test.go +++ b/x/feegrant/simulation/decoder_test.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/cosmos/cosmos-sdk/x/feegrant" "github.com/cosmos/cosmos-sdk/x/feegrant/simulation" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" ) var ( @@ -25,7 +25,7 @@ func TestDecodeStore(t *testing.T) { cdc := simapp.MakeTestEncodingConfig().Marshaler dec := simulation.NewDecodeStore(cdc) - grant, err := types.NewGrant(granterAddr, granteeAddr, &types.BasicAllowance{ + grant, err := feegrant.NewGrant(granterAddr, granteeAddr, &feegrant.BasicAllowance{ SpendLimit: sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(100))), }) @@ -36,7 +36,7 @@ func TestDecodeStore(t *testing.T) { kvPairs := kv.Pairs{ Pairs: []kv.Pair{ - {Key: []byte(types.FeeAllowanceKeyPrefix), Value: grantBz}, + {Key: []byte(feegrant.FeeAllowanceKeyPrefix), Value: grantBz}, {Key: []byte{0x99}, Value: []byte{0x99}}, }, } diff --git a/x/feegrant/simulation/genesis.go b/x/feegrant/simulation/genesis.go index 5d4e837e3994..21e4e7079dea 100644 --- a/x/feegrant/simulation/genesis.go +++ b/x/feegrant/simulation/genesis.go @@ -8,15 +8,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) -// Simulation parameter constants -const feegrant = "feegrant" - // genFeeGrants returns a slice of randomly generated allowances. -func genFeeGrants(r *rand.Rand, accounts []simtypes.Account) []types.Grant { - allowances := make([]types.Grant, len(accounts)-1) +func genFeeGrants(r *rand.Rand, accounts []simtypes.Account) []feegrant.Grant { + allowances := make([]feegrant.Grant, len(accounts)-1) for i := 0; i < len(accounts)-1; i++ { granter := accounts[i].Address grantee := accounts[i+1].Address @@ -25,22 +22,22 @@ func genFeeGrants(r *rand.Rand, accounts []simtypes.Account) []types.Grant { return allowances } -func generateRandomAllowances(granter, grantee sdk.AccAddress, r *rand.Rand) types.Grant { - allowances := make([]types.Grant, 3) +func generateRandomAllowances(granter, grantee sdk.AccAddress, r *rand.Rand) feegrant.Grant { + allowances := make([]feegrant.Grant, 3) spendLimit := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))) periodSpendLimit := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))) - basic := types.BasicAllowance{ + basic := feegrant.BasicAllowance{ SpendLimit: spendLimit, } - basicAllowance, err := types.NewGrant(granter, grantee, &basic) + basicAllowance, err := feegrant.NewGrant(granter, grantee, &basic) if err != nil { panic(err) } allowances[0] = basicAllowance - periodicAllowance, err := types.NewGrant(granter, grantee, &types.PeriodicAllowance{ + periodicAllowance, err := feegrant.NewGrant(granter, grantee, &feegrant.PeriodicAllowance{ Basic: basic, PeriodSpendLimit: periodSpendLimit, Period: time.Hour, @@ -50,7 +47,7 @@ func generateRandomAllowances(granter, grantee sdk.AccAddress, r *rand.Rand) typ } allowances[1] = periodicAllowance - filteredAllowance, err := types.NewGrant(granter, grantee, &types.AllowedMsgAllowance{ + filteredAllowance, err := feegrant.NewGrant(granter, grantee, &feegrant.AllowedMsgAllowance{ Allowance: basicAllowance.GetAllowance(), AllowedMessages: []string{"/cosmos.gov.v1beta1.MsgSubmitProposal"}, }) @@ -64,19 +61,19 @@ func generateRandomAllowances(granter, grantee sdk.AccAddress, r *rand.Rand) typ // RandomizedGenState generates a random GenesisState for feegrant func RandomizedGenState(simState *module.SimulationState) { - var feegrants []types.Grant + var feegrants []feegrant.Grant simState.AppParams.GetOrGenerate( - simState.Cdc, feegrant, &feegrants, simState.Rand, + simState.Cdc, "feegrant", &feegrants, simState.Rand, func(r *rand.Rand) { feegrants = genFeeGrants(r, simState.Accounts) }, ) - feegrantGenesis := types.NewGenesisState(feegrants) + feegrantGenesis := feegrant.NewGenesisState(feegrants) bz, err := simState.Cdc.MarshalJSON(feegrantGenesis) if err != nil { panic(err) } - fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz) - simState.GenState[types.ModuleName] = bz + fmt.Printf("Selected randomly generated %s parameters:\n%s\n", feegrant.ModuleName, bz) + simState.GenState[feegrant.ModuleName] = bz } diff --git a/x/feegrant/simulation/genesis_test.go b/x/feegrant/simulation/genesis_test.go index 06298e57829f..5cd22fa6716a 100644 --- a/x/feegrant/simulation/genesis_test.go +++ b/x/feegrant/simulation/genesis_test.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/feegrant" "github.com/cosmos/cosmos-sdk/x/feegrant/simulation" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" ) func TestRandomizedGenState(t *testing.T) { @@ -33,8 +33,8 @@ func TestRandomizedGenState(t *testing.T) { } simulation.RandomizedGenState(&simState) - var feegrantGenesis types.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &feegrantGenesis) + var feegrantGenesis feegrant.GenesisState + simState.Cdc.MustUnmarshalJSON(simState.GenState[feegrant.ModuleName], &feegrantGenesis) require.Len(t, feegrantGenesis.Allowances, len(accounts)-1) } diff --git a/x/feegrant/simulation/operations.go b/x/feegrant/simulation/operations.go index 441f888c2271..f0174434c26d 100644 --- a/x/feegrant/simulation/operations.go +++ b/x/feegrant/simulation/operations.go @@ -11,70 +11,70 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/feegrant" "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" "github.com/cosmos/cosmos-sdk/x/simulation" ) // Simulation operation weights constants const ( - OpWeightMsgGrantFeeAllowance = "op_weight_msg_grant_fee_allowance" - OpWeightMsgRevokeFeeAllowance = "op_weight_msg_grant_revoke_allowance" + OpWeightMsgGrantAllowance = "op_weight_msg_grant_fee_allowance" + OpWeightMsgRevokeAllowance = "op_weight_msg_grant_revoke_allowance" ) var ( - TypeMsgGrantFeeAllowance = sdk.MsgTypeURL(&types.MsgGrantAllowance{}) - TypeMsgRevokeFeeAllowance = sdk.MsgTypeURL(&types.MsgRevokeAllowance{}) + TypeMsgGrantAllowance = sdk.MsgTypeURL(&feegrant.MsgGrantAllowance{}) + TypeMsgRevokeAllowance = sdk.MsgTypeURL(&feegrant.MsgRevokeAllowance{}) ) func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, - ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, + ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec, ) simulation.WeightedOperations { var ( - weightMsgGrantFeeAllowance int - weightMsgRevokeFeeAllowance int + weightMsgGrantAllowance int + weightMsgRevokeAllowance int ) - appParams.GetOrGenerate(cdc, OpWeightMsgGrantFeeAllowance, &weightMsgGrantFeeAllowance, nil, + appParams.GetOrGenerate(cdc, OpWeightMsgGrantAllowance, &weightMsgGrantAllowance, nil, func(_ *rand.Rand) { - weightMsgGrantFeeAllowance = simappparams.DefaultWeightGrantFeeAllowance + weightMsgGrantAllowance = simappparams.DefaultWeightGrantAllowance }, ) - appParams.GetOrGenerate(cdc, OpWeightMsgRevokeFeeAllowance, &weightMsgRevokeFeeAllowance, nil, + appParams.GetOrGenerate(cdc, OpWeightMsgRevokeAllowance, &weightMsgRevokeAllowance, nil, func(_ *rand.Rand) { - weightMsgRevokeFeeAllowance = simappparams.DefaultWeightRevokeFeeAllowance + weightMsgRevokeAllowance = simappparams.DefaultWeightRevokeAllowance }, ) return simulation.WeightedOperations{ simulation.NewWeightedOperation( - weightMsgGrantFeeAllowance, - SimulateMsgGrantFeeAllowance(ak, bk, k, protoCdc), + weightMsgGrantAllowance, + SimulateMsgGrantAllowance(ak, bk, k, protoCdc), ), simulation.NewWeightedOperation( - weightMsgRevokeFeeAllowance, - SimulateMsgRevokeFeeAllowance(ak, bk, k, protoCdc), + weightMsgRevokeAllowance, + SimulateMsgRevokeAllowance(ak, bk, k, protoCdc), ), } } -// SimulateMsgGrantFeeAllowance generates MsgGrantFeeAllowance with random values. -func SimulateMsgGrantFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { +// SimulateMsgGrantAllowance generates MsgGrantAllowance with random values. +func SimulateMsgGrantAllowance(ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { granter, _ := simtypes.RandomAcc(r, accs) grantee, _ := simtypes.RandomAcc(r, accs) if grantee.Address.String() == granter.Address.String() { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantFeeAllowance, "grantee and granter cannot be same"), nil, nil + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgGrantAllowance, "grantee and granter cannot be same"), nil, nil } if f, _ := k.GetAllowance(ctx, granter.Address, grantee.Address); f != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantFeeAllowance, "fee allowance exists"), nil, nil + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgGrantAllowance, "fee allowance exists"), nil, nil } account := ak.GetAccount(ctx, granter.Address) @@ -82,29 +82,29 @@ func SimulateMsgGrantFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper, k spendableCoins := bk.SpendableCoins(ctx, account.GetAddress()) fees, err := simtypes.RandomFees(r, ctx, spendableCoins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantFeeAllowance, err.Error()), nil, err + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgGrantAllowance, err.Error()), nil, err } spendableCoins = spendableCoins.Sub(fees) if spendableCoins.Empty() { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantFeeAllowance, "unable to grant empty coins as SpendLimit"), nil, nil + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgGrantAllowance, "unable to grant empty coins as SpendLimit"), nil, nil } oneYear := ctx.BlockTime().AddDate(1, 0, 0) - msg, err := types.NewMsgGrantAllowance(&types.BasicAllowance{ + msg, err := feegrant.NewMsgGrantAllowance(&feegrant.BasicAllowance{ SpendLimit: spendableCoins, Expiration: &oneYear, }, granter.Address, grantee.Address) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantFeeAllowance, err.Error()), nil, err + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgGrantAllowance, err.Error()), nil, err } txGen := simappparams.MakeTestEncodingConfig().TxConfig svcMsgClientConn := &msgservice.ServiceMsgClientConn{} - feegrantMsgClient := types.NewMsgClient(svcMsgClientConn) + feegrantMsgClient := feegrant.NewMsgClient(svcMsgClientConn) _, err = feegrantMsgClient.GrantAllowance(context.Background(), msg) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantFeeAllowance, err.Error()), nil, err + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgGrantAllowance, err.Error()), nil, err } tx, err := helpers.GenTx( txGen, @@ -118,20 +118,20 @@ func SimulateMsgGrantFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper, k ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantFeeAllowance, "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgGrantAllowance, "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(svcMsgClientConn.GetMsgs()[0]), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(feegrant.ModuleName, sdk.MsgTypeURL(svcMsgClientConn.GetMsgs()[0]), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(svcMsgClientConn.GetMsgs()[0], true, "", protoCdc), nil, err } } -// SimulateMsgRevokeFeeAllowance generates a MsgRevokeFeeAllowance with random values. -func SimulateMsgRevokeFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { +// SimulateMsgRevokeAllowance generates a MsgRevokeAllowance with random values. +func SimulateMsgRevokeAllowance(ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -139,7 +139,7 @@ func SimulateMsgRevokeFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper, hasGrant := false var granterAddr sdk.AccAddress var granteeAddr sdk.AccAddress - k.IterateAllFeeAllowances(ctx, func(grant types.Grant) bool { + k.IterateAllFeeAllowances(ctx, func(grant feegrant.Grant) bool { granter, err := sdk.AccAddressFromBech32(grant.Granter) if err != nil { @@ -156,29 +156,29 @@ func SimulateMsgRevokeFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper, }) if !hasGrant { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeFeeAllowance, "no grants"), nil, nil + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgRevokeAllowance, "no grants"), nil, nil } granter, ok := simtypes.FindAccount(accs, granterAddr) if !ok { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeFeeAllowance, "Account not found"), nil, nil + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgRevokeAllowance, "Account not found"), nil, nil } account := ak.GetAccount(ctx, granter.Address) spendableCoins := bk.SpendableCoins(ctx, account.GetAddress()) fees, err := simtypes.RandomFees(r, ctx, spendableCoins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeFeeAllowance, err.Error()), nil, err + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgRevokeAllowance, err.Error()), nil, err } - msg := types.NewMsgRevokeAllowance(granterAddr, granteeAddr) + msg := feegrant.NewMsgRevokeAllowance(granterAddr, granteeAddr) txGen := simappparams.MakeTestEncodingConfig().TxConfig svcMsgClientConn := &msgservice.ServiceMsgClientConn{} - feegrantMsgClient := types.NewMsgClient(svcMsgClientConn) + feegrantMsgClient := feegrant.NewMsgClient(svcMsgClientConn) _, err = feegrantMsgClient.RevokeAllowance(context.Background(), &msg) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantFeeAllowance, err.Error()), nil, err + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgGrantAllowance, err.Error()), nil, err } tx, err := helpers.GenTx( @@ -193,7 +193,7 @@ func SimulateMsgRevokeFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper, ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeFeeAllowance, err.Error()), nil, err + return simtypes.NoOpMsg(feegrant.ModuleName, TypeMsgRevokeAllowance, err.Error()), nil, err } _, _, err = app.Deliver(txGen.TxEncoder(), tx) diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index e721ed1bf16f..8ac80cc5b36c 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -15,8 +15,8 @@ import ( simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/feegrant" "github.com/cosmos/cosmos-sdk/x/feegrant/simulation" - "github.com/cosmos/cosmos-sdk/x/feegrant/types" ) type SimTestSuite struct { @@ -78,14 +78,14 @@ func (suite *SimTestSuite) TestWeightedOperations() { opMsgName string }{ { - simappparams.DefaultWeightGrantFeeAllowance, - types.ModuleName, - simulation.TypeMsgGrantFeeAllowance, + simappparams.DefaultWeightGrantAllowance, + feegrant.ModuleName, + simulation.TypeMsgGrantAllowance, }, { - simappparams.DefaultWeightRevokeFeeAllowance, - types.ModuleName, - simulation.TypeMsgRevokeFeeAllowance, + simappparams.DefaultWeightRevokeAllowance, + feegrant.ModuleName, + simulation.TypeMsgRevokeAllowance, }, } @@ -100,7 +100,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { } } -func (suite *SimTestSuite) TestSimulateMsgGrantFeeAllowance() { +func (suite *SimTestSuite) TestSimulateMsgGrantAllowance() { app, ctx := suite.app, suite.ctx require := suite.Require() @@ -112,11 +112,11 @@ func (suite *SimTestSuite) TestSimulateMsgGrantFeeAllowance() { app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash}}) // execute operation - op := simulation.SimulateMsgGrantFeeAllowance(app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, suite.protoCdc) + op := simulation.SimulateMsgGrantAllowance(app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, suite.protoCdc) operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(err) - var msg types.MsgGrantAllowance + var msg feegrant.MsgGrantAllowance suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) @@ -125,7 +125,7 @@ func (suite *SimTestSuite) TestSimulateMsgGrantFeeAllowance() { require.Len(futureOperations, 0) } -func (suite *SimTestSuite) TestSimulateMsgRevokeFeeAllowance() { +func (suite *SimTestSuite) TestSimulateMsgRevokeAllowance() { app, ctx := suite.app, suite.ctx require := suite.Require() @@ -146,7 +146,7 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeFeeAllowance() { ctx, granter.Address, grantee.Address, - &types.BasicAllowance{ + &feegrant.BasicAllowance{ SpendLimit: feeCoins, Expiration: &oneYear, }, @@ -154,11 +154,11 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeFeeAllowance() { require.NoError(err) // execute operation - op := simulation.SimulateMsgRevokeFeeAllowance(app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, suite.protoCdc) + op := simulation.SimulateMsgRevokeAllowance(app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, suite.protoCdc) operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(err) - var msg types.MsgRevokeAllowance + var msg feegrant.MsgRevokeAllowance suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) diff --git a/x/feegrant/spec/01_concepts.md b/x/feegrant/spec/01_concepts.md index a209e8d67407..835128974350 100644 --- a/x/feegrant/spec/01_concepts.md +++ b/x/feegrant/spec/01_concepts.md @@ -3,27 +3,28 @@ order: 1 --> # Concepts -## FeeAllowanceGrant -`FeeAllowanceGrant` is stored in the KVStore to record a grant with full context. Every grant will contain `granter`, `grantee` and what kind of `allowance` is granted. `granter` is an account address who is giving permission to `grantee` (the beneficiary account address) to pay for some or all of `grantee`'s transaction fees. `allowance` defines what kind of fee allowance (`BasicFeeAllowance` or `PeriodicFeeAllowance`, see below) is granted to `grantee`. `allowance` accepts an interface which implements `FeeAllowanceI`, encoded as `Any` type. There can be only one existing fee grant allowed for a `grantee` and `granter`, self grants are not allowed. +## Grant -+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/proto/cosmos/feegrant/v1beta1/feegrant.proto#L75-L81 +`Grant` is stored in the KVStore to record a grant with full context. Every grant will contain `granter`, `grantee` and what kind of `allowance` is granted. `granter` is an account address who is giving permission to `grantee` (the beneficiary account address) to pay for some or all of `grantee`'s transaction fees. `allowance` defines what kind of fee allowance (`BasicAllowance` or `PeriodicAllowance`, see below) is granted to `grantee`. `allowance` accepts an interface which implements `FeeAllowanceI`, encoded as `Any` type. There can be only one existing fee grant allowed for a `grantee` and `granter`, self grants are not allowed. + ++++ https://github.com/cosmos/cosmos-sdk/blob/691032b8be0f7539ec99f8882caecefc51f33d1f/proto/cosmos/feegrant/v1beta1/feegrant.proto#L75-L81 `FeeAllowanceI` looks like: -+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/x/feegrant/types/fees.go#L9-L32 ++++ https://github.com/cosmos/cosmos-sdk/blob/691032b8be0f7539ec99f8882caecefc51f33d1f/x/feegrant/fees.go#L9-L32 ## Fee Allowance types There are two types of fee allowances present at the moment: -- `BasicFeeAllowance` -- `PeriodicFeeAllowance` +- `BasicAllowance` +- `PeriodicAllowance` -## BasicFeeAllowance +## BasicAllowance -`BasicFeeAllowance` is permission for `grantee` to use fee from a `granter`'s account. If any of the `spend_limit` or `expiration` reaches its limit, the grant will be removed from the state. +`BasicAllowance` is permission for `grantee` to use fee from a `granter`'s account. If any of the `spend_limit` or `expiration` reaches its limit, the grant will be removed from the state. -+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/proto/cosmos/feegrant/v1beta1/feegrant.proto#L13-L26 ++++ https://github.com/cosmos/cosmos-sdk/blob/691032b8be0f7539ec99f8882caecefc51f33d1f/proto/cosmos/feegrant/v1beta1/feegrant.proto#L13-L26 - `spend_limit` is the limit of coins that are allowed to be used from the `granter` account. If it is empty, it assumes there's no spend limit, `grantee` can use any number of available tokens from `granter` account address before the expiration. @@ -31,15 +32,15 @@ There are two types of fee allowances present at the moment: - When a grant is created with empty values for `spend_limit` and `expiration`, it is still a valid grant. It won't restrict the `grantee` to use any number of tokens from `granter` and it won't have any expiration. The only way to restrict the `grantee` is by revoking the grant. -## PeriodicFeeAllowance +## PeriodicAllowance -`PeriodicFeeAllowance` is a repeating fee allowance for the mentioned period, we can mention when the grant can expire as well as when a period can reset. We can also define the maximum number of coins that can be used in a mentioned period of time. +`PeriodicAllowance` is a repeating fee allowance for the mentioned period, we can mention when the grant can expire as well as when a period can reset. We can also define the maximum number of coins that can be used in a mentioned period of time. -+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/proto/cosmos/feegrant/v1beta1/feegrant.proto#L28-L73 ++++ https://github.com/cosmos/cosmos-sdk/blob/691032b8be0f7539ec99f8882caecefc51f33d1f/proto/cosmos/feegrant/v1beta1/feegrant.proto#L28-L73 -- `basic` is the instance of `BasicFeeAllowance` which is optional for periodic fee allowance. If empty, the grant will have no `expiration` and no `spend_limit`. +- `basic` is the instance of `BasicAllowance` which is optional for periodic fee allowance. If empty, the grant will have no `expiration` and no `spend_limit`. -- `period` is the specific period of time or blocks, after each period passes, `period_spend_limit` will be reset. +- `period` is the specific period of time, after each period passes, `period_spend_limit` will be reset. - `period_spend_limit` specifies the maximum number of coins that can be spent in the period. diff --git a/x/feegrant/spec/02_state.md b/x/feegrant/spec/02_state.md index 463ea70d0685..5b12cd2d0cee 100644 --- a/x/feegrant/spec/02_state.md +++ b/x/feegrant/spec/02_state.md @@ -8,8 +8,8 @@ order: 2 Fee Allowances are identified by combining `Grantee` (the account address of fee allowance grantee) with the `Granter` (the account address of fee allowance granter). -Fee allowances are stored in the state as follows: +Fee allowance grants are stored in the state as follows: -- FeeAllowance: `0x00 | grantee_addr_len (1 byte) | grantee_addr_bytes | granter_addr_len (1 byte) | granter_addr_bytes -> ProtocolBuffer(FeeAllowance)` +- Grant: `0x00 | grantee_addr_len (1 byte) | grantee_addr_bytes | granter_addr_len (1 byte) | granter_addr_bytes -> ProtocolBuffer(Grant)` -+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/x/feegrant/types/feegrant.pb.go#L358-L363 ++++ https://github.com/cosmos/cosmos-sdk/blob/691032b8be0f7539ec99f8882caecefc51f33d1f/x/feegrant/feegrant.pb.go#L221-L229 diff --git a/x/feegrant/spec/03_messages.md b/x/feegrant/spec/03_messages.md index 3ca65e25cd3f..602dd2b7125a 100644 --- a/x/feegrant/spec/03_messages.md +++ b/x/feegrant/spec/03_messages.md @@ -4,14 +4,14 @@ order: 3 # Messages -## Msg/GrantFeeAllowance +## Msg/GrantAllowance -A fee allowance grant will be created with the `MsgGrantFeeAllowance` message. +A fee allowance grant will be created with the `MsgGrantAllowance` message. -+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/proto/cosmos/feegrant/v1beta1/tx.proto#L22-L28 ++++ https://github.com/cosmos/cosmos-sdk/blob/691032b8be0f7539ec99f8882caecefc51f33d1f/proto/cosmos/feegrant/v1beta1/tx.proto#L22-L33 -## Msg/RevokeFeeAllowance +## Msg/RevokeAllowance -An allowed grant fee allowance can be removed with the `MsgRevokeFeeAllowance` message. +An allowed grant fee allowance can be removed with the `MsgRevokeAllowance` message. -+++ https://github.com/cosmos/cosmos-sdk/blob/d97e7907f176777ed8a464006d360bb3e1a223e4/proto/cosmos/feegrant/v1beta1/tx.proto#L33-L37 ++++ https://github.com/cosmos/cosmos-sdk/blob/691032b8be0f7539ec99f8882caecefc51f33d1f/proto/cosmos/feegrant/v1beta1/tx.proto#L38-L45 diff --git a/x/feegrant/spec/04_events.md b/x/feegrant/spec/04_events.md index 39a0c7affc91..55012f8c689d 100644 --- a/x/feegrant/spec/04_events.md +++ b/x/feegrant/spec/04_events.md @@ -8,7 +8,7 @@ The feegrant module emits the following events: # Msg Server -### MsgGrantFeeAllowance +### MsgGrantAllowance | Type | Attribute Key | Attribute Value | | -------- | ------------- | ------------------ | @@ -16,7 +16,7 @@ The feegrant module emits the following events: | message | granter | {granterAddress} | | message | grantee | {granteeAddress} | -### MsgRevokeFeeAllowance +### MsgRevokeAllowance | Type | Attribute Key | Attribute Value | | -------- | ------------- | ------------------ | diff --git a/x/feegrant/spec/README.md b/x/feegrant/spec/README.md index 5410731b1d22..62b5bf3b78dc 100644 --- a/x/feegrant/spec/README.md +++ b/x/feegrant/spec/README.md @@ -14,20 +14,20 @@ This module allows accounts to grant fee allowances and to use fees from their a ## Contents 1. **[Concepts](01_concepts.md)** - - [FeeAllowanceGrant](01_concepts.md#feeallowancegrant) + - [Grant](01_concepts.md#grant) - [Fee Allowance types](01_concepts.md#fee-allowance-types) - - [BasicFeeAllowance](01_concepts.md#basicfeeallowance) - - [PeriodicFeeAllowance](01_concepts.md#periodicfeeallowance) + - [BasicAllowance](01_concepts.md#basicallowance) + - [PeriodicAllowance](01_concepts.md#periodicallowance) - [FeeAccount flag](01_concepts.md#feeaccount-flag) - [Granted Fee Deductions](01_concepts.md#granted-fee-deductions) - [Gas](01_concepts.md#gas) 2. **[State](02_state.md)** - [FeeAllowance](02_state.md#feeallowance) 3. **[Messages](03_messages.md)** - - [Msg/GrantFeeAllowance](03_messages.md#msggrantfeeallowance) - - [Msg/RevokeFeeAllowance](03_messages.md#msgrevokefeeallowance) + - [Msg/GrantAllowance](03_messages.md#msggrantallowance) + - [Msg/RevokeAllowance](03_messages.md#msgrevokeallowance) 4. **[Events](04_events.md)** - - [MsgGrantFeeAllowance](04_events.md#msggrantfeeallowance) - - [MsgrevokeFeeAllowance](04_events.md#msgrevokefeeallowance) + - [MsgGrantAllowance](04_events.md#msggrantallowance) + - [MsgRevokeAllowance](04_events.md#msgrevokeallowance) - [Exec fee allowance](04_events.md#exec-fee-allowance) diff --git a/x/feegrant/types/tx.pb.go b/x/feegrant/tx.pb.go similarity index 92% rename from x/feegrant/types/tx.pb.go rename to x/feegrant/tx.pb.go index 703bd0d586aa..2a40a7ad49b4 100644 --- a/x/feegrant/types/tx.pb.go +++ b/x/feegrant/tx.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cosmos/feegrant/v1beta1/tx.proto -package types +package feegrant import ( context "context" @@ -234,29 +234,29 @@ func init() { func init() { proto.RegisterFile("cosmos/feegrant/v1beta1/tx.proto", fileDescriptor_dd44ad7946dad783) } var fileDescriptor_dd44ad7946dad783 = []byte{ - // 344 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x92, 0xc1, 0x4e, 0xc2, 0x40, - 0x10, 0x86, 0x59, 0x49, 0x34, 0xac, 0x51, 0x43, 0x43, 0x62, 0xa9, 0x66, 0x43, 0x7a, 0x22, 0x1a, - 0x76, 0x03, 0x3c, 0x01, 0x24, 0x8a, 0x1e, 0xb8, 0xf4, 0xe8, 0xc5, 0xb4, 0x38, 0xac, 0x06, 0xe8, - 0x34, 0xec, 0x82, 0xf0, 0x12, 0xc6, 0x87, 0xf1, 0x21, 0x8c, 0x27, 0x8e, 0x1e, 0x0d, 0x5c, 0x7d, - 0x08, 0x43, 0xdb, 0x15, 0x03, 0xd1, 0x68, 0x3c, 0xb5, 0x93, 0xf9, 0xe6, 0xff, 0xff, 0x76, 0x86, - 0x96, 0x3a, 0xa8, 0x06, 0xa8, 0x44, 0x17, 0x40, 0x0e, 0xfd, 0x50, 0x8b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0xec, 0xd4, 0xff, 0x00, 0x1b, 0xd3, 0x66, 0xeb, 0x79, 0xce, 0xc8, 0x6c, 0xce, 0xc8, - 0xdb, 0x9c, 0x91, 0xc7, 0x05, 0xcb, 0xcc, 0x16, 0x2c, 0xf3, 0xba, 0x60, 0x99, 0xab, 0x8a, 0xbc, - 0xd3, 0xb7, 0xa3, 0x80, 0x77, 0x70, 0x90, 0xde, 0x4d, 0xfa, 0xa8, 0xa8, 0x9b, 0x9e, 0x98, 0xac, - 0xae, 0x57, 0x4f, 0x23, 0x50, 0xc1, 0x76, 0xbc, 0xe8, 0xfa, 0x47, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x8d, 0x25, 0xe0, 0x0e, 0xdd, 0x02, 0x00, 0x00, + // 339 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x4b, 0x4d, 0x4d, 0x2f, 0x4a, 0xcc, 0x2b, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, + 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x87, 0xa8, + 0xd0, 0x83, 0xa9, 0xd0, 0x83, 0xaa, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd1, 0x07, + 0xb1, 0x20, 0xca, 0xa5, 0x24, 0xd3, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0xc1, 0xbc, 0xa4, 0xd2, + 0x34, 0xfd, 0xc4, 0xbc, 0x4a, 0x98, 0x14, 0xc4, 0xa4, 0x78, 0x88, 0x1e, 0xa8, 0xb1, 0x60, 0x8e, + 0x52, 0x1f, 0x23, 0x97, 0xa0, 0x6f, 0x71, 0xba, 0x3b, 0xc8, 0x02, 0xc7, 0x9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 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xea, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, + 0xc9, 0xf9, 0xb9, 0xd0, 0x74, 0x03, 0xa5, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0xe0, 0xa9, 0x37, + 0x89, 0x0d, 0x1c, 0xc5, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x60, 0x47, 0xc8, 0xf2, 0xd7, + 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/feegrant/types/genesis.go b/x/feegrant/types/genesis.go deleted file mode 100644 index 78472b90a92b..000000000000 --- a/x/feegrant/types/genesis.go +++ /dev/null @@ -1,44 +0,0 @@ -package types - -import "github.com/cosmos/cosmos-sdk/codec/types" - -var _ types.UnpackInterfacesMessage = GenesisState{} - -// NewGenesisState creates new GenesisState object -func NewGenesisState(entries []Grant) *GenesisState { - return &GenesisState{ - Allowances: entries, - } -} - -// ValidateGenesis ensures all grants in the genesis state are valid -func ValidateGenesis(data GenesisState) error { - for _, f := range data.Allowances { - grant, err := f.GetGrant() - if err != nil { - return err - } - err = grant.ValidateBasic() - if err != nil { - return err - } - } - return nil -} - -// DefaultGenesisState returns default state for feegrant module. -func DefaultGenesisState() *GenesisState { - return &GenesisState{} -} - -// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (data GenesisState) UnpackInterfaces(unpacker types.AnyUnpacker) error { - for _, f := range data.Allowances { - err := f.UnpackInterfaces(unpacker) - if err != nil { - return err - } - } - - return nil -}