diff --git a/proto/cosmos/feegrant/v1beta1/query.proto b/proto/cosmos/feegrant/v1beta1/query.proto index cc0b969c55..591537acd9 100644 --- a/proto/cosmos/feegrant/v1beta1/query.proto +++ b/proto/cosmos/feegrant/v1beta1/query.proto @@ -12,12 +12,12 @@ option go_package = "cosmossdk.io/x/feegrant"; // Query defines the gRPC querier service. service Query { - // Allowance returns fee granted to the grantee by the granter. + // Allowance returns granted allwance to the grantee by the granter. rpc Allowance(QueryAllowanceRequest) returns (QueryAllowanceResponse) { option (google.api.http).get = "/cosmos/feegrant/v1beta1/allowance/{granter}/{grantee}"; } - // Allowances returns all the grants for address. + // Allowances returns all the grants for the given grantee address. rpc Allowances(QueryAllowancesRequest) returns (QueryAllowancesResponse) { option (google.api.http).get = "/cosmos/feegrant/v1beta1/allowances/{grantee}"; } diff --git a/x/feegrant/basic_fee.go b/x/feegrant/basic_fee.go index e1eb829f52..e9703c96c1 100644 --- a/x/feegrant/basic_fee.go +++ b/x/feegrant/basic_fee.go @@ -58,6 +58,7 @@ func (a BasicAllowance) ValidateBasic() error { return nil } +// ExpiresAt returns the expiry time of the BasicAllowance. func (a BasicAllowance) ExpiresAt() (*time.Time, error) { return a.Expiration, nil } diff --git a/x/feegrant/client/cli/tx.go b/x/feegrant/client/cli/tx.go index 0f0c53ac01..2b4a8ed45b 100644 --- a/x/feegrant/client/cli/tx.go +++ b/x/feegrant/client/cli/tx.go @@ -26,11 +26,11 @@ const ( FlagAllowedMsgs = "allowed-messages" ) -// GetTxCmd returns the transaction commands for this module +// GetTxCmd returns the transaction commands for feegrant module func GetTxCmd(ac address.Codec) *cobra.Command { feegrantTxCmd := &cobra.Command{ Use: feegrant.ModuleName, - Short: "Feegrant transactions subcommands", + Short: "Feegrant transactions sub-commands", Long: "Grant and revoke fee allowance for a grantee by a granter", DisableFlagParsing: true, SuggestionsMinimumDistance: 2, @@ -45,14 +45,14 @@ func GetTxCmd(ac address.Codec) *cobra.Command { return feegrantTxCmd } -// NewCmdFeeGrant returns a CLI command handler for creating a MsgGrantAllowance transaction. +// NewCmdFeeGrant returns a CLI command handler to create a MsgGrantAllowance transaction. func NewCmdFeeGrant(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "grant [granter_key_or_address] [grantee]", Short: "Grant Fee allowance to an address", Long: strings.TrimSpace( fmt.Sprintf( - `Grant authorization to pay fees from your address. Note, the'--from' flag is + `Grant authorization to pay fees from your address. Note, the '--from' flag is ignored as it is implied from [granter]. Examples: @@ -65,7 +65,10 @@ Examples: ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - cmd.Flags().Set(flags.FlagFrom, args[0]) + if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil { + return err + } + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err @@ -82,7 +85,8 @@ Examples: return err } - // if `FlagSpendLimit` isn't set, limit will be nil + // if `FlagSpendLimit` isn't set, limit will be nil. + // Hence, there won't be any spendlimit for the grantee. limit, err := sdk.ParseCoinsNormalized(sl) if err != nil { return err @@ -119,7 +123,8 @@ Examples: return err } - // Check any of period or periodLimit flags set, If set consider it as periodic fee allowance. + // check any of period or periodLimit flags are set, + // if set consider it as periodic fee allowance. if periodClock > 0 || periodLimitVal != "" { periodLimit, err := sdk.ParseCoinsNormalized(periodLimitVal) if err != nil { @@ -181,13 +186,13 @@ Examples: return cmd } -// NewCmdRevokeFeegrant returns a CLI command handler for creating a MsgRevokeAllowance transaction. +// NewCmdRevokeFeegrant returns a CLI command handler to create a MsgRevokeAllowance transaction. func NewCmdRevokeFeegrant(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "revoke [granter] [grantee]", Short: "revoke fee-grant", Long: strings.TrimSpace( - fmt.Sprintf(`revoke fee grant from a granter to a grantee. Note, the'--from' flag is + fmt.Sprintf(`revoke fee grant from a granter to a grantee. Note, the '--from' flag is ignored as it is implied from [granter]. Example: diff --git a/x/feegrant/fees.go b/x/feegrant/fees.go index b6191204d5..fcaa8fdf9f 100644 --- a/x/feegrant/fees.go +++ b/x/feegrant/fees.go @@ -8,7 +8,7 @@ import ( ) // FeeAllowance implementations are tied to a given fee delegator and delegatee, -// and are used to enforce fee grant limits. +// and are used to enforce feegrant limits. type FeeAllowanceI interface { // Accept can use fee payment requested as well as timestamp of the current block // to determine whether or not to process this. This is checked in diff --git a/x/feegrant/filtered_fee.go b/x/feegrant/filtered_fee.go index 3dec4663a7..c6ed2fed40 100644 --- a/x/feegrant/filtered_fee.go +++ b/x/feegrant/filtered_fee.go @@ -128,6 +128,7 @@ func (a *AllowedMsgAllowance) ValidateBasic() error { return allowance.ValidateBasic() } +// ExpiresAt returns the expiry time of the AllowedMsgAllowance. func (a *AllowedMsgAllowance) ExpiresAt() (*time.Time, error) { allowance, err := a.GetAllowance() if err != nil { diff --git a/x/feegrant/keeper/grpc_query.go b/x/feegrant/keeper/grpc_query.go index 9b97a17887..7dde415171 100644 --- a/x/feegrant/keeper/grpc_query.go +++ b/x/feegrant/keeper/grpc_query.go @@ -19,7 +19,7 @@ import ( var _ feegrant.QueryServer = Keeper{} -// Allowance returns fee granted to the grantee by the granter. +// Allowance returns granted allowance to the grantee by the granter. func (q Keeper) Allowance(c context.Context, req *feegrant.QueryAllowanceRequest) (*feegrant.QueryAllowanceResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") diff --git a/x/feegrant/keeper/keeper.go b/x/feegrant/keeper/keeper.go index 291cb64be5..aa49166536 100644 --- a/x/feegrant/keeper/keeper.go +++ b/x/feegrant/keeper/keeper.go @@ -28,7 +28,7 @@ type Keeper struct { var _ ante.FeegrantKeeper = &Keeper{} -// NewKeeper creates a fee grant Keeper +// NewKeeper creates a feegrant Keeper func NewKeeper(cdc codec.BinaryCodec, storeService store.KVStoreService, ak feegrant.AccountKeeper) Keeper { return Keeper{ cdc: cdc, @@ -144,7 +144,7 @@ func (k Keeper) UpdateAllowance(ctx context.Context, granter, grantee sdk.AccAdd // revokeAllowance removes an existing grant func (k Keeper) revokeAllowance(ctx context.Context, granter, grantee sdk.AccAddress) error { - _, err := k.getGrant(ctx, granter, grantee) + grant, err := k.GetAllowance(ctx, granter, grantee) if err != nil { return err } @@ -156,6 +156,17 @@ func (k Keeper) revokeAllowance(ctx context.Context, granter, grantee sdk.AccAdd return err } + exp, err := grant.ExpiresAt() + if err != nil { + return err + } + + if exp != nil { + if err := store.Delete(feegrant.FeeAllowancePrefixQueue(exp, feegrant.FeeAllowanceKey(grantee, granter)[1:])); err != nil { + return err + } + } + sdk.UnwrapSDKContext(ctx).EventManager().EmitEvent( sdk.NewEvent( feegrant.EventTypeRevokeFeeGrant, diff --git a/x/feegrant/msgs.go b/x/feegrant/msgs.go index 655c7bcb90..3c9e7f1737 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -57,8 +57,6 @@ func (msg MsgGrantAllowance) UnpackInterfaces(unpacker types.AnyUnpacker) error // NewMsgRevokeAllowance returns a message to revoke a fee allowance for a given // granter and grantee -// - func NewMsgRevokeAllowance(granter, grantee sdk.AccAddress) MsgRevokeAllowance { return MsgRevokeAllowance{Granter: granter.String(), Grantee: grantee.String()} } diff --git a/x/feegrant/periodic_fee.go b/x/feegrant/periodic_fee.go index 5439d66fb1..d5906c955a 100644 --- a/x/feegrant/periodic_fee.go +++ b/x/feegrant/periodic_fee.go @@ -91,7 +91,7 @@ func (a PeriodicAllowance) ValidateBasic() error { if !a.PeriodCanSpend.IsValid() { return errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "can spend amount is invalid: %s", a.PeriodCanSpend) } - // We allow 0 for CanSpend + // We allow 0 for `PeriodCanSpend` if a.PeriodCanSpend.IsAnyNegative() { return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "can spend must not be negative") } @@ -109,6 +109,7 @@ func (a PeriodicAllowance) ValidateBasic() error { return nil } +// ExpiresAt returns the expiry time of the PeriodicAllowance. func (a PeriodicAllowance) ExpiresAt() (*time.Time, error) { return a.Basic.ExpiresAt() }