* -add comments to proto fields -add comments to msg and query server -remove decorator from docs -add coments to msgs.go -remove decorator from godoc * Update x/feegrant/spec/04_events.md Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * refactor and add to docs *refactor proto msg names and functions *add docs pertaining to auth's ante handler for deducted fees * lint * update comment * gofmt Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com> Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
79 lines
1.9 KiB
Go
79 lines
1.9 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
|
|
)
|
|
|
|
type msgServer struct {
|
|
Keeper
|
|
}
|
|
|
|
// NewMsgServerImpl returns an implementation of the feegrant MsgServer interface
|
|
// for the provided Keeper.
|
|
func NewMsgServerImpl(k Keeper) types.MsgServer {
|
|
return &msgServer{
|
|
Keeper: k,
|
|
}
|
|
}
|
|
|
|
var _ types.MsgServer = msgServer{}
|
|
|
|
// GrantAllowance grants an allowance from the granter's funds to be used by the grantee.
|
|
func (k msgServer) GrantAllowance(goCtx context.Context, msg *types.MsgGrantAllowance) (*types.MsgGrantAllowanceResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
grantee, err := sdk.AccAddressFromBech32(msg.Grantee)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
granter, err := sdk.AccAddressFromBech32(msg.Granter)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Checking for duplicate entry
|
|
if f, _ := k.Keeper.GetAllowance(ctx, granter, grantee); f != nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee allowance already exists")
|
|
}
|
|
|
|
allowance, err := msg.GetFeeAllowanceI()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = k.Keeper.GrantAllowance(ctx, granter, grantee, allowance)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.MsgGrantAllowanceResponse{}, nil
|
|
}
|
|
|
|
// RevokeAllowance revokes a fee allowance between a granter and grantee.
|
|
func (k msgServer) RevokeAllowance(goCtx context.Context, msg *types.MsgRevokeAllowance) (*types.MsgRevokeAllowanceResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
grantee, err := sdk.AccAddressFromBech32(msg.Grantee)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
granter, err := sdk.AccAddressFromBech32(msg.Granter)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = k.Keeper.revokeAllowance(ctx, granter, grantee)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.MsgRevokeAllowanceResponse{}, nil
|
|
}
|