Documentation
¶
Overview ¶
Package orm provides the ORM layer for managing policies in the Scroll paymaster service.
Package orm provides the ORM layer for managing user operations in the Scroll paymaster service.
Index ¶
- type Policy
- func (p *Policy) Create(ctx context.Context, policy *Policy) error
- func (p *Policy) Delete(ctx context.Context, apiKey string, policyID int64) error
- func (p *Policy) GetByAPIKey(ctx context.Context, apiKey string) ([]*Policy, error)
- func (p *Policy) GetByAPIKeyAndPolicyID(ctx context.Context, apiKey string, policyID int64) (*Policy, error)
- func (*Policy) TableName() string
- func (p *Policy) Update(ctx context.Context, apiKey string, policyID int64, ...) error
- type PolicyLimits
- type UserOperation
- type UserOperationStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Policy ¶
type Policy struct {
ID uint64 `gorm:"column:id;primaryKey"`
APIKeyHash common.Hash `gorm:"column:api_key_hash"`
PolicyID int64 `gorm:"column:policy_id"`
PolicyName string `gorm:"column:policy_name"`
Limits PolicyLimits `gorm:"column:limits;serializer:json"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
DeletedAt *time.Time `gorm:"column:deleted_at"`
// contains filtered or unexported fields
}
Policy represents the data structure for sponsorship policy
func (*Policy) GetByAPIKey ¶
GetByAPIKey retrieves all policies for a given API key
func (*Policy) GetByAPIKeyAndPolicyID ¶
func (p *Policy) GetByAPIKeyAndPolicyID(ctx context.Context, apiKey string, policyID int64) (*Policy, error)
GetByAPIKeyAndPolicyID retrieves a policy by API key and policy ID
type PolicyLimits ¶
type PolicyLimits struct {
MaxEthPerWalletPerWindow string `json:"max_eth_per_wallet_per_window"`
TimeWindowHours int `json:"time_window_hours"`
}
PolicyLimits represents the limits configuration for a policy
type UserOperation ¶
type UserOperation struct {
ID uint64 `gorm:"column:id;primaryKey"`
APIKeyHash common.Hash `gorm:"column:api_key_hash;uniqueIndex:unique_idx_api_key_hash_policy_id_sender_nonce"`
PolicyID int64 `gorm:"column:policy_id;uniqueIndex:unique_idx_api_key_hash_policy_id_sender_nonce"`
Sender string `gorm:"column:sender;uniqueIndex:unique_idx_api_key_hash_policy_id_sender_nonce"`
Nonce int64 `gorm:"column:nonce;uniqueIndex:unique_idx_api_key_hash_policy_id_sender_nonce"`
WeiAmount int64 `gorm:"column:wei_amount"`
Status UserOperationStatus `gorm:"column:status"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
DeletedAt *time.Time `gorm:"column:deleted_at"`
// contains filtered or unexported fields
}
UserOperation represents the data structure for user operation
func NewUserOperation ¶
func NewUserOperation(db *gorm.DB) *UserOperation
NewUserOperation creates a new instance of UserOperation
func (*UserOperation) CreateOrUpdate ¶
func (u *UserOperation) CreateOrUpdate(ctx context.Context, userOp *UserOperation) error
CreateOrUpdate creates a new user operation or updates existing one with max wei_amount
func (*UserOperation) GetWalletUsage ¶
func (u *UserOperation) GetWalletUsage(ctx context.Context, apiKey string, policyID int64, sender string, timeWindowHours int) (int64, error)
GetWalletUsage calculates the ETH amount used by a specific sender within the time window for a specific policy
func (*UserOperation) TableName ¶
func (*UserOperation) TableName() string
TableName returns the database table name for UserOperation
type UserOperationStatus ¶
type UserOperationStatus int
UserOperationStatus represents the status of a user operation
const ( // UserOperationStatusPaymasterStubDataProvided is the status when pm_getPaymasterStubData is called UserOperationStatusPaymasterStubDataProvided UserOperationStatus = 1 // UserOperationStatusPaymasterDataProvided is the status when pm_getPaymasterData is called UserOperationStatusPaymasterDataProvided UserOperationStatus = 2 )