authorization

package
v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrAuthzDoesNotExistOrExpired is raised when the authorization does not exist.
	ErrAuthzDoesNotExistOrExpired = "authorization to %s for address %s does not exist or is expired"
	// ErrEmptyMethods is raised when the given methods array is empty.
	ErrEmptyMethods = "no methods defined; expected at least one message type url"
	// ErrEmptyStringInMethods is raised when the given methods array contains an empty string.
	ErrEmptyStringInMethods = "empty string found in methods array; expected no empty strings to be passed; got: %v"
	// ErrExceededAllowance is raised when the amount exceeds the set allowance.
	ErrExceededAllowance = "amount %s greater than allowed limit %s"
	// ErrInvalidGranter is raised when the granter address is not valid.
	ErrInvalidGranter = "invalid granter address: %v"
	// ErrInvalidGrantee is raised when the grantee address is not valid.
	ErrInvalidGrantee = "invalid grantee address: %v"
	// ErrInvalidMethods is raised when the given methods cannot be unpacked.
	ErrInvalidMethods = "invalid methods defined; expected an array of strings; got: %v"
	// ErrInvalidMethod is raised when the given method cannot be unpacked.
	ErrInvalidMethod = "invalid method defined; expected a string; got: %v"
	// ErrAuthzNotAccepted is raised when the authorization is not accepted.
	ErrAuthzNotAccepted = "authorization to %s for address %s is not accepted"
)
View Source
const (
	// ApproveMethod defines the ABI method name for the authorization Approve transaction.
	ApproveMethod = "approve"
	// RevokeMethod defines the ABI method name for the authorization Revoke transaction.
	RevokeMethod = "revoke"
	// DecreaseAllowanceMethod defines the ABI method name for the DecreaseAllowance transaction.
	DecreaseAllowanceMethod = "decreaseAllowance"
	// IncreaseAllowanceMethod defines the ABI method name for the IncreaseAllowance transaction.
	IncreaseAllowanceMethod = "increaseAllowance"
	// AllowanceMethod defines the ABI method name for the Allowance query.
	AllowanceMethod = "allowance"
	// EventTypeApproval defines the event type for the distribution Approve transaction.
	EventTypeApproval = "Approval"
	// EventTypeRevocation defines the event type for the distribution Revoke transaction.
	EventTypeRevocation = "Revocation"
	// EventTypeAllowanceChange defines the event type for the staking IncreaseAllowance or
	// DecreaseAllowance transactions.
	EventTypeAllowanceChange = "AllowanceChange"
)
View Source
const (
	// EventTypeIBCTransferAuthorization defines the event type for the ICS20 TransferAuthorization transaction.
	EventTypeIBCTransferAuthorization = "IBCTransferAuthorization" //#nosec G101 -- no hardcoded credentials here
)

Variables

This section is empty.

Functions

func CheckAllowanceArgs

func CheckAllowanceArgs(args []interface{}) (common.Address, common.Address, string, error)

CheckAllowanceArgs checks the arguments for the Allowance function.

func CheckApprovalArgs

func CheckApprovalArgs(args []interface{}, denom string) (common.Address, *sdk.Coin, []string, error)

CheckApprovalArgs checks the arguments passed to the approve function as well as the functions to change the allowance. This is refactored into one function as they all take in the same arguments.

func CheckAuthzAndAllowanceForGranter

func CheckAuthzAndAllowanceForGranter(
	ctx sdk.Context,
	authzKeeper authzkeeper.Keeper,
	grantee, granter common.Address,
	amount *sdk.Coin,
	msgURL string,
) (*stakingtypes.StakeAuthorization, *time.Time, error)

CheckAuthzAndAllowanceForGranter checks if the authorization exists and is not expired for the given spender and the allowance is not exceeded. If the authorization has a limit, checks that the provided amount does not exceed the current limit. Returns an error if the authorization does not exist is expired or the allowance is exceeded.

func CheckAuthzExists

func CheckAuthzExists(
	ctx sdk.Context,
	authzKeeper authzkeeper.Keeper,
	grantee, granter common.Address,
	msgURL string,
) (authz.Authorization, *time.Time, error)

CheckAuthzExists checks if the authorization exists for the given granter and returns the authorization and its expiration time.

NOTE: It's not necessary to check for expiration of the authorization, because that is already handled by the GetAuthorization method. If a grant is expired, it will return nil.

func CheckRevokeArgs

func CheckRevokeArgs(args []interface{}) (common.Address, []string, error)

CheckRevokeArgs checks the arguments passed to the revoke function.

func EmitIBCTransferAuthorizationEvent

func EmitIBCTransferAuthorizationEvent(
	event abi.Event,
	ctx sdk.Context,
	stateDB vm.StateDB,
	precompileAddr, granteeAddr, granterAddr common.Address,
	allocations []cmn.ICS20Allocation,
) error

EmitIBCTransferAuthorizationEvent creates a new IBC transfer authorization event emitted on a TransferAuthorization transaction.

func EmitRevocationEvent

func EmitRevocationEvent(args cmn.EmitEventArgs) error

EmitRevocationEvent creates a new approval event emitted on a Revoke transaction.

Types

type EventAllowanceChange

type EventAllowanceChange struct {
	Grantee common.Address
	Granter common.Address
	Values  []*big.Int
	Methods []string
}

EventAllowanceChange is the event emitted on successful IncreaseAllowance or DecreaseAllowance transactions.

type EventApproval

type EventApproval struct {
	Grantee common.Address
	Granter common.Address
	Value   *big.Int
	Methods []string
}

EventApproval is the event emitted on a successful Approve transaction.

type EventRevocation

type EventRevocation struct {
	Grantee  common.Address
	Granter  common.Address
	TypeUrls []string
}

EventRevocation is the event emitted on a successful Revoke transaction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL