Move x/feegrant/types to x/feegrant (#9273)
* Move x/feegrant/types to x/feegrant * Update spec * Use feegrantmodule
This commit is contained in:
parent
59810f3286
commit
3582ccef7c
|
@ -8,7 +8,7 @@ import "cosmos/base/v1beta1/coin.proto";
|
||||||
import "google/protobuf/timestamp.proto";
|
import "google/protobuf/timestamp.proto";
|
||||||
import "google/protobuf/duration.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
|
// BasicAllowance implements Allowance with a one-time grant of tokens
|
||||||
// that optionally expires. The grantee can use up to SpendLimit to cover fees.
|
// that optionally expires. The grantee can use up to SpendLimit to cover fees.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package cosmos.feegrant.v1beta1;
|
||||||
import "gogoproto/gogo.proto";
|
import "gogoproto/gogo.proto";
|
||||||
import "cosmos/feegrant/v1beta1/feegrant.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
|
// GenesisState contains a set of fee allowances, persisted from the store
|
||||||
message GenesisState {
|
message GenesisState {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import "cosmos/feegrant/v1beta1/feegrant.proto";
|
||||||
import "cosmos/base/query/v1beta1/pagination.proto";
|
import "cosmos/base/query/v1beta1/pagination.proto";
|
||||||
import "google/api/annotations.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.
|
// Query defines the gRPC querier service.
|
||||||
service Query {
|
service Query {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import "gogoproto/gogo.proto";
|
||||||
import "google/protobuf/any.proto";
|
import "google/protobuf/any.proto";
|
||||||
import "cosmos_proto/cosmos.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.
|
// Msg defines the feegrant msg service.
|
||||||
service Msg {
|
service Msg {
|
||||||
|
|
|
@ -58,9 +58,9 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/evidence"
|
"github.com/cosmos/cosmos-sdk/x/evidence"
|
||||||
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
|
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
|
||||||
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
|
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"
|
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"
|
"github.com/cosmos/cosmos-sdk/x/genutil"
|
||||||
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
|
@ -112,7 +112,7 @@ var (
|
||||||
params.AppModuleBasic{},
|
params.AppModuleBasic{},
|
||||||
crisis.AppModuleBasic{},
|
crisis.AppModuleBasic{},
|
||||||
slashing.AppModuleBasic{},
|
slashing.AppModuleBasic{},
|
||||||
feegrant.AppModuleBasic{},
|
feegrantmodule.AppModuleBasic{},
|
||||||
upgrade.AppModuleBasic{},
|
upgrade.AppModuleBasic{},
|
||||||
evidence.AppModuleBasic{},
|
evidence.AppModuleBasic{},
|
||||||
authz_m.AppModuleBasic{},
|
authz_m.AppModuleBasic{},
|
||||||
|
@ -205,7 +205,7 @@ func NewSimApp(
|
||||||
keys := sdk.NewKVStoreKeys(
|
keys := sdk.NewKVStoreKeys(
|
||||||
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
|
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
|
||||||
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.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,
|
evidencetypes.StoreKey, capabilitytypes.StoreKey,
|
||||||
authzkeeper.StoreKey,
|
authzkeeper.StoreKey,
|
||||||
)
|
)
|
||||||
|
@ -255,7 +255,7 @@ func NewSimApp(
|
||||||
app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
|
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)
|
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)
|
||||||
|
|
||||||
// register the staking hooks
|
// register the staking hooks
|
||||||
|
@ -308,7 +308,7 @@ func NewSimApp(
|
||||||
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
|
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
|
||||||
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
|
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
|
||||||
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
|
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),
|
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
|
||||||
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
|
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
|
||||||
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
|
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,
|
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
|
||||||
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
|
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
|
||||||
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
|
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
|
||||||
feegranttypes.ModuleName,
|
feegrant.ModuleName,
|
||||||
)
|
)
|
||||||
|
|
||||||
app.mm.RegisterInvariants(&app.CrisisKeeper)
|
app.mm.RegisterInvariants(&app.CrisisKeeper)
|
||||||
|
@ -358,7 +358,7 @@ func NewSimApp(
|
||||||
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
|
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
|
||||||
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
|
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
|
||||||
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
|
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),
|
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
|
||||||
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
|
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
|
||||||
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
|
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||||
"github.com/cosmos/cosmos-sdk/x/distribution"
|
"github.com/cosmos/cosmos-sdk/x/distribution"
|
||||||
"github.com/cosmos/cosmos-sdk/x/evidence"
|
"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/genutil"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
"github.com/cosmos/cosmos-sdk/x/mint"
|
"github.com/cosmos/cosmos-sdk/x/mint"
|
||||||
|
@ -177,7 +177,7 @@ func TestRunMigrations(t *testing.T) {
|
||||||
"params": params.AppModule{}.ConsensusVersion(),
|
"params": params.AppModule{}.ConsensusVersion(),
|
||||||
"upgrade": upgrade.AppModule{}.ConsensusVersion(),
|
"upgrade": upgrade.AppModule{}.ConsensusVersion(),
|
||||||
"vesting": vesting.AppModule{}.ConsensusVersion(),
|
"vesting": vesting.AppModule{}.ConsensusVersion(),
|
||||||
"feegrant": feegrant.AppModule{}.ConsensusVersion(),
|
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
|
||||||
"evidence": evidence.AppModule{}.ConsensusVersion(),
|
"evidence": evidence.AppModule{}.ConsensusVersion(),
|
||||||
"crisis": crisis.AppModule{}.ConsensusVersion(),
|
"crisis": crisis.AppModule{}.ConsensusVersion(),
|
||||||
"genutil": genutil.AppModule{}.ConsensusVersion(),
|
"genutil": genutil.AppModule{}.ConsensusVersion(),
|
||||||
|
@ -228,7 +228,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
|
||||||
"params": params.AppModule{}.ConsensusVersion(),
|
"params": params.AppModule{}.ConsensusVersion(),
|
||||||
"upgrade": upgrade.AppModule{}.ConsensusVersion(),
|
"upgrade": upgrade.AppModule{}.ConsensusVersion(),
|
||||||
"vesting": vesting.AppModule{}.ConsensusVersion(),
|
"vesting": vesting.AppModule{}.ConsensusVersion(),
|
||||||
"feegrant": feegrant.AppModule{}.ConsensusVersion(),
|
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
|
||||||
"evidence": evidence.AppModule{}.ConsensusVersion(),
|
"evidence": evidence.AppModule{}.ConsensusVersion(),
|
||||||
"crisis": crisis.AppModule{}.ConsensusVersion(),
|
"crisis": crisis.AppModule{}.ConsensusVersion(),
|
||||||
"genutil": genutil.AppModule{}.ConsensusVersion(),
|
"genutil": genutil.AppModule{}.ConsensusVersion(),
|
||||||
|
|
|
@ -23,6 +23,6 @@ const (
|
||||||
DefaultWeightParamChangeProposal int = 5
|
DefaultWeightParamChangeProposal int = 5
|
||||||
|
|
||||||
// feegrant
|
// feegrant
|
||||||
DefaultWeightGrantFeeAllowance int = 100
|
DefaultWeightGrantAllowance int = 100
|
||||||
DefaultWeightRevokeFeeAllowance int = 100
|
DefaultWeightRevokeAllowance int = 100
|
||||||
)
|
)
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
authsign "github.com/cosmos/cosmos-sdk/x/auth/signing"
|
authsign "github.com/cosmos/cosmos-sdk/x/auth/signing"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/tx"
|
"github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
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() {
|
func (suite *AnteTestSuite) TestDeductFeesNoDelegation() {
|
||||||
|
@ -54,13 +54,13 @@ func (suite *AnteTestSuite) TestDeductFeesNoDelegation() {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// grant fee allowance from `addr2` to `addr3` (plenty to pay)
|
// 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)),
|
SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 500)),
|
||||||
})
|
})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// grant low fee allowance (20atom), to check the tx requesting more than allowed.
|
// 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)),
|
SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 20)),
|
||||||
})
|
})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
@ -16,7 +16,7 @@ var _ FeeAllowanceI = (*BasicAllowance)(nil)
|
||||||
// and will be saved again after an acceptance.
|
// and will be saved again after an acceptance.
|
||||||
//
|
//
|
||||||
// If remove is true (regardless of the error), the FeeAllowance will be deleted from storage
|
// 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) {
|
func (a *BasicAllowance) Accept(ctx sdk.Context, fee sdk.Coins, _ []sdk.Msg) (bool, error) {
|
||||||
if a.Expiration != nil && a.Expiration.Before(ctx.BlockTime()) {
|
if a.Expiration != nil && a.Expiration.Before(ctx.BlockTime()) {
|
||||||
return true, sdkerrors.Wrap(ErrFeeLimitExpired, "basic allowance")
|
return true, sdkerrors.Wrap(ErrFeeLimitExpired, "basic allowance")
|
|
@ -1,4 +1,4 @@
|
||||||
package types_test
|
package feegrant_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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) {
|
func TestBasicFeeValidAllow(t *testing.T) {
|
||||||
|
@ -18,7 +18,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||||
|
|
||||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||||
badTime := ctx.BlockTime().AddDate(0, 0, -1)
|
badTime := ctx.BlockTime().AddDate(0, 0, -1)
|
||||||
allowace := &types.BasicAllowance{
|
allowace := &feegrant.BasicAllowance{
|
||||||
Expiration: &badTime,
|
Expiration: &badTime,
|
||||||
}
|
}
|
||||||
require.Error(t, allowace.ValidateBasic())
|
require.Error(t, allowace.ValidateBasic())
|
||||||
|
@ -35,7 +35,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||||
oneHour := now.Add(1 * time.Hour)
|
oneHour := now.Add(1 * time.Hour)
|
||||||
|
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
allowance *types.BasicAllowance
|
allowance *feegrant.BasicAllowance
|
||||||
// all other checks are ignored if valid=false
|
// all other checks are ignored if valid=false
|
||||||
fee sdk.Coins
|
fee sdk.Coins
|
||||||
blockTime time.Time
|
blockTime time.Time
|
||||||
|
@ -45,11 +45,11 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||||
remains sdk.Coins
|
remains sdk.Coins
|
||||||
}{
|
}{
|
||||||
"empty": {
|
"empty": {
|
||||||
allowance: &types.BasicAllowance{},
|
allowance: &feegrant.BasicAllowance{},
|
||||||
accept: true,
|
accept: true,
|
||||||
},
|
},
|
||||||
"small fee without expire": {
|
"small fee without expire": {
|
||||||
allowance: &types.BasicAllowance{
|
allowance: &feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
},
|
},
|
||||||
fee: smallAtom,
|
fee: smallAtom,
|
||||||
|
@ -58,7 +58,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||||
remains: leftAtom,
|
remains: leftAtom,
|
||||||
},
|
},
|
||||||
"all fee without expire": {
|
"all fee without expire": {
|
||||||
allowance: &types.BasicAllowance{
|
allowance: &feegrant.BasicAllowance{
|
||||||
SpendLimit: smallAtom,
|
SpendLimit: smallAtom,
|
||||||
},
|
},
|
||||||
fee: smallAtom,
|
fee: smallAtom,
|
||||||
|
@ -66,14 +66,14 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||||
remove: true,
|
remove: true,
|
||||||
},
|
},
|
||||||
"wrong fee": {
|
"wrong fee": {
|
||||||
allowance: &types.BasicAllowance{
|
allowance: &feegrant.BasicAllowance{
|
||||||
SpendLimit: smallAtom,
|
SpendLimit: smallAtom,
|
||||||
},
|
},
|
||||||
fee: eth,
|
fee: eth,
|
||||||
accept: false,
|
accept: false,
|
||||||
},
|
},
|
||||||
"non-expired": {
|
"non-expired": {
|
||||||
allowance: &types.BasicAllowance{
|
allowance: &feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &oneHour,
|
Expiration: &oneHour,
|
||||||
},
|
},
|
||||||
|
@ -85,7 +85,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||||
remains: leftAtom,
|
remains: leftAtom,
|
||||||
},
|
},
|
||||||
"expired": {
|
"expired": {
|
||||||
allowance: &types.BasicAllowance{
|
allowance: &feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &now,
|
Expiration: &now,
|
||||||
},
|
},
|
||||||
|
@ -96,7 +96,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||||
remove: true,
|
remove: true,
|
||||||
},
|
},
|
||||||
"fee more than allowed": {
|
"fee more than allowed": {
|
||||||
allowance: &types.BasicAllowance{
|
allowance: &feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &oneHour,
|
Expiration: &oneHour,
|
||||||
},
|
},
|
||||||
|
@ -106,7 +106,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||||
accept: false,
|
accept: false,
|
||||||
},
|
},
|
||||||
"with out spend limit": {
|
"with out spend limit": {
|
||||||
allowance: &types.BasicAllowance{
|
allowance: &feegrant.BasicAllowance{
|
||||||
Expiration: &oneHour,
|
Expiration: &oneHour,
|
||||||
},
|
},
|
||||||
valid: true,
|
valid: true,
|
||||||
|
@ -115,7 +115,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||||
accept: true,
|
accept: true,
|
||||||
},
|
},
|
||||||
"expired no spend limit": {
|
"expired no spend limit": {
|
||||||
allowance: &types.BasicAllowance{
|
allowance: &feegrant.BasicAllowance{
|
||||||
Expiration: &now,
|
Expiration: &now,
|
||||||
},
|
},
|
||||||
valid: true,
|
valid: true,
|
|
@ -10,13 +10,13 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/version"
|
"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
|
// GetQueryCmd returns the cli query commands for this module
|
||||||
func GetQueryCmd() *cobra.Command {
|
func GetQueryCmd() *cobra.Command {
|
||||||
feegrantQueryCmd := &cobra.Command{
|
feegrantQueryCmd := &cobra.Command{
|
||||||
Use: types.ModuleName,
|
Use: feegrant.ModuleName,
|
||||||
Short: "Querying commands for the feegrant module",
|
Short: "Querying commands for the feegrant module",
|
||||||
DisableFlagParsing: true,
|
DisableFlagParsing: true,
|
||||||
SuggestionsMinimumDistance: 2,
|
SuggestionsMinimumDistance: 2,
|
||||||
|
@ -47,7 +47,7 @@ $ %s query feegrant grant [granter] [grantee]
|
||||||
),
|
),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||||
queryClient := types.NewQueryClient(clientCtx)
|
queryClient := feegrant.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
granterAddr, err := sdk.AccAddressFromBech32(args[0])
|
granterAddr, err := sdk.AccAddressFromBech32(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -61,7 +61,7 @@ $ %s query feegrant grant [granter] [grantee]
|
||||||
|
|
||||||
res, err := queryClient.Allowance(
|
res, err := queryClient.Allowance(
|
||||||
cmd.Context(),
|
cmd.Context(),
|
||||||
&types.QueryAllowanceRequest{
|
&feegrant.QueryAllowanceRequest{
|
||||||
Granter: granterAddr.String(),
|
Granter: granterAddr.String(),
|
||||||
Grantee: granteeAddr.String(),
|
Grantee: granteeAddr.String(),
|
||||||
},
|
},
|
||||||
|
@ -95,7 +95,7 @@ $ %s query feegrant grants [grantee]
|
||||||
),
|
),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||||
queryClient := types.NewQueryClient(clientCtx)
|
queryClient := feegrant.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
granteeAddr, err := sdk.AccAddressFromBech32(args[0])
|
granteeAddr, err := sdk.AccAddressFromBech32(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -109,7 +109,7 @@ $ %s query feegrant grants [grantee]
|
||||||
|
|
||||||
res, err := queryClient.Allowances(
|
res, err := queryClient.Allowances(
|
||||||
cmd.Context(),
|
cmd.Context(),
|
||||||
&types.QueryAllowancesRequest{
|
&feegrant.QueryAllowancesRequest{
|
||||||
Grantee: granteeAddr.String(),
|
Grantee: granteeAddr.String(),
|
||||||
Pagination: pageReq,
|
Pagination: pageReq,
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||||
"github.com/cosmos/cosmos-sdk/version"
|
"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
|
// flag for feegrant module
|
||||||
|
@ -28,7 +28,7 @@ const (
|
||||||
// GetTxCmd returns the transaction commands for this module
|
// GetTxCmd returns the transaction commands for this module
|
||||||
func GetTxCmd() *cobra.Command {
|
func GetTxCmd() *cobra.Command {
|
||||||
feegrantTxCmd := &cobra.Command{
|
feegrantTxCmd := &cobra.Command{
|
||||||
Use: types.ModuleName,
|
Use: feegrant.ModuleName,
|
||||||
Short: "Feegrant transactions subcommands",
|
Short: "Feegrant transactions subcommands",
|
||||||
Long: "Grant and revoke fee allowance for a grantee by a granter",
|
Long: "Grant and revoke fee allowance for a grantee by a granter",
|
||||||
DisableFlagParsing: true,
|
DisableFlagParsing: true,
|
||||||
|
@ -44,7 +44,7 @@ func GetTxCmd() *cobra.Command {
|
||||||
return feegrantTxCmd
|
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 {
|
func NewCmdFeeGrant() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "grant [granter] [grantee]",
|
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 --period 3600 --period-limit 10stake --expiration 36000 or
|
||||||
%s tx %s grant cosmos1skjw... cosmos1skjw... --spend-limit 100stake --expiration 2022-01-30T15:04:05Z
|
%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"
|
--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),
|
Args: cobra.ExactArgs(2),
|
||||||
|
@ -97,7 +97,7 @@ Examples:
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
basic := types.BasicAllowance{
|
basic := feegrant.BasicAllowance{
|
||||||
SpendLimit: limit,
|
SpendLimit: limit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ Examples:
|
||||||
basic.Expiration = &expiresAtTime
|
basic.Expiration = &expiresAtTime
|
||||||
}
|
}
|
||||||
|
|
||||||
var grant types.FeeAllowanceI
|
var grant feegrant.FeeAllowanceI
|
||||||
grant = &basic
|
grant = &basic
|
||||||
|
|
||||||
periodClock, err := cmd.Flags().GetInt64(FlagPeriod)
|
periodClock, err := cmd.Flags().GetInt64(FlagPeriod)
|
||||||
|
@ -136,7 +136,7 @@ Examples:
|
||||||
return fmt.Errorf("period(%d) cannot reset after expiration(%v)", periodClock, exp)
|
return fmt.Errorf("period(%d) cannot reset after expiration(%v)", periodClock, exp)
|
||||||
}
|
}
|
||||||
|
|
||||||
periodic := types.PeriodicAllowance{
|
periodic := feegrant.PeriodicAllowance{
|
||||||
Basic: basic,
|
Basic: basic,
|
||||||
Period: getPeriod(periodClock),
|
Period: getPeriod(periodClock),
|
||||||
PeriodReset: getPeriodReset(periodClock),
|
PeriodReset: getPeriodReset(periodClock),
|
||||||
|
@ -157,19 +157,19 @@ Examples:
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(allowedMsgs) > 0 {
|
if len(allowedMsgs) > 0 {
|
||||||
grant, err = types.NewAllowedMsgAllowance(grant, allowedMsgs)
|
grant, err = feegrant.NewAllowedMsgAllowance(grant, allowedMsgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msg, err := types.NewMsgGrantAllowance(grant, granter, grantee)
|
msg, err := feegrant.NewMsgGrantAllowance(grant, granter, grantee)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
msgClient := feegrant.NewMsgClient(svcMsgClientConn)
|
||||||
_, err = msgClient.GrantAllowance(cmd.Context(), msg)
|
_, err = msgClient.GrantAllowance(cmd.Context(), msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -189,7 +189,7 @@ Examples:
|
||||||
return cmd
|
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 {
|
func NewCmdRevokeFeegrant() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "revoke [granter] [grantee]",
|
Use: "revoke [granter] [grantee]",
|
||||||
|
@ -200,7 +200,7 @@ func NewCmdRevokeFeegrant() *cobra.Command {
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
$ %s tx %s revoke cosmos1skj.. cosmos1skj..
|
$ %s tx %s revoke cosmos1skj.. cosmos1skj..
|
||||||
`, version.AppName, types.ModuleName),
|
`, version.AppName, feegrant.ModuleName),
|
||||||
),
|
),
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -215,9 +215,9 @@ Example:
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := types.NewMsgRevokeAllowance(clientCtx.GetFromAddress(), grantee)
|
msg := feegrant.NewMsgRevokeAllowance(clientCtx.GetFromAddress(), grantee)
|
||||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
msgClient := feegrant.NewMsgClient(svcMsgClientConn)
|
||||||
_, err = msgClient.RevokeAllowance(cmd.Context(), &msg)
|
_, err = msgClient.RevokeAllowance(cmd.Context(), &msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -17,8 +17,8 @@ import (
|
||||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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/client/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
|
|
||||||
govtestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
|
govtestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
)
|
)
|
||||||
|
@ -36,7 +36,7 @@ type IntegrationTestSuite struct {
|
||||||
network *network.Network
|
network *network.Network
|
||||||
addedGranter sdk.AccAddress
|
addedGranter sdk.AccAddress
|
||||||
addedGrantee sdk.AccAddress
|
addedGrantee sdk.AccAddress
|
||||||
addedGrant types.Grant
|
addedGrant feegrant.Grant
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
|
func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
|
||||||
|
@ -89,7 +89,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
||||||
s.addedGranter = granter
|
s.addedGranter = granter
|
||||||
s.addedGrantee = grantee
|
s.addedGrantee = grantee
|
||||||
|
|
||||||
grant, err := types.NewGrant(granter, grantee, &types.BasicAllowance{
|
grant, err := feegrant.NewGrant(granter, grantee, &feegrant.BasicAllowance{
|
||||||
SpendLimit: sdk.NewCoins(fee),
|
SpendLimit: sdk.NewCoins(fee),
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -113,8 +113,8 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrant() {
|
||||||
args []string
|
args []string
|
||||||
expectErrMsg string
|
expectErrMsg string
|
||||||
expectErr bool
|
expectErr bool
|
||||||
respType *types.Grant
|
respType *feegrant.Grant
|
||||||
resp *types.Grant
|
resp *feegrant.Grant
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"wrong granter",
|
"wrong granter",
|
||||||
|
@ -155,7 +155,7 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrant() {
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
false,
|
false,
|
||||||
&types.Grant{},
|
&feegrant.Grant{},
|
||||||
&s.addedGrant,
|
&s.addedGrant,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -180,8 +180,8 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrant() {
|
||||||
grant1, err1 := tc.resp.GetGrant()
|
grant1, err1 := tc.resp.GetGrant()
|
||||||
s.Require().NoError(err1)
|
s.Require().NoError(err1)
|
||||||
s.Require().Equal(
|
s.Require().Equal(
|
||||||
grant.(*types.BasicAllowance).SpendLimit,
|
grant.(*feegrant.BasicAllowance).SpendLimit,
|
||||||
grant1.(*types.BasicAllowance).SpendLimit,
|
grant1.(*feegrant.BasicAllowance).SpendLimit,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -197,7 +197,7 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrants() {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
expectErr bool
|
expectErr bool
|
||||||
resp *types.QueryAllowancesResponse
|
resp *feegrant.QueryAllowancesResponse
|
||||||
expectLength int
|
expectLength int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -214,7 +214,7 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrants() {
|
||||||
"cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl",
|
"cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl",
|
||||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||||
},
|
},
|
||||||
false, &types.QueryAllowancesResponse{}, 0,
|
false, &feegrant.QueryAllowancesResponse{}, 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid req",
|
"valid req",
|
||||||
|
@ -222,7 +222,7 @@ func (s *IntegrationTestSuite) TestCmdGetFeeGrants() {
|
||||||
grantee.String(),
|
grantee.String(),
|
||||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
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)
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
resp := &types.Grant{}
|
resp := &feegrant.Grant{}
|
||||||
|
|
||||||
s.Require().NoError(clientCtx.JSONCodec.UnmarshalJSON(out.Bytes(), resp), out.String())
|
s.Require().NoError(clientCtx.JSONCodec.UnmarshalJSON(out.Bytes(), resp), out.String())
|
||||||
s.Require().Equal(resp.Grantee, resp.Grantee)
|
s.Require().Equal(resp.Grantee, resp.Grantee)
|
||||||
|
@ -742,11 +742,11 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() {
|
||||||
grant, err := resp.GetGrant()
|
grant, err := resp.GetGrant()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
filteredFeeGrant, err := grant.(*types.AllowedMsgAllowance).GetAllowance()
|
filteredFeeGrant, err := grant.(*feegrant.AllowedMsgAllowance).GetAllowance()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().Equal(
|
s.Require().Equal(
|
||||||
filteredFeeGrant.(*types.BasicAllowance).SpendLimit.String(),
|
filteredFeeGrant.(*feegrant.BasicAllowance).SpendLimit.String(),
|
||||||
spendLimit.String(),
|
spendLimit.String(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
@ -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.
|
another account can be done with clear and safe restrictions.
|
||||||
|
|
||||||
A user would authorize granting fee payment to another user using
|
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
|
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
|
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
|
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 fee allowance that a grantee receives is specified by an implementation of
|
||||||
the FeeAllowance interface. Two FeeAllowance implementations are provided in
|
the FeeAllowance interface. Two FeeAllowance implementations are provided in
|
||||||
this package: BasicFeeAllowance and PeriodicFeeAllowance.
|
this package: BasicAllowance and PeriodicAllowance.
|
||||||
*/
|
*/
|
||||||
package feegrant
|
package feegrant
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
// evidence module events
|
// evidence module events
|
||||||
const (
|
const (
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@ -1,7 +1,7 @@
|
||||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
// source: cosmos/feegrant/v1beta1/feegrant.proto
|
// source: cosmos/feegrant/v1beta1/feegrant.proto
|
||||||
|
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
fmt "fmt"
|
fmt "fmt"
|
||||||
|
@ -294,43 +294,43 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileDescriptor_7279582900c30aea = []byte{
|
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,
|
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,
|
0x14, 0x8f, 0x9b, 0xa4, 0x90, 0x0b, 0x94, 0xc6, 0x14, 0xe1, 0x64, 0x70, 0xa2, 0x0e, 0x34, 0x0c,
|
||||||
0x9c, 0x69, 0xd9, 0xca, 0x42, 0x1d, 0x20, 0x42, 0xa2, 0x12, 0x32, 0x4c, 0x2c, 0xd1, 0xd9, 0x79,
|
0xb5, 0x69, 0xd9, 0xca, 0x42, 0x1c, 0xa0, 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,
|
0x35, 0x27, 0x6c, 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,
|
0x88, 0x8a, 0xa9, 0x82, 0x85, 0x89, 0xa2, 0xe4, 0x8b, 0x20, 0xdf, 0x9d, 0x9d, 0x90, 0xf0, 0x47,
|
||||||
0x42, 0x9d, 0xe2, 0xbb, 0xf7, 0x7e, 0xff, 0xde, 0x3b, 0x05, 0xdd, 0x08, 0x18, 0x8f, 0x18, 0x77,
|
0xaa, 0x3a, 0xc5, 0x77, 0xef, 0xfd, 0xfe, 0xbd, 0x77, 0x0a, 0xba, 0xe5, 0x53, 0x16, 0x51, 0x66,
|
||||||
0x0e, 0x01, 0xc2, 0x94, 0xc4, 0xc2, 0x79, 0xb5, 0xe3, 0x83, 0x20, 0x3b, 0xb3, 0x0b, 0x9c, 0xa4,
|
0x1f, 0x02, 0x04, 0x29, 0x8e, 0xb9, 0xfd, 0x7a, 0xc7, 0x03, 0x8e, 0x77, 0x8a, 0x0b, 0x2b, 0x49,
|
||||||
0x4c, 0x30, 0xf3, 0xba, 0xea, 0xc3, 0xb3, 0x6b, 0xdd, 0xd7, 0xd8, 0x0a, 0x59, 0xc8, 0x64, 0x8f,
|
0x29, 0xa7, 0xfa, 0x4d, 0xd9, 0x67, 0x15, 0xd7, 0xaa, 0xaf, 0xb5, 0x11, 0xd0, 0x80, 0x8a, 0x1e,
|
||||||
0x93, 0x7d, 0xa9, 0xf6, 0x46, 0x3d, 0x64, 0x2c, 0x1c, 0x82, 0x23, 0x4f, 0xfe, 0xe8, 0xd0, 0x21,
|
0x3b, 0xfb, 0x92, 0xed, 0xad, 0x66, 0x40, 0x69, 0x10, 0x82, 0x2d, 0x4e, 0xde, 0xe8, 0xd0, 0xc6,
|
||||||
0xf1, 0x38, 0x2f, 0x29, 0xa6, 0xbe, 0xc2, 0x68, 0x5a, 0x55, 0xb2, 0xb5, 0x19, 0x9f, 0x70, 0x98,
|
0xf1, 0x38, 0x2f, 0x49, 0xa6, 0x81, 0xc4, 0x28, 0x5a, 0x59, 0x32, 0x95, 0x19, 0x0f, 0x33, 0x28,
|
||||||
0x19, 0x09, 0x18, 0x8d, 0x75, 0xbd, 0xb9, 0xcc, 0x2a, 0x68, 0x04, 0x5c, 0x90, 0x28, 0xc9, 0x09,
|
0x8c, 0xf8, 0x94, 0xc4, 0xaa, 0xde, 0x5e, 0x64, 0xe5, 0x24, 0x02, 0xc6, 0x71, 0x94, 0xe4, 0x04,
|
||||||
0x96, 0x1b, 0x06, 0xa3, 0x94, 0x08, 0xca, 0x34, 0xc1, 0xf6, 0x57, 0x03, 0x6d, 0xb8, 0x84, 0xd3,
|
0x8b, 0x0d, 0xc3, 0x51, 0x8a, 0x39, 0xa1, 0x8a, 0x60, 0xf3, 0x9b, 0x86, 0xd6, 0x1c, 0xcc, 0x88,
|
||||||
0x60, 0x7f, 0x38, 0x64, 0xaf, 0x49, 0x1c, 0x80, 0x39, 0x44, 0x55, 0x9e, 0x40, 0x3c, 0xe8, 0x0f,
|
0xdf, 0x0b, 0x43, 0xfa, 0x06, 0xc7, 0x3e, 0xe8, 0x21, 0xaa, 0xb3, 0x04, 0xe2, 0xe1, 0x20, 0x24,
|
||||||
0x69, 0x44, 0x85, 0x65, 0xb4, 0x8a, 0xed, 0xea, 0x6e, 0x1d, 0x6b, 0x5f, 0x99, 0x93, 0x3c, 0x2a,
|
0x11, 0xe1, 0x86, 0xd6, 0x29, 0x77, 0xeb, 0xbb, 0x4d, 0x4b, 0xf9, 0xca, 0x9c, 0xe4, 0x51, 0xad,
|
||||||
0xee, 0x32, 0x1a, 0xbb, 0xb7, 0x4f, 0xbe, 0x37, 0x0b, 0x1f, 0xcf, 0x9a, 0xed, 0x90, 0x8a, 0x17,
|
0x3e, 0x25, 0xb1, 0x73, 0xe7, 0xe4, 0x47, 0xbb, 0xf4, 0xe9, 0xac, 0xdd, 0x0d, 0x08, 0x7f, 0x39,
|
||||||
0x23, 0x1f, 0x07, 0x2c, 0xd2, 0x21, 0xf4, 0x4f, 0x87, 0x0f, 0x5e, 0x3a, 0x62, 0x9c, 0x00, 0x97,
|
0xf2, 0x2c, 0x9f, 0x46, 0x2a, 0x84, 0xfa, 0xd9, 0x66, 0xc3, 0x57, 0x36, 0x1f, 0x27, 0xc0, 0x04,
|
||||||
0x00, 0xee, 0x21, 0xc9, 0xff, 0x38, 0xa3, 0x37, 0xef, 0x21, 0x04, 0x47, 0x09, 0x55, 0xa6, 0xac,
|
0x80, 0xb9, 0x48, 0xf0, 0x3f, 0xc9, 0xe8, 0xf5, 0xfb, 0x08, 0xc1, 0x51, 0x42, 0xa4, 0x29, 0x63,
|
||||||
0xb5, 0x96, 0xd1, 0xae, 0xee, 0x36, 0xb0, 0x72, 0x8d, 0x73, 0xd7, 0xf8, 0x59, 0x1e, 0xcb, 0x2d,
|
0xa5, 0xa3, 0x75, 0xeb, 0xbb, 0x2d, 0x4b, 0xba, 0xb6, 0x72, 0xd7, 0xd6, 0xf3, 0x3c, 0x96, 0x53,
|
||||||
0x1d, 0x9f, 0x35, 0x0d, 0x6f, 0x01, 0xb3, 0x57, 0xfb, 0xf2, 0xa9, 0x73, 0xf9, 0x21, 0xc0, 0x2c,
|
0x39, 0x3e, 0x6b, 0x6b, 0xee, 0x1c, 0x66, 0xaf, 0xf1, 0xf5, 0xf3, 0xf6, 0xd5, 0x47, 0x00, 0x45,
|
||||||
0xc1, 0xa3, 0xed, 0x69, 0x11, 0xd5, 0x9e, 0x40, 0x4a, 0xd9, 0x60, 0x31, 0x58, 0x17, 0x95, 0xfd,
|
0x82, 0xc7, 0x9b, 0xd3, 0x32, 0x6a, 0x3c, 0x85, 0x94, 0xd0, 0xe1, 0x7c, 0xb0, 0x3e, 0xaa, 0x7a,
|
||||||
0x2c, 0xaa, 0x65, 0x48, 0x95, 0x9b, 0xf8, 0x0f, 0x1b, 0xc4, 0xbf, 0x0e, 0xc4, 0x2d, 0x65, 0x01,
|
0x59, 0x54, 0x43, 0x13, 0x2a, 0x5b, 0xd6, 0x5f, 0x36, 0x68, 0xfd, 0x3e, 0x10, 0xa7, 0x92, 0x05,
|
||||||
0x3d, 0x85, 0x35, 0xef, 0xa2, 0xf5, 0x44, 0x32, 0x6b, 0xaf, 0xf5, 0x15, 0xaf, 0xf7, 0xf5, 0x84,
|
0x74, 0x25, 0x56, 0xbf, 0x87, 0x56, 0x13, 0xc1, 0xac, 0xbc, 0x36, 0x97, 0xbc, 0x3e, 0x50, 0x13,
|
||||||
0xdd, 0x8b, 0x19, 0xee, 0x5d, 0x66, 0x57, 0x43, 0xcc, 0x31, 0x32, 0xd5, 0x57, 0x7f, 0x71, 0xc2,
|
0x76, 0x2e, 0x67, 0xb8, 0xf7, 0x99, 0x5d, 0x05, 0xd1, 0xc7, 0x48, 0x97, 0x5f, 0x83, 0xf9, 0x09,
|
||||||
0xc5, 0xf3, 0x9f, 0xf0, 0xa6, 0x92, 0x79, 0x3a, 0x9f, 0xf3, 0x08, 0xe9, 0xbb, 0x7e, 0x40, 0x62,
|
0x97, 0x2f, 0x7e, 0xc2, 0xeb, 0x52, 0xe6, 0xd9, 0x6c, 0xce, 0x23, 0xa4, 0xee, 0x06, 0x3e, 0x8e,
|
||||||
0x25, 0x6f, 0x95, 0xce, 0x5f, 0x78, 0x43, 0x89, 0x74, 0x49, 0x2c, 0xb5, 0xcd, 0x1e, 0xba, 0xa4,
|
0xa5, 0xbc, 0x51, 0xb9, 0x78, 0xe1, 0x35, 0x29, 0xd2, 0xc7, 0xb1, 0xd0, 0xd6, 0xf7, 0xd1, 0x15,
|
||||||
0x65, 0x53, 0xe0, 0x20, 0xac, 0xf2, 0x3f, 0x17, 0x2c, 0xa7, 0x26, 0x97, 0x5c, 0x55, 0x48, 0x2f,
|
0x25, 0x9b, 0x02, 0x03, 0x6e, 0x54, 0xff, 0xbb, 0x60, 0x31, 0x35, 0xb1, 0xe4, 0xba, 0x44, 0xba,
|
||||||
0x03, 0xfe, 0x6e, 0xcb, 0xef, 0x0d, 0x74, 0x55, 0x1e, 0x61, 0x70, 0xc0, 0xc3, 0xf9, 0x9e, 0x1f,
|
0x19, 0xf0, 0x4f, 0x5b, 0xfe, 0xa0, 0xa1, 0xeb, 0xe2, 0x08, 0xc3, 0x03, 0x16, 0xcc, 0xf6, 0xfc,
|
||||||
0xa0, 0x0a, 0xc9, 0x0f, 0x7a, 0xd7, 0x5b, 0x2b, 0x82, 0xfb, 0xf1, 0xd8, 0xad, 0x7d, 0x5e, 0xe6,
|
0x10, 0xd5, 0x70, 0x7e, 0x50, 0xbb, 0xde, 0x58, 0x12, 0xec, 0xc5, 0x63, 0xa7, 0xf1, 0x65, 0x91,
|
||||||
0xf4, 0xe6, 0x48, 0xf3, 0x16, 0xda, 0x24, 0x8a, 0xbd, 0x1f, 0x01, 0xe7, 0x24, 0x04, 0x6e, 0xad,
|
0xd3, 0x9d, 0x21, 0xf5, 0xdb, 0x68, 0x1d, 0x4b, 0xf6, 0x41, 0x04, 0x8c, 0xe1, 0x00, 0x98, 0xb1,
|
||||||
0xb5, 0x8a, 0xed, 0x8a, 0x77, 0x45, 0xdf, 0x1f, 0xe8, 0xeb, 0xbd, 0x6b, 0x6f, 0x3f, 0x34, 0x0b,
|
0xd2, 0x29, 0x77, 0x6b, 0xee, 0x35, 0x75, 0x7f, 0xa0, 0xae, 0xf7, 0x6e, 0xbc, 0xfb, 0xd8, 0x2e,
|
||||||
0xab, 0x06, 0xdf, 0x18, 0xa8, 0xdc, 0xcb, 0x5e, 0x96, 0x69, 0xa1, 0x0b, 0xf2, 0x89, 0x41, 0x2a,
|
0x2d, 0x1b, 0x7c, 0xab, 0xa1, 0xea, 0x7e, 0xf6, 0xb2, 0x74, 0x03, 0x5d, 0x12, 0x4f, 0x0c, 0x52,
|
||||||
0x0d, 0x55, 0xbc, 0xfc, 0x38, 0xaf, 0x80, 0x7c, 0x50, 0xb3, 0xca, 0x52, 0x8c, 0xe2, 0xff, 0xc6,
|
0x61, 0xa8, 0xe6, 0xe6, 0xc7, 0x59, 0x05, 0xc4, 0x83, 0x2a, 0x2a, 0x0b, 0x31, 0xca, 0xe7, 0x8d,
|
||||||
0x70, 0x7b, 0x27, 0x13, 0xdb, 0x38, 0x9d, 0xd8, 0xc6, 0x8f, 0x89, 0x6d, 0x1c, 0x4f, 0xed, 0xc2,
|
0xe1, 0xf4, 0x4e, 0x26, 0xa6, 0x76, 0x3a, 0x31, 0xb5, 0x9f, 0x13, 0x53, 0x3b, 0x9e, 0x9a, 0xa5,
|
||||||
0xe9, 0xd4, 0x2e, 0x7c, 0x9b, 0xda, 0x85, 0xe7, 0x9d, 0xbf, 0x6e, 0xf5, 0x68, 0xfe, 0x0f, 0x28,
|
0xd3, 0xa9, 0x59, 0xfa, 0x3e, 0x35, 0x4b, 0x2f, 0xb6, 0xfe, 0xb9, 0xd5, 0xa3, 0xe2, 0x0f, 0xcf,
|
||||||
0x17, 0xec, 0xaf, 0x4b, 0xd1, 0x3b, 0x3f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x34, 0xef, 0x7e, 0x35,
|
0x5b, 0x15, 0x72, 0x77, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0xd0, 0x08, 0x9a, 0x3d, 0x1b, 0x05,
|
||||||
0x21, 0x05, 0x00, 0x00,
|
0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *BasicAllowance) Marshal() (dAtA []byte, err error) {
|
func (m *BasicAllowance) Marshal() (dAtA []byte, err error) {
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
@ -16,7 +16,7 @@ type FeeAllowanceI interface {
|
||||||
// and will be saved again after an acceptance.
|
// and will be saved again after an acceptance.
|
||||||
//
|
//
|
||||||
// If remove is true (regardless of the error), the FeeAllowance will be deleted from storage
|
// 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)
|
Accept(ctx sdk.Context, fee sdk.Coins, msgs []sdk.Msg) (remove bool, err error)
|
||||||
|
|
||||||
// ValidateBasic should evaluate this FeeAllowance for internal consistency.
|
// ValidateBasic should evaluate this FeeAllowance for internal consistency.
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
@ -1,29 +1,26 @@
|
||||||
package feegrant
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitGenesis will initialize the keeper from a *previously validated* GenesisState
|
var _ types.UnpackInterfacesMessage = 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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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()
|
grant, err := f.GetGrant()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
err = grant.ValidateBasic()
|
||||||
err = k.GrantAllowance(ctx, granter, grantee, grant)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -31,16 +28,19 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, data *types.GenesisState) err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExportGenesis will dump the contents of the keeper into a serializable GenesisState.
|
// DefaultGenesisState returns default state for feegrant module.
|
||||||
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) (*types.GenesisState, error) {
|
func DefaultGenesisState() *GenesisState {
|
||||||
var grants []types.Grant
|
return &GenesisState{}
|
||||||
|
}
|
||||||
err := k.IterateAllFeeAllowances(ctx, func(grant types.Grant) bool {
|
|
||||||
grants = append(grants, grant)
|
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
||||||
return false
|
func (data GenesisState) UnpackInterfaces(unpacker types.AnyUnpacker) error {
|
||||||
})
|
for _, f := range data.Allowances {
|
||||||
|
err := f.UnpackInterfaces(unpacker)
|
||||||
return &types.GenesisState{
|
if err != nil {
|
||||||
Allowances: grants,
|
return err
|
||||||
}, err
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
// source: cosmos/feegrant/v1beta1/genesis.proto
|
// source: cosmos/feegrant/v1beta1/genesis.proto
|
||||||
|
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
fmt "fmt"
|
fmt "fmt"
|
||||||
|
@ -77,7 +77,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileDescriptor_ac719d2d0954d1bf = []byte{
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
0x3d, 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,
|
0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x01, 0x77, 0x5e, 0x12, 0x1b, 0xd8, 0x7d, 0xc6, 0x80, 0x00, 0x00,
|
||||||
0x95, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8b, 0xe8, 0xa0, 0x07, 0x25, 0x01, 0x00, 0x00,
|
0x00, 0xff, 0xff, 0x3e, 0xdc, 0xb9, 0x91, 0x1f, 0x01, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
|
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
|
@ -1,4 +1,4 @@
|
||||||
package types_test
|
package feegrant_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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) {
|
func TestGrant(t *testing.T) {
|
||||||
|
@ -75,7 +75,7 @@ func TestGrant(t *testing.T) {
|
||||||
for name, tc := range cases {
|
for name, tc := range cases {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(name, func(t *testing.T) {
|
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,
|
SpendLimit: tc.limit,
|
||||||
Expiration: &tc.expires,
|
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
|
// if it is valid, let's try to serialize, deserialize, and make sure it matches
|
||||||
bz, err := cdc.Marshal(&grant)
|
bz, err := cdc.Marshal(&grant)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var loaded types.Grant
|
var loaded feegrant.Grant
|
||||||
err = cdc.Unmarshal(bz, &loaded)
|
err = cdc.Unmarshal(bz, &loaded)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package feegrant_test
|
package keeper_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -11,9 +11,8 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GenesisTestSuite struct {
|
type GenesisTestSuite struct {
|
||||||
|
@ -42,22 +41,22 @@ func (suite *GenesisTestSuite) TestImportExportGenesis() {
|
||||||
oneYear := now.AddDate(1, 0, 0)
|
oneYear := now.AddDate(1, 0, 0)
|
||||||
msgSrvr := keeper.NewMsgServerImpl(suite.keeper)
|
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)
|
err := suite.keeper.GrantAllowance(suite.ctx, granterAddr, granteeAddr, allowance)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
genesis, err := feegrant.ExportGenesis(suite.ctx, suite.keeper)
|
genesis, err := suite.keeper.ExportGenesis(suite.ctx)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
// revoke fee allowance
|
// revoke fee allowance
|
||||||
_, err = msgSrvr.RevokeAllowance(sdk.WrapSDKContext(suite.ctx), &types.MsgRevokeAllowance{
|
_, err = msgSrvr.RevokeAllowance(sdk.WrapSDKContext(suite.ctx), &feegrant.MsgRevokeAllowance{
|
||||||
Granter: granterAddr.String(),
|
Granter: granterAddr.String(),
|
||||||
Grantee: granteeAddr.String(),
|
Grantee: granteeAddr.String(),
|
||||||
})
|
})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
err = feegrant.InitGenesis(suite.ctx, suite.keeper, genesis)
|
err = suite.keeper.InitGenesis(suite.ctx, genesis)
|
||||||
suite.Require().NoError(err)
|
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().NoError(err)
|
||||||
suite.Require().Equal(genesis, newGenesis)
|
suite.Require().Equal(genesis, newGenesis)
|
||||||
}
|
}
|
||||||
|
@ -68,11 +67,11 @@ func (suite *GenesisTestSuite) TestInitGenesis() {
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
feeAllowances []types.Grant
|
feeAllowances []feegrant.Grant
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"invalid granter",
|
"invalid granter",
|
||||||
[]types.Grant{
|
[]feegrant.Grant{
|
||||||
{
|
{
|
||||||
Granter: "invalid granter",
|
Granter: "invalid granter",
|
||||||
Grantee: granteeAddr.String(),
|
Grantee: granteeAddr.String(),
|
||||||
|
@ -81,7 +80,7 @@ func (suite *GenesisTestSuite) TestInitGenesis() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid grantee",
|
"invalid grantee",
|
||||||
[]types.Grant{
|
[]feegrant.Grant{
|
||||||
{
|
{
|
||||||
Granter: granterAddr.String(),
|
Granter: granterAddr.String(),
|
||||||
Grantee: "invalid grantee",
|
Grantee: "invalid grantee",
|
||||||
|
@ -90,7 +89,7 @@ func (suite *GenesisTestSuite) TestInitGenesis() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid allowance",
|
"invalid allowance",
|
||||||
[]types.Grant{
|
[]feegrant.Grant{
|
||||||
{
|
{
|
||||||
Granter: granterAddr.String(),
|
Granter: granterAddr.String(),
|
||||||
Grantee: granteeAddr.String(),
|
Grantee: granteeAddr.String(),
|
||||||
|
@ -103,7 +102,7 @@ func (suite *GenesisTestSuite) TestInitGenesis() {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
suite.Run(tc.name, func() {
|
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)
|
suite.Require().Error(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -11,13 +11,13 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/query"
|
"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.
|
// 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 {
|
if req == nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
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 nil, status.Errorf(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.QueryAllowanceResponse{
|
return &feegrant.QueryAllowanceResponse{
|
||||||
Allowance: &types.Grant{
|
Allowance: &feegrant.Grant{
|
||||||
Granter: granterAddr.String(),
|
Granter: granterAddr.String(),
|
||||||
Grantee: granteeAddr.String(),
|
Grantee: granteeAddr.String(),
|
||||||
Allowance: feeAllowanceAny,
|
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.
|
// 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 {
|
if req == nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
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)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
|
|
||||||
var grants []*types.Grant
|
var grants []*feegrant.Grant
|
||||||
|
|
||||||
store := ctx.KVStore(q.storeKey)
|
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 {
|
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 {
|
if err := q.cdc.Unmarshal(value, &grant); err != nil {
|
||||||
return err
|
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 nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.QueryAllowancesResponse{Allowances: grants, Pagination: pageRes}, nil
|
return &feegrant.QueryAllowancesResponse{Allowances: grants, Pagination: pageRes}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,58 +2,58 @@ package keeper_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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() {
|
func (suite *KeeperTestSuite) TestFeeAllowance() {
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
req *types.QueryAllowanceRequest
|
req *feegrant.QueryAllowanceRequest
|
||||||
expectErr bool
|
expectErr bool
|
||||||
preRun func()
|
preRun func()
|
||||||
postRun func(_ *types.QueryAllowanceResponse)
|
postRun func(_ *feegrant.QueryAllowanceResponse)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"nil request",
|
"nil request",
|
||||||
nil,
|
nil,
|
||||||
true,
|
true,
|
||||||
func() {},
|
func() {},
|
||||||
func(*types.QueryAllowanceResponse) {},
|
func(*feegrant.QueryAllowanceResponse) {},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fail: invalid granter",
|
"fail: invalid granter",
|
||||||
&types.QueryAllowanceRequest{
|
&feegrant.QueryAllowanceRequest{
|
||||||
Granter: "invalid_granter",
|
Granter: "invalid_granter",
|
||||||
Grantee: suite.addrs[0].String(),
|
Grantee: suite.addrs[0].String(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
func() {},
|
func() {},
|
||||||
func(*types.QueryAllowanceResponse) {},
|
func(*feegrant.QueryAllowanceResponse) {},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fail: invalid grantee",
|
"fail: invalid grantee",
|
||||||
&types.QueryAllowanceRequest{
|
&feegrant.QueryAllowanceRequest{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: "invalid_grantee",
|
Grantee: "invalid_grantee",
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
func() {},
|
func() {},
|
||||||
func(*types.QueryAllowanceResponse) {},
|
func(*feegrant.QueryAllowanceResponse) {},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fail: no grants",
|
"fail: no grants",
|
||||||
&types.QueryAllowanceRequest{
|
&feegrant.QueryAllowanceRequest{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
func() {},
|
func() {},
|
||||||
func(*types.QueryAllowanceResponse) {},
|
func(*feegrant.QueryAllowanceResponse) {},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid query: expect single grant",
|
"valid query: expect single grant",
|
||||||
&types.QueryAllowanceRequest{
|
&feegrant.QueryAllowanceRequest{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
},
|
},
|
||||||
|
@ -61,7 +61,7 @@ func (suite *KeeperTestSuite) TestFeeAllowance() {
|
||||||
func() {
|
func() {
|
||||||
grantFeeAllowance(suite)
|
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.Granter, suite.addrs[0].String())
|
||||||
suite.Require().Equal(response.Allowance.Grantee, suite.addrs[1].String())
|
suite.Require().Equal(response.Allowance.Grantee, suite.addrs[1].String())
|
||||||
},
|
},
|
||||||
|
@ -85,48 +85,48 @@ func (suite *KeeperTestSuite) TestFeeAllowance() {
|
||||||
func (suite *KeeperTestSuite) TestFeeAllowances() {
|
func (suite *KeeperTestSuite) TestFeeAllowances() {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
req *types.QueryAllowancesRequest
|
req *feegrant.QueryAllowancesRequest
|
||||||
expectErr bool
|
expectErr bool
|
||||||
preRun func()
|
preRun func()
|
||||||
postRun func(_ *types.QueryAllowancesResponse)
|
postRun func(_ *feegrant.QueryAllowancesResponse)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"nil request",
|
"nil request",
|
||||||
nil,
|
nil,
|
||||||
true,
|
true,
|
||||||
func() {},
|
func() {},
|
||||||
func(*types.QueryAllowancesResponse) {},
|
func(*feegrant.QueryAllowancesResponse) {},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fail: invalid grantee",
|
"fail: invalid grantee",
|
||||||
&types.QueryAllowancesRequest{
|
&feegrant.QueryAllowancesRequest{
|
||||||
Grantee: "invalid_grantee",
|
Grantee: "invalid_grantee",
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
func() {},
|
func() {},
|
||||||
func(*types.QueryAllowancesResponse) {},
|
func(*feegrant.QueryAllowancesResponse) {},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"no grants",
|
"no grants",
|
||||||
&types.QueryAllowancesRequest{
|
&feegrant.QueryAllowancesRequest{
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
func() {},
|
func() {},
|
||||||
func(resp *types.QueryAllowancesResponse) {
|
func(resp *feegrant.QueryAllowancesResponse) {
|
||||||
suite.Require().Equal(len(resp.Allowances), 0)
|
suite.Require().Equal(len(resp.Allowances), 0)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid query: expect single grant",
|
"valid query: expect single grant",
|
||||||
&types.QueryAllowancesRequest{
|
&feegrant.QueryAllowancesRequest{
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
func() {
|
func() {
|
||||||
grantFeeAllowance(suite)
|
grantFeeAllowance(suite)
|
||||||
},
|
},
|
||||||
func(resp *types.QueryAllowancesResponse) {
|
func(resp *feegrant.QueryAllowancesResponse) {
|
||||||
suite.Require().Equal(len(resp.Allowances), 1)
|
suite.Require().Equal(len(resp.Allowances), 1)
|
||||||
suite.Require().Equal(resp.Allowances[0].Granter, suite.addrs[0].String())
|
suite.Require().Equal(resp.Allowances[0].Granter, suite.addrs[0].String())
|
||||||
suite.Require().Equal(resp.Allowances[0].Grantee, suite.addrs[1].String())
|
suite.Require().Equal(resp.Allowances[0].Grantee, suite.addrs[1].String())
|
||||||
|
@ -150,7 +150,7 @@ func (suite *KeeperTestSuite) TestFeeAllowances() {
|
||||||
|
|
||||||
func grantFeeAllowance(suite *KeeperTestSuite) {
|
func grantFeeAllowance(suite *KeeperTestSuite) {
|
||||||
exp := suite.sdkCtx.BlockTime().AddDate(1, 0, 0)
|
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)),
|
SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 555)),
|
||||||
Expiration: &exp,
|
Expiration: &exp,
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
"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.
|
// Keeper manages state of all fee grants, as well as calculating approval.
|
||||||
|
@ -17,13 +17,13 @@ import (
|
||||||
type Keeper struct {
|
type Keeper struct {
|
||||||
cdc codec.BinaryCodec
|
cdc codec.BinaryCodec
|
||||||
storeKey sdk.StoreKey
|
storeKey sdk.StoreKey
|
||||||
authKeeper types.AccountKeeper
|
authKeeper feegrant.AccountKeeper
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ ante.FeegrantKeeper = &Keeper{}
|
var _ ante.FeegrantKeeper = &Keeper{}
|
||||||
|
|
||||||
// NewKeeper creates a fee grant 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{
|
return Keeper{
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
storeKey: storeKey,
|
storeKey: storeKey,
|
||||||
|
@ -33,11 +33,11 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, ak types.AccountKee
|
||||||
|
|
||||||
// Logger returns a module-specific logger.
|
// Logger returns a module-specific logger.
|
||||||
func (k Keeper) Logger(ctx sdk.Context) log.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
|
// 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
|
// create the account if it is not in account state
|
||||||
granteeAcc := k.authKeeper.GetAccount(ctx, grantee)
|
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)
|
store := ctx.KVStore(k.storeKey)
|
||||||
key := types.FeeAllowanceKey(granter, grantee)
|
key := feegrant.FeeAllowanceKey(granter, grantee)
|
||||||
grant, err := types.NewGrant(granter, grantee, feeAllowance)
|
grant, err := feegrant.NewGrant(granter, grantee, feeAllowance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -62,9 +62,9 @@ func (k Keeper) GrantAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress,
|
||||||
|
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
types.EventTypeSetFeeGrant,
|
feegrant.EventTypeSetFeeGrant,
|
||||||
sdk.NewAttribute(types.AttributeKeyGranter, grant.Granter),
|
sdk.NewAttribute(feegrant.AttributeKeyGranter, grant.Granter),
|
||||||
sdk.NewAttribute(types.AttributeKeyGrantee, grant.Grantee),
|
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)
|
store := ctx.KVStore(k.storeKey)
|
||||||
key := types.FeeAllowanceKey(granter, grantee)
|
key := feegrant.FeeAllowanceKey(granter, grantee)
|
||||||
store.Delete(key)
|
store.Delete(key)
|
||||||
|
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
types.EventTypeRevokeFeeGrant,
|
feegrant.EventTypeRevokeFeeGrant,
|
||||||
sdk.NewAttribute(types.AttributeKeyGranter, granter.String()),
|
sdk.NewAttribute(feegrant.AttributeKeyGranter, granter.String()),
|
||||||
sdk.NewAttribute(types.AttributeKeyGrantee, grantee.String()),
|
sdk.NewAttribute(feegrant.AttributeKeyGrantee, grantee.String()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return nil
|
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.
|
// GetAllowance returns the allowance between the granter and grantee.
|
||||||
// If there is none, it returns nil, nil.
|
// If there is none, it returns nil, nil.
|
||||||
// Returns an error on parsing issues
|
// 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)
|
grant, err := k.getGrant(ctx, granter, grantee)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// 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)
|
store := ctx.KVStore(k.storeKey)
|
||||||
key := types.FeeAllowanceKey(granter, grantee)
|
key := feegrant.FeeAllowanceKey(granter, grantee)
|
||||||
bz := store.Get(key)
|
bz := store.Get(key)
|
||||||
if len(bz) == 0 {
|
if len(bz) == 0 {
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "fee-grant not found")
|
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 {
|
if err := k.cdc.Unmarshal(bz, &feegrant); err != nil {
|
||||||
return nil, err
|
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.
|
// IterateAllFeeAllowances iterates over all the grants in the store.
|
||||||
// Callback to get all data, returns true to stop, false to keep reading
|
// 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
|
// 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)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, types.FeeAllowanceKeyPrefix)
|
iter := sdk.KVStorePrefixIterator(store, feegrant.FeeAllowanceKeyPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
|
|
||||||
stop := false
|
stop := false
|
||||||
for ; iter.Valid() && !stop; iter.Next() {
|
for ; iter.Valid() && !stop; iter.Next() {
|
||||||
bz := iter.Value()
|
bz := iter.Value()
|
||||||
var feeGrant types.Grant
|
var feeGrant feegrant.Grant
|
||||||
if err := k.cdc.Unmarshal(bz, &feeGrant); err != nil {
|
if err := k.cdc.Unmarshal(bz, &feeGrant); err != nil {
|
||||||
return err
|
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) {
|
func emitUseGrantEvent(ctx sdk.Context, granter, grantee string) {
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
types.EventTypeUseFeeGrant,
|
feegrant.EventTypeUseFeeGrant,
|
||||||
sdk.NewAttribute(types.AttributeKeyGranter, granter),
|
sdk.NewAttribute(feegrant.AttributeKeyGranter, granter),
|
||||||
sdk.NewAttribute(types.AttributeKeyGrantee, grantee),
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type KeeperTestSuite struct {
|
type KeeperTestSuite struct {
|
||||||
|
@ -19,7 +19,7 @@ type KeeperTestSuite struct {
|
||||||
app *simapp.SimApp
|
app *simapp.SimApp
|
||||||
sdkCtx sdk.Context
|
sdkCtx sdk.Context
|
||||||
addrs []sdk.AccAddress
|
addrs []sdk.AccAddress
|
||||||
msgSrvr types.MsgServer
|
msgSrvr feegrant.MsgServer
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
atom sdk.Coins
|
atom sdk.Coins
|
||||||
keeper keeper.Keeper
|
keeper keeper.Keeper
|
||||||
|
@ -46,12 +46,12 @@ func (suite *KeeperTestSuite) TestKeeperCrud() {
|
||||||
// some helpers
|
// some helpers
|
||||||
eth := sdk.NewCoins(sdk.NewInt64Coin("eth", 123))
|
eth := sdk.NewCoins(sdk.NewInt64Coin("eth", 123))
|
||||||
exp := suite.sdkCtx.BlockTime().AddDate(1, 0, 0)
|
exp := suite.sdkCtx.BlockTime().AddDate(1, 0, 0)
|
||||||
basic := &types.BasicAllowance{
|
basic := &feegrant.BasicAllowance{
|
||||||
SpendLimit: suite.atom,
|
SpendLimit: suite.atom,
|
||||||
Expiration: &exp,
|
Expiration: &exp,
|
||||||
}
|
}
|
||||||
|
|
||||||
basic2 := &types.BasicAllowance{
|
basic2 := &feegrant.BasicAllowance{
|
||||||
SpendLimit: eth,
|
SpendLimit: eth,
|
||||||
Expiration: &exp,
|
Expiration: &exp,
|
||||||
}
|
}
|
||||||
|
@ -73,13 +73,13 @@ func (suite *KeeperTestSuite) TestKeeperCrud() {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// remove some, overwrite other
|
// 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)
|
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)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// revoke non-exist fee allowance
|
// 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)
|
suite.Require().Error(err)
|
||||||
|
|
||||||
err = suite.keeper.GrantAllowance(suite.sdkCtx, suite.addrs[0], suite.addrs[2], basic)
|
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 {
|
cases := map[string]struct {
|
||||||
grantee sdk.AccAddress
|
grantee sdk.AccAddress
|
||||||
granter sdk.AccAddress
|
granter sdk.AccAddress
|
||||||
allowance types.FeeAllowanceI
|
allowance feegrant.FeeAllowanceI
|
||||||
}{
|
}{
|
||||||
"addr revoked": {
|
"addr revoked": {
|
||||||
granter: suite.addrs[0],
|
granter: suite.addrs[0],
|
||||||
|
@ -142,7 +142,7 @@ func (suite *KeeperTestSuite) TestKeeperCrud() {
|
||||||
_, err = suite.keeper.GetAllowance(suite.sdkCtx, suite.addrs[3], accAddr)
|
_, err = suite.keeper.GetAllowance(suite.sdkCtx, suite.addrs[3], accAddr)
|
||||||
suite.Require().NoError(err)
|
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)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() {
|
||||||
blockTime := suite.sdkCtx.BlockTime()
|
blockTime := suite.sdkCtx.BlockTime()
|
||||||
oneYear := blockTime.AddDate(1, 0, 0)
|
oneYear := blockTime.AddDate(1, 0, 0)
|
||||||
|
|
||||||
future := &types.BasicAllowance{
|
future := &feegrant.BasicAllowance{
|
||||||
SpendLimit: suite.atom,
|
SpendLimit: suite.atom,
|
||||||
Expiration: &oneYear,
|
Expiration: &oneYear,
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() {
|
||||||
// for testing limits of the contract
|
// for testing limits of the contract
|
||||||
hugeAtom := sdk.NewCoins(sdk.NewInt64Coin("atom", 9999))
|
hugeAtom := sdk.NewCoins(sdk.NewInt64Coin("atom", 9999))
|
||||||
smallAtom := sdk.NewCoins(sdk.NewInt64Coin("atom", 1))
|
smallAtom := sdk.NewCoins(sdk.NewInt64Coin("atom", 1))
|
||||||
futureAfterSmall := &types.BasicAllowance{
|
futureAfterSmall := &feegrant.BasicAllowance{
|
||||||
SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 554)),
|
SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 554)),
|
||||||
Expiration: &oneYear,
|
Expiration: &oneYear,
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() {
|
||||||
granter sdk.AccAddress
|
granter sdk.AccAddress
|
||||||
fee sdk.Coins
|
fee sdk.Coins
|
||||||
allowed bool
|
allowed bool
|
||||||
final types.FeeAllowanceI
|
final feegrant.FeeAllowanceI
|
||||||
}{
|
}{
|
||||||
"use entire pot": {
|
"use entire pot": {
|
||||||
granter: suite.addrs[0],
|
granter: suite.addrs[0],
|
||||||
|
@ -214,7 +214,7 @@ func (suite *KeeperTestSuite) TestUseGrantedFee() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
expired := &types.BasicAllowance{
|
expired := &feegrant.BasicAllowance{
|
||||||
SpendLimit: eth,
|
SpendLimit: eth,
|
||||||
Expiration: &blockTime,
|
Expiration: &blockTime,
|
||||||
}
|
}
|
||||||
|
@ -239,12 +239,12 @@ func (suite *KeeperTestSuite) TestIterateGrants() {
|
||||||
eth := sdk.NewCoins(sdk.NewInt64Coin("eth", 123))
|
eth := sdk.NewCoins(sdk.NewInt64Coin("eth", 123))
|
||||||
exp := suite.sdkCtx.BlockTime().AddDate(1, 0, 0)
|
exp := suite.sdkCtx.BlockTime().AddDate(1, 0, 0)
|
||||||
|
|
||||||
allowance := &types.BasicAllowance{
|
allowance := &feegrant.BasicAllowance{
|
||||||
SpendLimit: suite.atom,
|
SpendLimit: suite.atom,
|
||||||
Expiration: &exp,
|
Expiration: &exp,
|
||||||
}
|
}
|
||||||
|
|
||||||
allowance1 := &types.BasicAllowance{
|
allowance1 := &feegrant.BasicAllowance{
|
||||||
SpendLimit: eth,
|
SpendLimit: eth,
|
||||||
Expiration: &exp,
|
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[0], suite.addrs[1], allowance)
|
||||||
suite.keeper.GrantAllowance(suite.sdkCtx, suite.addrs[2], suite.addrs[1], allowance1)
|
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().Equal(suite.addrs[1].String(), grant.Grantee)
|
||||||
suite.Require().Contains([]string{suite.addrs[0].String(), suite.addrs[2].String()}, grant.Granter)
|
suite.Require().Contains([]string{suite.addrs[0].String(), suite.addrs[2].String()}, grant.Granter)
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
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 {
|
type msgServer struct {
|
||||||
|
@ -15,16 +15,16 @@ type msgServer struct {
|
||||||
|
|
||||||
// NewMsgServerImpl returns an implementation of the feegrant MsgServer interface
|
// NewMsgServerImpl returns an implementation of the feegrant MsgServer interface
|
||||||
// for the provided Keeper.
|
// for the provided Keeper.
|
||||||
func NewMsgServerImpl(k Keeper) types.MsgServer {
|
func NewMsgServerImpl(k Keeper) feegrant.MsgServer {
|
||||||
return &msgServer{
|
return &msgServer{
|
||||||
Keeper: k,
|
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.
|
// 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)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
|
|
||||||
grantee, err := sdk.AccAddressFromBech32(msg.Grantee)
|
grantee, err := sdk.AccAddressFromBech32(msg.Grantee)
|
||||||
|
@ -52,11 +52,11 @@ func (k msgServer) GrantAllowance(goCtx context.Context, msg *types.MsgGrantAllo
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.MsgGrantAllowanceResponse{}, nil
|
return &feegrant.MsgGrantAllowanceResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RevokeAllowance revokes a fee allowance between a granter and grantee.
|
// 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)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
|
|
||||||
grantee, err := sdk.AccAddressFromBech32(msg.Grantee)
|
grantee, err := sdk.AccAddressFromBech32(msg.Grantee)
|
||||||
|
@ -74,5 +74,5 @@ func (k msgServer) RevokeAllowance(goCtx context.Context, msg *types.MsgRevokeAl
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.MsgRevokeAllowanceResponse{}, nil
|
return &feegrant.MsgRevokeAllowanceResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,24 +3,24 @@ package keeper_test
|
||||||
import (
|
import (
|
||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
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)
|
oneYear := suite.sdkCtx.BlockTime().AddDate(1, 0, 0)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
req func() *types.MsgGrantAllowance
|
req func() *feegrant.MsgGrantAllowance
|
||||||
expectErr bool
|
expectErr bool
|
||||||
errMsg string
|
errMsg string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"invalid granter address",
|
"invalid granter address",
|
||||||
func() *types.MsgGrantAllowance {
|
func() *feegrant.MsgGrantAllowance {
|
||||||
any, err := codectypes.NewAnyWithValue(&types.BasicAllowance{})
|
any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
return &types.MsgGrantAllowance{
|
return &feegrant.MsgGrantAllowance{
|
||||||
Granter: "invalid-granter",
|
Granter: "invalid-granter",
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
Allowance: any,
|
Allowance: any,
|
||||||
|
@ -31,10 +31,10 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid grantee address",
|
"invalid grantee address",
|
||||||
func() *types.MsgGrantAllowance {
|
func() *feegrant.MsgGrantAllowance {
|
||||||
any, err := codectypes.NewAnyWithValue(&types.BasicAllowance{})
|
any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
return &types.MsgGrantAllowance{
|
return &feegrant.MsgGrantAllowance{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: "invalid-grantee",
|
Grantee: "invalid-grantee",
|
||||||
Allowance: any,
|
Allowance: any,
|
||||||
|
@ -45,13 +45,13 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid: basic fee allowance",
|
"valid: basic fee allowance",
|
||||||
func() *types.MsgGrantAllowance {
|
func() *feegrant.MsgGrantAllowance {
|
||||||
any, err := codectypes.NewAnyWithValue(&types.BasicAllowance{
|
any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{
|
||||||
SpendLimit: suite.atom,
|
SpendLimit: suite.atom,
|
||||||
Expiration: &oneYear,
|
Expiration: &oneYear,
|
||||||
})
|
})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
return &types.MsgGrantAllowance{
|
return &feegrant.MsgGrantAllowance{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
Allowance: any,
|
Allowance: any,
|
||||||
|
@ -62,13 +62,13 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fail: fee allowance exists",
|
"fail: fee allowance exists",
|
||||||
func() *types.MsgGrantAllowance {
|
func() *feegrant.MsgGrantAllowance {
|
||||||
any, err := codectypes.NewAnyWithValue(&types.BasicAllowance{
|
any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{
|
||||||
SpendLimit: suite.atom,
|
SpendLimit: suite.atom,
|
||||||
Expiration: &oneYear,
|
Expiration: &oneYear,
|
||||||
})
|
})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
return &types.MsgGrantAllowance{
|
return &feegrant.MsgGrantAllowance{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
Allowance: any,
|
Allowance: any,
|
||||||
|
@ -79,15 +79,15 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid: periodic fee allowance",
|
"valid: periodic fee allowance",
|
||||||
func() *types.MsgGrantAllowance {
|
func() *feegrant.MsgGrantAllowance {
|
||||||
any, err := codectypes.NewAnyWithValue(&types.PeriodicAllowance{
|
any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{
|
||||||
Basic: types.BasicAllowance{
|
Basic: feegrant.BasicAllowance{
|
||||||
SpendLimit: suite.atom,
|
SpendLimit: suite.atom,
|
||||||
Expiration: &oneYear,
|
Expiration: &oneYear,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
return &types.MsgGrantAllowance{
|
return &feegrant.MsgGrantAllowance{
|
||||||
Granter: suite.addrs[1].String(),
|
Granter: suite.addrs[1].String(),
|
||||||
Grantee: suite.addrs[2].String(),
|
Grantee: suite.addrs[2].String(),
|
||||||
Allowance: any,
|
Allowance: any,
|
||||||
|
@ -98,15 +98,15 @@ func (suite *KeeperTestSuite) TestGrantFeeAllowance() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"error: fee allowance exists",
|
"error: fee allowance exists",
|
||||||
func() *types.MsgGrantAllowance {
|
func() *feegrant.MsgGrantAllowance {
|
||||||
any, err := codectypes.NewAnyWithValue(&types.PeriodicAllowance{
|
any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{
|
||||||
Basic: types.BasicAllowance{
|
Basic: feegrant.BasicAllowance{
|
||||||
SpendLimit: suite.atom,
|
SpendLimit: suite.atom,
|
||||||
Expiration: &oneYear,
|
Expiration: &oneYear,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
return &types.MsgGrantAllowance{
|
return &feegrant.MsgGrantAllowance{
|
||||||
Granter: suite.addrs[1].String(),
|
Granter: suite.addrs[1].String(),
|
||||||
Grantee: suite.addrs[2].String(),
|
Grantee: suite.addrs[2].String(),
|
||||||
Allowance: any,
|
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)
|
oneYear := suite.sdkCtx.BlockTime().AddDate(1, 0, 0)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
request *types.MsgRevokeAllowance
|
request *feegrant.MsgRevokeAllowance
|
||||||
preRun func()
|
preRun func()
|
||||||
expectErr bool
|
expectErr bool
|
||||||
errMsg string
|
errMsg string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"error: invalid granter",
|
"error: invalid granter",
|
||||||
&types.MsgRevokeAllowance{
|
&feegrant.MsgRevokeAllowance{
|
||||||
Granter: "invalid-granter",
|
Granter: "invalid-granter",
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
},
|
},
|
||||||
|
@ -149,7 +149,7 @@ func (suite *KeeperTestSuite) TestRevokeFeeAllowance() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"error: invalid grantee",
|
"error: invalid grantee",
|
||||||
&types.MsgRevokeAllowance{
|
&feegrant.MsgRevokeAllowance{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: "invalid-grantee",
|
Grantee: "invalid-grantee",
|
||||||
},
|
},
|
||||||
|
@ -159,7 +159,7 @@ func (suite *KeeperTestSuite) TestRevokeFeeAllowance() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"error: fee allowance not found",
|
"error: fee allowance not found",
|
||||||
&types.MsgRevokeAllowance{
|
&feegrant.MsgRevokeAllowance{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
},
|
},
|
||||||
|
@ -169,24 +169,24 @@ func (suite *KeeperTestSuite) TestRevokeFeeAllowance() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"success: revoke fee allowance",
|
"success: revoke fee allowance",
|
||||||
&types.MsgRevokeAllowance{
|
&feegrant.MsgRevokeAllowance{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
},
|
},
|
||||||
func() {
|
func() {
|
||||||
// removing fee allowance from previous tests if exists
|
// 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(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
})
|
})
|
||||||
any, err := codectypes.NewAnyWithValue(&types.PeriodicAllowance{
|
any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{
|
||||||
Basic: types.BasicAllowance{
|
Basic: feegrant.BasicAllowance{
|
||||||
SpendLimit: suite.atom,
|
SpendLimit: suite.atom,
|
||||||
Expiration: &oneYear,
|
Expiration: &oneYear,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
req := &types.MsgGrantAllowance{
|
req := &feegrant.MsgGrantAllowance{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
Allowance: any,
|
Allowance: any,
|
||||||
|
@ -199,7 +199,7 @@ func (suite *KeeperTestSuite) TestRevokeFeeAllowance() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"error: check fee allowance revoked",
|
"error: check fee allowance revoked",
|
||||||
&types.MsgRevokeAllowance{
|
&feegrant.MsgRevokeAllowance{
|
||||||
Granter: suite.addrs[0].String(),
|
Granter: suite.addrs[0].String(),
|
||||||
Grantee: suite.addrs[1].String(),
|
Grantee: suite.addrs[1].String(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@ -1,4 +1,4 @@
|
||||||
package feegrant
|
package module
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -18,10 +18,10 @@ import (
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
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/client/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
|
"github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/simulation"
|
"github.com/cosmos/cosmos-sdk/x/feegrant/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -41,14 +41,14 @@ type AppModuleBasic struct {
|
||||||
|
|
||||||
// Name returns the feegrant module's name.
|
// Name returns the feegrant module's name.
|
||||||
func (AppModuleBasic) Name() string {
|
func (AppModuleBasic) Name() string {
|
||||||
return types.ModuleName
|
return feegrant.ModuleName
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterServices registers a gRPC query service to respond to the
|
// RegisterServices registers a gRPC query service to respond to the
|
||||||
// module-specific gRPC queries.
|
// module-specific gRPC queries.
|
||||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
feegrant.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||||
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
feegrant.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterLegacyAminoCodec registers the feegrant module's types for the given codec.
|
// 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
|
// RegisterInterfaces registers the feegrant module's interface types
|
||||||
func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
|
func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
|
||||||
types.RegisterInterfaces(registry)
|
feegrant.RegisterInterfaces(registry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LegacyQuerierHandler returns the feegrant module sdk.Querier.
|
// 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
|
// DefaultGenesis returns default genesis state as raw bytes for the feegrant
|
||||||
// module.
|
// module.
|
||||||
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
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.
|
// ValidateGenesis performs genesis state validation for the feegrant module.
|
||||||
func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error {
|
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 {
|
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.
|
// 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.
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the feegrant module.
|
||||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) {
|
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.
|
// GetTxCmd returns the root tx command for the feegrant module.
|
||||||
|
@ -107,13 +107,13 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
||||||
type AppModule struct {
|
type AppModule struct {
|
||||||
AppModuleBasic
|
AppModuleBasic
|
||||||
keeper keeper.Keeper
|
keeper keeper.Keeper
|
||||||
accountKeeper types.AccountKeeper
|
accountKeeper feegrant.AccountKeeper
|
||||||
bankKeeper types.BankKeeper
|
bankKeeper feegrant.BankKeeper
|
||||||
registry cdctypes.InterfaceRegistry
|
registry cdctypes.InterfaceRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAppModule creates a new AppModule object
|
// 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{
|
return AppModule{
|
||||||
AppModuleBasic: AppModuleBasic{cdc: cdc},
|
AppModuleBasic: AppModuleBasic{cdc: cdc},
|
||||||
keeper: keeper,
|
keeper: keeper,
|
||||||
|
@ -125,7 +125,7 @@ func NewAppModule(cdc codec.Codec, ak types.AccountKeeper, bk types.BankKeeper,
|
||||||
|
|
||||||
// Name returns the feegrant module's name.
|
// Name returns the feegrant module's name.
|
||||||
func (AppModule) Name() string {
|
func (AppModule) Name() string {
|
||||||
return types.ModuleName
|
return feegrant.ModuleName
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterInvariants registers the feegrant module invariants.
|
// 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.
|
// Route returns the message routing key for the feegrant module.
|
||||||
func (am AppModule) Route() sdk.Route {
|
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.
|
// 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
|
// InitGenesis performs genesis initialization for the feegrant module. It returns
|
||||||
// no validator updates.
|
// no validator updates.
|
||||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate {
|
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)
|
cdc.MustUnmarshalJSON(bz, &gs)
|
||||||
|
|
||||||
err := InitGenesis(ctx, am.keeper, &gs)
|
err := am.keeper.InitGenesis(ctx, &gs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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
|
// ExportGenesis returns the exported genesis state as raw bytes for the feegrant
|
||||||
// module.
|
// module.
|
||||||
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
|
||||||
|
|
||||||
// RegisterStoreDecoder registers a decoder for feegrant module's types
|
// RegisterStoreDecoder registers a decoder for feegrant module's types
|
||||||
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
|
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.
|
// WeightedOperations returns all the feegrant module operations with their respective weights.
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
|
@ -13,7 +13,7 @@ var (
|
||||||
_ types.UnpackInterfacesMessage = &MsgGrantAllowance{}
|
_ types.UnpackInterfacesMessage = &MsgGrantAllowance{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewMsgGrantAllowance creates a new MsgGrantFeeAllowance.
|
// NewMsgGrantAllowance creates a new MsgGrantAllowance.
|
||||||
//nolint:interfacer
|
//nolint:interfacer
|
||||||
func NewMsgGrantAllowance(feeAllowance FeeAllowanceI, granter, grantee sdk.AccAddress) (*MsgGrantAllowance, error) {
|
func NewMsgGrantAllowance(feeAllowance FeeAllowanceI, granter, grantee sdk.AccAddress) (*MsgGrantAllowance, error) {
|
||||||
msg, ok := feeAllowance.(proto.Message)
|
msg, ok := feeAllowance.(proto.Message)
|
|
@ -1,4 +1,4 @@
|
||||||
package types_test
|
package feegrant_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -7,17 +7,17 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/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"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMsgGrantFeeAllowance(t *testing.T) {
|
func TestMsgGrantAllowance(t *testing.T) {
|
||||||
cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
||||||
addr, _ := sdk.AccAddressFromBech32("cosmos1aeuqja06474dfrj7uqsvukm6rael982kk89mqr")
|
addr, _ := sdk.AccAddressFromBech32("cosmos1aeuqja06474dfrj7uqsvukm6rael982kk89mqr")
|
||||||
addr2, _ := sdk.AccAddressFromBech32("cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl")
|
addr2, _ := sdk.AccAddressFromBech32("cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl")
|
||||||
atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555))
|
atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555))
|
||||||
threeHours := time.Now().Add(3 * time.Hour)
|
threeHours := time.Now().Add(3 * time.Hour)
|
||||||
basic := &types.BasicAllowance{
|
basic := &feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &threeHours,
|
Expiration: &threeHours,
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func TestMsgGrantFeeAllowance(t *testing.T) {
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
grantee sdk.AccAddress
|
grantee sdk.AccAddress
|
||||||
granter sdk.AccAddress
|
granter sdk.AccAddress
|
||||||
grant *types.BasicAllowance
|
grant *feegrant.BasicAllowance
|
||||||
valid bool
|
valid bool
|
||||||
}{
|
}{
|
||||||
"valid": {
|
"valid": {
|
||||||
|
@ -55,7 +55,7 @@ func TestMsgGrantFeeAllowance(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
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)
|
require.NoError(t, err)
|
||||||
err = msg.ValidateBasic()
|
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")
|
addr, _ := sdk.AccAddressFromBech32("cosmos1aeuqja06474dfrj7uqsvukm6rael982kk89mqr")
|
||||||
addr2, _ := sdk.AccAddressFromBech32("cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl")
|
addr2, _ := sdk.AccAddressFromBech32("cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl")
|
||||||
atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555))
|
atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555))
|
||||||
threeHours := time.Now().Add(3 * time.Hour)
|
threeHours := time.Now().Add(3 * time.Hour)
|
||||||
|
|
||||||
basic := &types.BasicAllowance{
|
basic := &feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &threeHours,
|
Expiration: &threeHours,
|
||||||
}
|
}
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
grantee sdk.AccAddress
|
grantee sdk.AccAddress
|
||||||
granter sdk.AccAddress
|
granter sdk.AccAddress
|
||||||
grant *types.BasicAllowance
|
grant *feegrant.BasicAllowance
|
||||||
valid bool
|
valid bool
|
||||||
}{
|
}{
|
||||||
"valid": {
|
"valid": {
|
||||||
|
@ -120,7 +120,7 @@ func TestMsgRevokeFeeAllowance(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
msg := types.NewMsgRevokeAllowance(tc.granter, tc.grantee)
|
msg := feegrant.NewMsgRevokeAllowance(tc.granter, tc.grantee)
|
||||||
err := msg.ValidateBasic()
|
err := msg.ValidateBasic()
|
||||||
if tc.valid {
|
if tc.valid {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
|
@ -1,4 +1,4 @@
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
@ -18,7 +18,7 @@ var _ FeeAllowanceI = (*PeriodicAllowance)(nil)
|
||||||
// and will be saved again after an acceptance.
|
// and will be saved again after an acceptance.
|
||||||
//
|
//
|
||||||
// If remove is true (regardless of the error), the FeeAllowance will be deleted from storage
|
// 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) {
|
func (a *PeriodicAllowance) Accept(ctx sdk.Context, fee sdk.Coins, _ []sdk.Msg) (bool, error) {
|
||||||
blockTime := ctx.BlockTime()
|
blockTime := ctx.BlockTime()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package types_test
|
package feegrant_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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) {
|
func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
|
@ -31,7 +31,7 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
tenMinutes := time.Duration(10) * time.Minute
|
tenMinutes := time.Duration(10) * time.Minute
|
||||||
|
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
allow types.PeriodicAllowance
|
allow feegrant.PeriodicAllowance
|
||||||
// all other checks are ignored if valid=false
|
// all other checks are ignored if valid=false
|
||||||
fee sdk.Coins
|
fee sdk.Coins
|
||||||
blockTime time.Time
|
blockTime time.Time
|
||||||
|
@ -43,12 +43,12 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
periodReset time.Time
|
periodReset time.Time
|
||||||
}{
|
}{
|
||||||
"empty": {
|
"empty": {
|
||||||
allow: types.PeriodicAllowance{},
|
allow: feegrant.PeriodicAllowance{},
|
||||||
valid: false,
|
valid: false,
|
||||||
},
|
},
|
||||||
"only basic": {
|
"only basic": {
|
||||||
allow: types.PeriodicAllowance{
|
allow: feegrant.PeriodicAllowance{
|
||||||
Basic: types.BasicAllowance{
|
Basic: feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &oneHour,
|
Expiration: &oneHour,
|
||||||
},
|
},
|
||||||
|
@ -56,7 +56,7 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
valid: false,
|
valid: false,
|
||||||
},
|
},
|
||||||
"empty basic": {
|
"empty basic": {
|
||||||
allow: types.PeriodicAllowance{
|
allow: feegrant.PeriodicAllowance{
|
||||||
Period: tenMinutes,
|
Period: tenMinutes,
|
||||||
PeriodSpendLimit: smallAtom,
|
PeriodSpendLimit: smallAtom,
|
||||||
PeriodReset: now.Add(30 * time.Minute),
|
PeriodReset: now.Add(30 * time.Minute),
|
||||||
|
@ -68,8 +68,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
periodReset: now.Add(30 * time.Minute),
|
periodReset: now.Add(30 * time.Minute),
|
||||||
},
|
},
|
||||||
"mismatched currencies": {
|
"mismatched currencies": {
|
||||||
allow: types.PeriodicAllowance{
|
allow: feegrant.PeriodicAllowance{
|
||||||
Basic: types.BasicAllowance{
|
Basic: feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &oneHour,
|
Expiration: &oneHour,
|
||||||
},
|
},
|
||||||
|
@ -79,8 +79,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
valid: false,
|
valid: false,
|
||||||
},
|
},
|
||||||
"same period": {
|
"same period": {
|
||||||
allow: types.PeriodicAllowance{
|
allow: feegrant.PeriodicAllowance{
|
||||||
Basic: types.BasicAllowance{
|
Basic: feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &twoHours,
|
Expiration: &twoHours,
|
||||||
},
|
},
|
||||||
|
@ -99,8 +99,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
periodReset: now.Add(1 * time.Hour),
|
periodReset: now.Add(1 * time.Hour),
|
||||||
},
|
},
|
||||||
"step one period": {
|
"step one period": {
|
||||||
allow: types.PeriodicAllowance{
|
allow: feegrant.PeriodicAllowance{
|
||||||
Basic: types.BasicAllowance{
|
Basic: feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &twoHours,
|
Expiration: &twoHours,
|
||||||
},
|
},
|
||||||
|
@ -118,8 +118,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
periodReset: oneHour.Add(10 * time.Minute), // one step from last reset, not now
|
periodReset: oneHour.Add(10 * time.Minute), // one step from last reset, not now
|
||||||
},
|
},
|
||||||
"step limited by global allowance": {
|
"step limited by global allowance": {
|
||||||
allow: types.PeriodicAllowance{
|
allow: feegrant.PeriodicAllowance{
|
||||||
Basic: types.BasicAllowance{
|
Basic: feegrant.BasicAllowance{
|
||||||
SpendLimit: smallAtom,
|
SpendLimit: smallAtom,
|
||||||
Expiration: &twoHours,
|
Expiration: &twoHours,
|
||||||
},
|
},
|
||||||
|
@ -137,8 +137,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
periodReset: oneHour.Add(10 * time.Minute), // one step from last reset, not now
|
periodReset: oneHour.Add(10 * time.Minute), // one step from last reset, not now
|
||||||
},
|
},
|
||||||
"expired": {
|
"expired": {
|
||||||
allow: types.PeriodicAllowance{
|
allow: feegrant.PeriodicAllowance{
|
||||||
Basic: types.BasicAllowance{
|
Basic: feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &now,
|
Expiration: &now,
|
||||||
},
|
},
|
||||||
|
@ -152,8 +152,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
remove: true,
|
remove: true,
|
||||||
},
|
},
|
||||||
"over period limit": {
|
"over period limit": {
|
||||||
allow: types.PeriodicAllowance{
|
allow: feegrant.PeriodicAllowance{
|
||||||
Basic: types.BasicAllowance{
|
Basic: feegrant.BasicAllowance{
|
||||||
SpendLimit: atom,
|
SpendLimit: atom,
|
||||||
Expiration: &now,
|
Expiration: &now,
|
||||||
},
|
},
|
|
@ -1,7 +1,7 @@
|
||||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
// source: cosmos/feegrant/v1beta1/query.proto
|
// source: cosmos/feegrant/v1beta1/query.proto
|
||||||
|
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
context "context"
|
context "context"
|
||||||
|
@ -251,34 +251,34 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileDescriptor_59efc303945de53f = []byte{
|
var fileDescriptor_59efc303945de53f = []byte{
|
||||||
// 432 bytes of a gzipped FileDescriptorProto
|
// 430 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xc1, 0xca, 0xd3, 0x40,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4e, 0xce, 0x2f, 0xce,
|
||||||
0x10, 0xc7, 0xbb, 0x15, 0x95, 0x6e, 0x6f, 0x0b, 0xda, 0x10, 0x24, 0x94, 0x08, 0x55, 0x84, 0xee,
|
0xcd, 0x2f, 0xd6, 0x4f, 0x4b, 0x4d, 0x4d, 0x2f, 0x4a, 0xcc, 0x2b, 0xd1, 0x2f, 0x33, 0x4c, 0x4a,
|
||||||
0xda, 0x8a, 0xe2, 0x41, 0x0a, 0x7a, 0xb0, 0x07, 0x2f, 0x9a, 0x83, 0x07, 0x6f, 0x9b, 0x3a, 0xc6,
|
0x2d, 0x49, 0x34, 0xd4, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17,
|
||||||
0x60, 0x9b, 0x4d, 0xb3, 0x5b, 0xb5, 0x4a, 0x2f, 0x3e, 0x81, 0xe0, 0x1b, 0x78, 0xf0, 0xe4, 0x83,
|
0x12, 0x87, 0x28, 0xd2, 0x83, 0x29, 0xd2, 0x83, 0x2a, 0x92, 0x52, 0xc3, 0xa5, 0x1b, 0xae, 0x12,
|
||||||
0x78, 0x2c, 0x78, 0xf1, 0xe6, 0x47, 0xfb, 0x3d, 0xc8, 0x47, 0x37, 0xd9, 0x24, 0x5f, 0xdb, 0xd0,
|
0x6c, 0x80, 0x94, 0x16, 0x54, 0x5d, 0x52, 0x62, 0x71, 0x2a, 0xc4, 0x64, 0xb8, 0xca, 0x82, 0xc4,
|
||||||
0x9c, 0x92, 0xcd, 0xfc, 0xe7, 0x3f, 0xbf, 0x99, 0xd9, 0xe0, 0xdb, 0x13, 0x21, 0x67, 0x42, 0xb2,
|
0xf4, 0xcc, 0xbc, 0xc4, 0x92, 0xcc, 0xfc, 0x3c, 0xa8, 0x5a, 0x99, 0xf4, 0xfc, 0xfc, 0xf4, 0x9c,
|
||||||
0x77, 0x00, 0x41, 0xc2, 0x23, 0xc5, 0x3e, 0x0e, 0x7c, 0x50, 0x7c, 0xc0, 0xe6, 0x0b, 0x48, 0x96,
|
0x54, 0xfd, 0xc4, 0x82, 0x4c, 0xfd, 0xc4, 0xbc, 0xbc, 0xfc, 0x12, 0xb0, 0x64, 0x31, 0x44, 0x56,
|
||||||
0x34, 0x4e, 0x84, 0x12, 0xa4, 0x93, 0x8a, 0xa8, 0x11, 0xd1, 0x4c, 0x64, 0xf7, 0xaa, 0xb2, 0x73,
|
0xc9, 0x9b, 0x4b, 0x34, 0x10, 0xa4, 0xdf, 0x31, 0x27, 0x27, 0xbf, 0x3c, 0x31, 0x2f, 0x39, 0x35,
|
||||||
0xa5, 0x36, 0xb0, 0xef, 0x65, 0x3a, 0x9f, 0x4b, 0x48, 0x9d, 0x73, 0x65, 0xcc, 0x83, 0x30, 0xe2,
|
0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0x44, 0x48, 0x82, 0x8b, 0x1d, 0x6c, 0x63, 0x6a, 0x91, 0x04,
|
||||||
0x2a, 0x14, 0x51, 0xa6, 0xbd, 0x15, 0x08, 0x11, 0x4c, 0x81, 0xf1, 0x38, 0x64, 0x3c, 0x8a, 0x84,
|
0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x8c, 0x8b, 0x90, 0x49, 0x95, 0x60, 0x42, 0x96, 0x49, 0x55,
|
||||||
0xd2, 0x41, 0x99, 0x46, 0xdd, 0x17, 0xf8, 0xc6, 0xab, 0x5d, 0xfe, 0xd3, 0xe9, 0x54, 0x7c, 0xe2,
|
0x0a, 0xe3, 0x12, 0x43, 0x37, 0xac, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0xc8, 0x86, 0x8b, 0x33,
|
||||||
0xd1, 0x04, 0x3c, 0x98, 0x2f, 0x40, 0x2a, 0x62, 0xe1, 0xeb, 0xba, 0x22, 0x24, 0x16, 0xea, 0xa2,
|
0x11, 0x26, 0x08, 0x36, 0x8f, 0xdb, 0x48, 0x4e, 0x0f, 0x47, 0x28, 0xe8, 0xb9, 0x83, 0x78, 0x41,
|
||||||
0xbb, 0x2d, 0xcf, 0x1c, 0x8b, 0x08, 0x58, 0xcd, 0x72, 0x04, 0xdc, 0xd7, 0xf8, 0xe6, 0xbe, 0x99,
|
0x08, 0x0d, 0x4a, 0x55, 0xe8, 0xe6, 0x16, 0x63, 0xb8, 0x32, 0x15, 0xd5, 0x95, 0xa9, 0x42, 0x6e,
|
||||||
0x8c, 0x45, 0x24, 0x81, 0x3c, 0xc1, 0x2d, 0x6e, 0x3e, 0x6a, 0xbf, 0xf6, 0xd0, 0xa1, 0x15, 0x53,
|
0x5c, 0x5c, 0x88, 0xa0, 0x00, 0x3b, 0x94, 0xdb, 0x48, 0x0d, 0x66, 0x25, 0x28, 0xdc, 0xf4, 0x20,
|
||||||
0xa0, 0xe3, 0xdd, 0xc9, 0x2b, 0x12, 0xdc, 0x2f, 0xfb, 0xbe, 0xf2, 0x80, 0x12, 0x2e, 0x53, 0x02,
|
0x31, 0x02, 0xb3, 0x34, 0x20, 0x31, 0x1d, 0xe6, 0xf7, 0x20, 0x24, 0x9d, 0x4a, 0x8b, 0x18, 0xb9,
|
||||||
0x79, 0x8e, 0x71, 0x31, 0x0a, 0x0d, 0xda, 0x1e, 0xf6, 0x4c, 0xc9, 0xdd, 0xdc, 0x68, 0xba, 0x11,
|
0xc4, 0x31, 0x2c, 0x87, 0xfa, 0xca, 0x8e, 0x8b, 0x0b, 0xee, 0xc8, 0x62, 0x09, 0x46, 0x05, 0x66,
|
||||||
0x53, 0xf4, 0x25, 0x0f, 0x4c, 0xef, 0x5e, 0x29, 0xd3, 0xfd, 0x89, 0x70, 0xe7, 0xa0, 0x78, 0xd6,
|
0x22, 0xbc, 0x85, 0xa4, 0x43, 0xc8, 0x1d, 0x8b, 0x1b, 0xd5, 0x09, 0xba, 0x11, 0x62, 0x39, 0xb2,
|
||||||
0xd5, 0x08, 0xe3, 0x1c, 0x52, 0x5a, 0xa8, 0x7b, 0xa5, 0x46, 0x5b, 0xa5, 0x0c, 0x32, 0x3e, 0xc2,
|
0x23, 0x8d, 0xee, 0x33, 0x71, 0xb1, 0x82, 0x1d, 0x29, 0xb4, 0x86, 0x91, 0x8b, 0x13, 0xee, 0x52,
|
||||||
0x78, 0xe7, 0x24, 0x63, 0x5a, 0xbc, 0x0c, 0x39, 0xfc, 0xdf, 0xc4, 0x57, 0x35, 0x24, 0xf9, 0x8d,
|
0x21, 0x3d, 0x9c, 0x8e, 0xc1, 0x1a, 0xe9, 0x52, 0xfa, 0x44, 0xab, 0x87, 0x38, 0x42, 0xc9, 0xae,
|
||||||
0x70, 0x2b, 0x27, 0x25, 0xb4, 0x12, 0xe6, 0xe8, 0xd2, 0x6d, 0x56, 0x5b, 0x9f, 0x42, 0xb8, 0xa3,
|
0xe9, 0xf2, 0x93, 0xc9, 0x4c, 0x16, 0x42, 0x66, 0xfa, 0xb8, 0x52, 0x2e, 0xdc, 0xbb, 0xfa, 0xd5,
|
||||||
0x6f, 0x7f, 0xcf, 0x7f, 0x34, 0x1f, 0x93, 0x47, 0xac, 0xea, 0xe6, 0xe6, 0xed, 0xb2, 0xaf, 0xd9,
|
0xd0, 0x04, 0x54, 0x0b, 0x63, 0xa5, 0xd6, 0x0a, 0x2d, 0x63, 0xe4, 0xe2, 0x42, 0x04, 0xac, 0x10,
|
||||||
0x05, 0x5a, 0x99, 0x37, 0x58, 0x91, 0x5f, 0x08, 0xe3, 0x62, 0xb0, 0xa4, 0x6e, 0x7d, 0xb3, 0x7f,
|
0xb1, 0xf6, 0xc3, 0xe2, 0x5f, 0xca, 0x80, 0x78, 0x0d, 0x50, 0x17, 0x9b, 0x82, 0x5d, 0xac, 0x2f,
|
||||||
0xfb, 0x7e, 0xfd, 0x84, 0x8c, 0xf8, 0xa1, 0x26, 0x66, 0xa4, 0x7f, 0x9a, 0x58, 0x16, 0xa0, 0xcf,
|
0xa4, 0x4b, 0xd8, 0xc5, 0xc5, 0x08, 0x87, 0x3a, 0x39, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91,
|
||||||
0xc6, 0x7f, 0x36, 0x0e, 0x5a, 0x6f, 0x1c, 0x74, 0xb6, 0x71, 0xd0, 0xf7, 0xad, 0xd3, 0x58, 0x6f,
|
0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3,
|
||||||
0x9d, 0xc6, 0xbf, 0xad, 0xd3, 0x78, 0xd3, 0x0f, 0x42, 0xf5, 0x7e, 0xe1, 0xd3, 0x89, 0x98, 0x19,
|
0xb1, 0x1c, 0x43, 0x94, 0x7a, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0x2e, 0xcc,
|
||||||
0xcb, 0xf4, 0xd1, 0x97, 0x6f, 0x3f, 0xb0, 0xcf, 0x85, 0xbf, 0x5a, 0xc6, 0x20, 0xfd, 0x6b, 0xfa,
|
0x48, 0x08, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x01, 0x37, 0x3f, 0x89, 0x0d, 0x9c, 0xe3, 0x8c,
|
||||||
0xbf, 0x7b, 0x70, 0x11, 0x00, 0x00, 0xff, 0xff, 0x86, 0xb1, 0x57, 0xa8, 0x29, 0x04, 0x00, 0x00,
|
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.
|
// Reference imports to suppress errors if they are not otherwise used.
|
|
@ -2,11 +2,11 @@
|
||||||
// source: cosmos/feegrant/v1beta1/query.proto
|
// 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.
|
It translates gRPC into RESTful JSON APIs.
|
||||||
*/
|
*/
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
"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
|
// 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 {
|
func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
|
||||||
return func(kvA, kvB kv.Pair) string {
|
return func(kvA, kvB kv.Pair) string {
|
||||||
switch {
|
switch {
|
||||||
case bytes.Equal(kvA.Key[:1], types.FeeAllowanceKeyPrefix):
|
case bytes.Equal(kvA.Key[:1], feegrant.FeeAllowanceKeyPrefix):
|
||||||
var grantA, grantB types.Grant
|
var grantA, grantB feegrant.Grant
|
||||||
cdc.MustUnmarshal(kvA.Value, &grantA)
|
cdc.MustUnmarshal(kvA.Value, &grantA)
|
||||||
cdc.MustUnmarshal(kvB.Value, &grantB)
|
cdc.MustUnmarshal(kvB.Value, &grantB)
|
||||||
return fmt.Sprintf("%v\n%v", grantA, grantB)
|
return fmt.Sprintf("%v\n%v", grantA, grantB)
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
"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/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -25,7 +25,7 @@ func TestDecodeStore(t *testing.T) {
|
||||||
cdc := simapp.MakeTestEncodingConfig().Marshaler
|
cdc := simapp.MakeTestEncodingConfig().Marshaler
|
||||||
dec := simulation.NewDecodeStore(cdc)
|
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))),
|
SpendLimit: sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(100))),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ func TestDecodeStore(t *testing.T) {
|
||||||
|
|
||||||
kvPairs := kv.Pairs{
|
kvPairs := kv.Pairs{
|
||||||
Pairs: []kv.Pair{
|
Pairs: []kv.Pair{
|
||||||
{Key: []byte(types.FeeAllowanceKeyPrefix), Value: grantBz},
|
{Key: []byte(feegrant.FeeAllowanceKeyPrefix), Value: grantBz},
|
||||||
{Key: []byte{0x99}, Value: []byte{0x99}},
|
{Key: []byte{0x99}, Value: []byte{0x99}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,12 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
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.
|
// genFeeGrants returns a slice of randomly generated allowances.
|
||||||
func genFeeGrants(r *rand.Rand, accounts []simtypes.Account) []types.Grant {
|
func genFeeGrants(r *rand.Rand, accounts []simtypes.Account) []feegrant.Grant {
|
||||||
allowances := make([]types.Grant, len(accounts)-1)
|
allowances := make([]feegrant.Grant, len(accounts)-1)
|
||||||
for i := 0; i < len(accounts)-1; i++ {
|
for i := 0; i < len(accounts)-1; i++ {
|
||||||
granter := accounts[i].Address
|
granter := accounts[i].Address
|
||||||
grantee := accounts[i+1].Address
|
grantee := accounts[i+1].Address
|
||||||
|
@ -25,22 +22,22 @@ func genFeeGrants(r *rand.Rand, accounts []simtypes.Account) []types.Grant {
|
||||||
return allowances
|
return allowances
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRandomAllowances(granter, grantee sdk.AccAddress, r *rand.Rand) types.Grant {
|
func generateRandomAllowances(granter, grantee sdk.AccAddress, r *rand.Rand) feegrant.Grant {
|
||||||
allowances := make([]types.Grant, 3)
|
allowances := make([]feegrant.Grant, 3)
|
||||||
spendLimit := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100)))
|
spendLimit := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100)))
|
||||||
periodSpendLimit := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10)))
|
periodSpendLimit := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10)))
|
||||||
|
|
||||||
basic := types.BasicAllowance{
|
basic := feegrant.BasicAllowance{
|
||||||
SpendLimit: spendLimit,
|
SpendLimit: spendLimit,
|
||||||
}
|
}
|
||||||
|
|
||||||
basicAllowance, err := types.NewGrant(granter, grantee, &basic)
|
basicAllowance, err := feegrant.NewGrant(granter, grantee, &basic)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
allowances[0] = basicAllowance
|
allowances[0] = basicAllowance
|
||||||
|
|
||||||
periodicAllowance, err := types.NewGrant(granter, grantee, &types.PeriodicAllowance{
|
periodicAllowance, err := feegrant.NewGrant(granter, grantee, &feegrant.PeriodicAllowance{
|
||||||
Basic: basic,
|
Basic: basic,
|
||||||
PeriodSpendLimit: periodSpendLimit,
|
PeriodSpendLimit: periodSpendLimit,
|
||||||
Period: time.Hour,
|
Period: time.Hour,
|
||||||
|
@ -50,7 +47,7 @@ func generateRandomAllowances(granter, grantee sdk.AccAddress, r *rand.Rand) typ
|
||||||
}
|
}
|
||||||
allowances[1] = periodicAllowance
|
allowances[1] = periodicAllowance
|
||||||
|
|
||||||
filteredAllowance, err := types.NewGrant(granter, grantee, &types.AllowedMsgAllowance{
|
filteredAllowance, err := feegrant.NewGrant(granter, grantee, &feegrant.AllowedMsgAllowance{
|
||||||
Allowance: basicAllowance.GetAllowance(),
|
Allowance: basicAllowance.GetAllowance(),
|
||||||
AllowedMessages: []string{"/cosmos.gov.v1beta1.MsgSubmitProposal"},
|
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
|
// RandomizedGenState generates a random GenesisState for feegrant
|
||||||
func RandomizedGenState(simState *module.SimulationState) {
|
func RandomizedGenState(simState *module.SimulationState) {
|
||||||
var feegrants []types.Grant
|
var feegrants []feegrant.Grant
|
||||||
|
|
||||||
simState.AppParams.GetOrGenerate(
|
simState.AppParams.GetOrGenerate(
|
||||||
simState.Cdc, feegrant, &feegrants, simState.Rand,
|
simState.Cdc, "feegrant", &feegrants, simState.Rand,
|
||||||
func(r *rand.Rand) { feegrants = genFeeGrants(r, simState.Accounts) },
|
func(r *rand.Rand) { feegrants = genFeeGrants(r, simState.Accounts) },
|
||||||
)
|
)
|
||||||
|
|
||||||
feegrantGenesis := types.NewGenesisState(feegrants)
|
feegrantGenesis := feegrant.NewGenesisState(feegrants)
|
||||||
bz, err := simState.Cdc.MarshalJSON(feegrantGenesis)
|
bz, err := simState.Cdc.MarshalJSON(feegrantGenesis)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz)
|
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", feegrant.ModuleName, bz)
|
||||||
simState.GenState[types.ModuleName] = bz
|
simState.GenState[feegrant.ModuleName] = bz
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
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/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRandomizedGenState(t *testing.T) {
|
func TestRandomizedGenState(t *testing.T) {
|
||||||
|
@ -33,8 +33,8 @@ func TestRandomizedGenState(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
simulation.RandomizedGenState(&simState)
|
simulation.RandomizedGenState(&simState)
|
||||||
var feegrantGenesis types.GenesisState
|
var feegrantGenesis feegrant.GenesisState
|
||||||
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &feegrantGenesis)
|
simState.Cdc.MustUnmarshalJSON(simState.GenState[feegrant.ModuleName], &feegrantGenesis)
|
||||||
|
|
||||||
require.Len(t, feegrantGenesis.Allowances, len(accounts)-1)
|
require.Len(t, feegrantGenesis.Allowances, len(accounts)-1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,70 +11,70 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
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/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/simulation"
|
"github.com/cosmos/cosmos-sdk/x/simulation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Simulation operation weights constants
|
// Simulation operation weights constants
|
||||||
const (
|
const (
|
||||||
OpWeightMsgGrantFeeAllowance = "op_weight_msg_grant_fee_allowance"
|
OpWeightMsgGrantAllowance = "op_weight_msg_grant_fee_allowance"
|
||||||
OpWeightMsgRevokeFeeAllowance = "op_weight_msg_grant_revoke_allowance"
|
OpWeightMsgRevokeAllowance = "op_weight_msg_grant_revoke_allowance"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
TypeMsgGrantFeeAllowance = sdk.MsgTypeURL(&types.MsgGrantAllowance{})
|
TypeMsgGrantAllowance = sdk.MsgTypeURL(&feegrant.MsgGrantAllowance{})
|
||||||
TypeMsgRevokeFeeAllowance = sdk.MsgTypeURL(&types.MsgRevokeAllowance{})
|
TypeMsgRevokeAllowance = sdk.MsgTypeURL(&feegrant.MsgRevokeAllowance{})
|
||||||
)
|
)
|
||||||
|
|
||||||
func WeightedOperations(
|
func WeightedOperations(
|
||||||
appParams simtypes.AppParams, cdc codec.JSONCodec,
|
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,
|
protoCdc *codec.ProtoCodec,
|
||||||
) simulation.WeightedOperations {
|
) simulation.WeightedOperations {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
weightMsgGrantFeeAllowance int
|
weightMsgGrantAllowance int
|
||||||
weightMsgRevokeFeeAllowance int
|
weightMsgRevokeAllowance int
|
||||||
)
|
)
|
||||||
|
|
||||||
appParams.GetOrGenerate(cdc, OpWeightMsgGrantFeeAllowance, &weightMsgGrantFeeAllowance, nil,
|
appParams.GetOrGenerate(cdc, OpWeightMsgGrantAllowance, &weightMsgGrantAllowance, nil,
|
||||||
func(_ *rand.Rand) {
|
func(_ *rand.Rand) {
|
||||||
weightMsgGrantFeeAllowance = simappparams.DefaultWeightGrantFeeAllowance
|
weightMsgGrantAllowance = simappparams.DefaultWeightGrantAllowance
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
appParams.GetOrGenerate(cdc, OpWeightMsgRevokeFeeAllowance, &weightMsgRevokeFeeAllowance, nil,
|
appParams.GetOrGenerate(cdc, OpWeightMsgRevokeAllowance, &weightMsgRevokeAllowance, nil,
|
||||||
func(_ *rand.Rand) {
|
func(_ *rand.Rand) {
|
||||||
weightMsgRevokeFeeAllowance = simappparams.DefaultWeightRevokeFeeAllowance
|
weightMsgRevokeAllowance = simappparams.DefaultWeightRevokeAllowance
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return simulation.WeightedOperations{
|
return simulation.WeightedOperations{
|
||||||
simulation.NewWeightedOperation(
|
simulation.NewWeightedOperation(
|
||||||
weightMsgGrantFeeAllowance,
|
weightMsgGrantAllowance,
|
||||||
SimulateMsgGrantFeeAllowance(ak, bk, k, protoCdc),
|
SimulateMsgGrantAllowance(ak, bk, k, protoCdc),
|
||||||
),
|
),
|
||||||
simulation.NewWeightedOperation(
|
simulation.NewWeightedOperation(
|
||||||
weightMsgRevokeFeeAllowance,
|
weightMsgRevokeAllowance,
|
||||||
SimulateMsgRevokeFeeAllowance(ak, bk, k, protoCdc),
|
SimulateMsgRevokeAllowance(ak, bk, k, protoCdc),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SimulateMsgGrantFeeAllowance generates MsgGrantFeeAllowance with random values.
|
// SimulateMsgGrantAllowance generates MsgGrantAllowance with random values.
|
||||||
func SimulateMsgGrantFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation {
|
func SimulateMsgGrantAllowance(ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation {
|
||||||
return func(
|
return func(
|
||||||
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
|
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
|
||||||
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
||||||
granter, _ := simtypes.RandomAcc(r, accs)
|
granter, _ := simtypes.RandomAcc(r, accs)
|
||||||
grantee, _ := simtypes.RandomAcc(r, accs)
|
grantee, _ := simtypes.RandomAcc(r, accs)
|
||||||
if grantee.Address.String() == granter.Address.String() {
|
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 {
|
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)
|
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())
|
spendableCoins := bk.SpendableCoins(ctx, account.GetAddress())
|
||||||
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
|
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
|
||||||
if err != nil {
|
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)
|
spendableCoins = spendableCoins.Sub(fees)
|
||||||
if spendableCoins.Empty() {
|
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)
|
oneYear := ctx.BlockTime().AddDate(1, 0, 0)
|
||||||
msg, err := types.NewMsgGrantAllowance(&types.BasicAllowance{
|
msg, err := feegrant.NewMsgGrantAllowance(&feegrant.BasicAllowance{
|
||||||
SpendLimit: spendableCoins,
|
SpendLimit: spendableCoins,
|
||||||
Expiration: &oneYear,
|
Expiration: &oneYear,
|
||||||
}, granter.Address, grantee.Address)
|
}, granter.Address, grantee.Address)
|
||||||
|
|
||||||
if err != nil {
|
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
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
||||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||||
feegrantMsgClient := types.NewMsgClient(svcMsgClientConn)
|
feegrantMsgClient := feegrant.NewMsgClient(svcMsgClientConn)
|
||||||
_, err = feegrantMsgClient.GrantAllowance(context.Background(), msg)
|
_, err = feegrantMsgClient.GrantAllowance(context.Background(), msg)
|
||||||
if err != nil {
|
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(
|
tx, err := helpers.GenTx(
|
||||||
txGen,
|
txGen,
|
||||||
|
@ -118,20 +118,20 @@ func SimulateMsgGrantFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper, k
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
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)
|
_, _, err = app.Deliver(txGen.TxEncoder(), tx)
|
||||||
|
|
||||||
if err != nil {
|
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
|
return simtypes.NewOperationMsg(svcMsgClientConn.GetMsgs()[0], true, "", protoCdc), nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SimulateMsgRevokeFeeAllowance generates a MsgRevokeFeeAllowance with random values.
|
// SimulateMsgRevokeAllowance generates a MsgRevokeAllowance with random values.
|
||||||
func SimulateMsgRevokeFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation {
|
func SimulateMsgRevokeAllowance(ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation {
|
||||||
return func(
|
return func(
|
||||||
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
|
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
|
||||||
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
||||||
|
@ -139,7 +139,7 @@ func SimulateMsgRevokeFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper,
|
||||||
hasGrant := false
|
hasGrant := false
|
||||||
var granterAddr sdk.AccAddress
|
var granterAddr sdk.AccAddress
|
||||||
var granteeAddr 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)
|
granter, err := sdk.AccAddressFromBech32(grant.Granter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -156,29 +156,29 @@ func SimulateMsgRevokeFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper,
|
||||||
})
|
})
|
||||||
|
|
||||||
if !hasGrant {
|
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)
|
granter, ok := simtypes.FindAccount(accs, granterAddr)
|
||||||
|
|
||||||
if !ok {
|
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)
|
account := ak.GetAccount(ctx, granter.Address)
|
||||||
spendableCoins := bk.SpendableCoins(ctx, account.GetAddress())
|
spendableCoins := bk.SpendableCoins(ctx, account.GetAddress())
|
||||||
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
|
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
|
||||||
if err != nil {
|
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
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
||||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||||
feegrantMsgClient := types.NewMsgClient(svcMsgClientConn)
|
feegrantMsgClient := feegrant.NewMsgClient(svcMsgClientConn)
|
||||||
_, err = feegrantMsgClient.RevokeAllowance(context.Background(), &msg)
|
_, err = feegrantMsgClient.RevokeAllowance(context.Background(), &msg)
|
||||||
if err != nil {
|
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(
|
tx, err := helpers.GenTx(
|
||||||
|
@ -193,7 +193,7 @@ func SimulateMsgRevokeFeeAllowance(ak types.AccountKeeper, bk types.BankKeeper,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
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)
|
_, _, err = app.Deliver(txGen.TxEncoder(), tx)
|
||||||
|
|
|
@ -15,8 +15,8 @@ import (
|
||||||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
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/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SimTestSuite struct {
|
type SimTestSuite struct {
|
||||||
|
@ -78,14 +78,14 @@ func (suite *SimTestSuite) TestWeightedOperations() {
|
||||||
opMsgName string
|
opMsgName string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
simappparams.DefaultWeightGrantFeeAllowance,
|
simappparams.DefaultWeightGrantAllowance,
|
||||||
types.ModuleName,
|
feegrant.ModuleName,
|
||||||
simulation.TypeMsgGrantFeeAllowance,
|
simulation.TypeMsgGrantAllowance,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
simappparams.DefaultWeightRevokeFeeAllowance,
|
simappparams.DefaultWeightRevokeAllowance,
|
||||||
types.ModuleName,
|
feegrant.ModuleName,
|
||||||
simulation.TypeMsgRevokeFeeAllowance,
|
simulation.TypeMsgRevokeAllowance,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ func (suite *SimTestSuite) TestWeightedOperations() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SimTestSuite) TestSimulateMsgGrantFeeAllowance() {
|
func (suite *SimTestSuite) TestSimulateMsgGrantAllowance() {
|
||||||
app, ctx := suite.app, suite.ctx
|
app, ctx := suite.app, suite.ctx
|
||||||
require := suite.Require()
|
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}})
|
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash}})
|
||||||
|
|
||||||
// execute operation
|
// 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, "")
|
operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "")
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
var msg types.MsgGrantAllowance
|
var msg feegrant.MsgGrantAllowance
|
||||||
suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg)
|
suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg)
|
||||||
|
|
||||||
require.True(operationMsg.OK)
|
require.True(operationMsg.OK)
|
||||||
|
@ -125,7 +125,7 @@ func (suite *SimTestSuite) TestSimulateMsgGrantFeeAllowance() {
|
||||||
require.Len(futureOperations, 0)
|
require.Len(futureOperations, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SimTestSuite) TestSimulateMsgRevokeFeeAllowance() {
|
func (suite *SimTestSuite) TestSimulateMsgRevokeAllowance() {
|
||||||
app, ctx := suite.app, suite.ctx
|
app, ctx := suite.app, suite.ctx
|
||||||
require := suite.Require()
|
require := suite.Require()
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeFeeAllowance() {
|
||||||
ctx,
|
ctx,
|
||||||
granter.Address,
|
granter.Address,
|
||||||
grantee.Address,
|
grantee.Address,
|
||||||
&types.BasicAllowance{
|
&feegrant.BasicAllowance{
|
||||||
SpendLimit: feeCoins,
|
SpendLimit: feeCoins,
|
||||||
Expiration: &oneYear,
|
Expiration: &oneYear,
|
||||||
},
|
},
|
||||||
|
@ -154,11 +154,11 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeFeeAllowance() {
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
// execute operation
|
// 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, "")
|
operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "")
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
var msg types.MsgRevokeAllowance
|
var msg feegrant.MsgRevokeAllowance
|
||||||
suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg)
|
suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg)
|
||||||
|
|
||||||
require.True(operationMsg.OK)
|
require.True(operationMsg.OK)
|
||||||
|
|
|
@ -3,27 +3,28 @@ order: 1
|
||||||
-->
|
-->
|
||||||
|
|
||||||
# Concepts
|
# 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:
|
`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
|
## Fee Allowance types
|
||||||
There are two types of fee allowances present at the moment:
|
There are two types of fee allowances present at the moment:
|
||||||
- `BasicFeeAllowance`
|
- `BasicAllowance`
|
||||||
- `PeriodicFeeAllowance`
|
- `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.
|
- `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.
|
- 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.
|
- `period_spend_limit` specifies the maximum number of coins that can be spent in the period.
|
||||||
|
|
||||||
|
|
|
@ -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 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
|
||||||
|
|
|
@ -4,14 +4,14 @@ order: 3
|
||||||
|
|
||||||
# Messages
|
# 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
|
||||||
|
|
|
@ -8,7 +8,7 @@ The feegrant module emits the following events:
|
||||||
|
|
||||||
# Msg Server
|
# Msg Server
|
||||||
|
|
||||||
### MsgGrantFeeAllowance
|
### MsgGrantAllowance
|
||||||
|
|
||||||
| Type | Attribute Key | Attribute Value |
|
| Type | Attribute Key | Attribute Value |
|
||||||
| -------- | ------------- | ------------------ |
|
| -------- | ------------- | ------------------ |
|
||||||
|
@ -16,7 +16,7 @@ The feegrant module emits the following events:
|
||||||
| message | granter | {granterAddress} |
|
| message | granter | {granterAddress} |
|
||||||
| message | grantee | {granteeAddress} |
|
| message | grantee | {granteeAddress} |
|
||||||
|
|
||||||
### MsgRevokeFeeAllowance
|
### MsgRevokeAllowance
|
||||||
|
|
||||||
| Type | Attribute Key | Attribute Value |
|
| Type | Attribute Key | Attribute Value |
|
||||||
| -------- | ------------- | ------------------ |
|
| -------- | ------------- | ------------------ |
|
||||||
|
|
|
@ -14,20 +14,20 @@ This module allows accounts to grant fee allowances and to use fees from their a
|
||||||
## Contents
|
## Contents
|
||||||
|
|
||||||
1. **[Concepts](01_concepts.md)**
|
1. **[Concepts](01_concepts.md)**
|
||||||
- [FeeAllowanceGrant](01_concepts.md#feeallowancegrant)
|
- [Grant](01_concepts.md#grant)
|
||||||
- [Fee Allowance types](01_concepts.md#fee-allowance-types)
|
- [Fee Allowance types](01_concepts.md#fee-allowance-types)
|
||||||
- [BasicFeeAllowance](01_concepts.md#basicfeeallowance)
|
- [BasicAllowance](01_concepts.md#basicallowance)
|
||||||
- [PeriodicFeeAllowance](01_concepts.md#periodicfeeallowance)
|
- [PeriodicAllowance](01_concepts.md#periodicallowance)
|
||||||
- [FeeAccount flag](01_concepts.md#feeaccount-flag)
|
- [FeeAccount flag](01_concepts.md#feeaccount-flag)
|
||||||
- [Granted Fee Deductions](01_concepts.md#granted-fee-deductions)
|
- [Granted Fee Deductions](01_concepts.md#granted-fee-deductions)
|
||||||
- [Gas](01_concepts.md#gas)
|
- [Gas](01_concepts.md#gas)
|
||||||
2. **[State](02_state.md)**
|
2. **[State](02_state.md)**
|
||||||
- [FeeAllowance](02_state.md#feeallowance)
|
- [FeeAllowance](02_state.md#feeallowance)
|
||||||
3. **[Messages](03_messages.md)**
|
3. **[Messages](03_messages.md)**
|
||||||
- [Msg/GrantFeeAllowance](03_messages.md#msggrantfeeallowance)
|
- [Msg/GrantAllowance](03_messages.md#msggrantallowance)
|
||||||
- [Msg/RevokeFeeAllowance](03_messages.md#msgrevokefeeallowance)
|
- [Msg/RevokeAllowance](03_messages.md#msgrevokeallowance)
|
||||||
4. **[Events](04_events.md)**
|
4. **[Events](04_events.md)**
|
||||||
- [MsgGrantFeeAllowance](04_events.md#msggrantfeeallowance)
|
- [MsgGrantAllowance](04_events.md#msggrantallowance)
|
||||||
- [MsgrevokeFeeAllowance](04_events.md#msgrevokefeeallowance)
|
- [MsgRevokeAllowance](04_events.md#msgrevokeallowance)
|
||||||
- [Exec fee allowance](04_events.md#exec-fee-allowance)
|
- [Exec fee allowance](04_events.md#exec-fee-allowance)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
// source: cosmos/feegrant/v1beta1/tx.proto
|
// source: cosmos/feegrant/v1beta1/tx.proto
|
||||||
|
|
||||||
package types
|
package feegrant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
context "context"
|
context "context"
|
||||||
|
@ -234,29 +234,29 @@ func init() {
|
||||||
func init() { proto.RegisterFile("cosmos/feegrant/v1beta1/tx.proto", fileDescriptor_dd44ad7946dad783) }
|
func init() { proto.RegisterFile("cosmos/feegrant/v1beta1/tx.proto", fileDescriptor_dd44ad7946dad783) }
|
||||||
|
|
||||||
var fileDescriptor_dd44ad7946dad783 = []byte{
|
var fileDescriptor_dd44ad7946dad783 = []byte{
|
||||||
// 344 bytes of a gzipped FileDescriptorProto
|
// 339 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x92, 0xc1, 0x4e, 0xc2, 0x40,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce,
|
||||||
0x10, 0x86, 0x59, 0x49, 0x34, 0xac, 0x51, 0x43, 0x43, 0x62, 0xa9, 0x66, 0x43, 0x7a, 0x22, 0x1a,
|
0xcd, 0x2f, 0xd6, 0x4f, 0x4b, 0x4d, 0x4d, 0x2f, 0x4a, 0xcc, 0x2b, 0xd1, 0x2f, 0x33, 0x4c, 0x4a,
|
||||||
0x76, 0x03, 0x3c, 0x01, 0x24, 0x8a, 0x1e, 0xb8, 0xf4, 0xe8, 0xc5, 0xb4, 0x38, 0xac, 0x06, 0xe8,
|
0x2d, 0x49, 0x34, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x87, 0xa8,
|
||||||
0x34, 0xec, 0x82, 0xf0, 0x12, 0xc6, 0x87, 0xf1, 0x21, 0x8c, 0x27, 0x8e, 0x1e, 0x0d, 0x5c, 0x7d,
|
0xd0, 0x83, 0xa9, 0xd0, 0x83, 0xaa, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd1, 0x07,
|
||||||
0x08, 0x43, 0xdb, 0x15, 0x03, 0xd1, 0x68, 0x3c, 0xb5, 0x93, 0xf9, 0xe6, 0xff, 0xff, 0x76, 0x86,
|
0xb1, 0x20, 0xca, 0xa5, 0x24, 0xd3, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0xc1, 0xbc, 0xa4, 0xd2,
|
||||||
0x96, 0x3a, 0xa8, 0x06, 0xa8, 0x44, 0x17, 0x40, 0x0e, 0xfd, 0x50, 0x8b, 0x71, 0x35, 0x00, 0xed,
|
0x34, 0xfd, 0xc4, 0xbc, 0x4a, 0x98, 0x14, 0xc4, 0xa4, 0x78, 0x88, 0x1e, 0xa8, 0xb1, 0x60, 0x8e,
|
||||||
0x57, 0x85, 0x9e, 0xf0, 0x68, 0x88, 0x1a, 0xad, 0xc3, 0x84, 0xe0, 0x86, 0xe0, 0x29, 0xe1, 0x14,
|
0x52, 0x1f, 0x23, 0x97, 0xa0, 0x6f, 0x71, 0xba, 0x3b, 0xc8, 0x02, 0xc7, 0x9c, 0x9c, 0xfc, 0xf2,
|
||||||
0x24, 0x4a, 0x8c, 0x19, 0xb1, 0x7c, 0x4b, 0x70, 0xa7, 0x28, 0x11, 0x65, 0x1f, 0x44, 0x5c, 0x05,
|
0xc4, 0xbc, 0xe4, 0x54, 0x21, 0x09, 0x2e, 0x76, 0xb0, 0x95, 0xa9, 0x45, 0x12, 0x8c, 0x0a, 0x8c,
|
||||||
0xa3, 0xae, 0xf0, 0xc3, 0xa9, 0x69, 0x25, 0x4a, 0xd7, 0xc9, 0x4c, 0x2a, 0x1b, 0x17, 0xee, 0x03,
|
0x1a, 0x9c, 0x41, 0x30, 0x2e, 0x42, 0x26, 0x55, 0x82, 0x09, 0x59, 0x26, 0x55, 0xc8, 0x95, 0x8b,
|
||||||
0xa1, 0xf9, 0xb6, 0x92, 0xad, 0xa5, 0x41, 0xa3, 0xdf, 0xc7, 0x7b, 0x3f, 0xec, 0x80, 0x65, 0xd3,
|
0x33, 0x11, 0x66, 0x80, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x88, 0x1e, 0xc4, 0x4d, 0x7a,
|
||||||
0x9d, 0xd8, 0x12, 0x86, 0x36, 0x29, 0x91, 0x72, 0xce, 0x33, 0xe5, 0xaa, 0x03, 0xf6, 0xd6, 0xd7,
|
0x30, 0x37, 0xe9, 0x39, 0xe6, 0x55, 0x3a, 0x09, 0x9e, 0xda, 0xa2, 0xcb, 0xeb, 0x96, 0x9a, 0x0a,
|
||||||
0x0e, 0x58, 0x67, 0x34, 0xe7, 0x1b, 0x01, 0x3b, 0x5b, 0x22, 0xe5, 0xdd, 0x5a, 0x81, 0x27, 0x99,
|
0xb7, 0xce, 0x33, 0x08, 0xa1, 0x53, 0x49, 0x9a, 0x4b, 0x12, 0xc3, 0x3d, 0x41, 0xa9, 0xc5, 0x05,
|
||||||
0xb8, 0xc9, 0xc4, 0x1b, 0xe1, 0xb4, 0x99, 0x7f, 0x79, 0xaa, 0xec, 0x9d, 0x03, 0x7c, 0xda, 0x5d,
|
0xf9, 0x79, 0xc5, 0xa9, 0x4a, 0x1e, 0x5c, 0x42, 0xbe, 0xc5, 0xe9, 0x41, 0xa9, 0x65, 0xf9, 0xd9,
|
||||||
0x7a, 0xab, 0x49, 0xf7, 0x88, 0x16, 0x37, 0xf2, 0x78, 0xa0, 0x22, 0x0c, 0x15, 0xb8, 0x17, 0xd4,
|
0xa9, 0x14, 0xb9, 0x56, 0x49, 0x86, 0x4b, 0x0a, 0xd3, 0x24, 0x98, 0x3d, 0x46, 0x6f, 0x18, 0xb9,
|
||||||
0x6a, 0x2b, 0xe9, 0xc1, 0x18, 0x7b, 0xf0, 0xaf, 0xb4, 0xee, 0x31, 0x75, 0x36, 0x95, 0x8c, 0x4f,
|
0x98, 0x7d, 0x8b, 0xd3, 0x85, 0x0a, 0xb8, 0xf8, 0xd0, 0x42, 0x46, 0x4b, 0x0f, 0x47, 0xac, 0xe8,
|
||||||
0xed, 0x9d, 0xd0, 0x6c, 0x5b, 0x49, 0x2b, 0xa2, 0xfb, 0x6b, 0x7f, 0xe6, 0x84, 0x7f, 0xb3, 0x15,
|
0x61, 0xb8, 0x5a, 0xca, 0x88, 0x78, 0xb5, 0x30, 0x9b, 0x85, 0x8a, 0xb9, 0xf8, 0xd1, 0xbd, 0xa7,
|
||||||
0xbe, 0x91, 0xda, 0xa9, 0xfd, 0x9e, 0x35, 0xce, 0x96, 0xa2, 0x07, 0xeb, 0x9f, 0x77, 0xfa, 0x93,
|
0x8d, 0xcf, 0x18, 0x34, 0xc5, 0x52, 0xc6, 0x24, 0x28, 0x86, 0x59, 0xea, 0xe4, 0x78, 0xe2, 0x91,
|
||||||
0xcc, 0x1a, 0xec, 0xd4, 0xff, 0x00, 0x1b, 0xd3, 0x66, 0xeb, 0x79, 0xce, 0xc8, 0x6c, 0xce, 0xc8,
|
0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1,
|
||||||
0xdb, 0x9c, 0x91, 0xc7, 0x05, 0xcb, 0xcc, 0x16, 0x2c, 0xf3, 0xba, 0x60, 0x99, 0xab, 0x8a, 0xbc,
|
0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xea, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a,
|
||||||
0xd3, 0xb7, 0xa3, 0x80, 0x77, 0x70, 0x90, 0xde, 0x4d, 0xfa, 0xa8, 0xa8, 0x9b, 0x9e, 0x98, 0xac,
|
0xc9, 0xf9, 0xb9, 0xd0, 0x74, 0x03, 0xa5, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0xe0, 0xa9, 0x37,
|
||||||
0xae, 0x57, 0x4f, 0x23, 0x50, 0xc1, 0x76, 0xbc, 0xe8, 0xfa, 0x47, 0x00, 0x00, 0x00, 0xff, 0xff,
|
0x89, 0x0d, 0x1c, 0xc5, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x60, 0x47, 0xc8, 0xf2, 0xd7,
|
||||||
0x8d, 0x25, 0xe0, 0x0e, 0xdd, 0x02, 0x00, 0x00,
|
0x02, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
|
@ -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
|
|
||||||
}
|
|
Loading…
Reference in New Issue