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
- func (u *UserOperation) CreateOrUpdate(ctx context.Context, userOp *UserOperation) error
- func (u *UserOperation) GetWalletUsageStats(ctx context.Context, apiKey string, policyID int64, sender string, ...) (*WalletUsageStats, error)
- func (u *UserOperation) GetWalletUsageStatsExcludingSameSenderAndNonce(ctx context.Context, apiKey string, policyID int64, sender string, ...) (*WalletUsageStats, error)
- func (*UserOperation) TableName() string
- type UserOperationStatus
- type WalletUsageStats
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 string `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"`
MaxTransactionsPerWalletPerWindow int64 `json:"max_transactions_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 string `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) GetWalletUsageStats ¶ added in v0.0.10
func (u *UserOperation) GetWalletUsageStats(ctx context.Context, apiKey string, policyID int64, sender string, timeWindowHours int) (*WalletUsageStats, error)
GetWalletUsageStats gets both transaction count and total wei amount in a single query
func (*UserOperation) GetWalletUsageStatsExcludingSameSenderAndNonce ¶ added in v0.0.10
func (u *UserOperation) GetWalletUsageStatsExcludingSameSenderAndNonce(ctx context.Context, apiKey string, policyID int64, sender string, nonce *big.Int, timeWindowHours int) (*WalletUsageStats, error)
GetWalletUsageStatsExcludingSameSenderAndNonce gets both transaction count and total wei amount in a single query Excludes records with the same sender and nonce combination
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 )
type WalletUsageStats ¶ added in v0.0.10
type WalletUsageStats struct {
TransactionCount int64 `json:"transaction_count" gorm:"column:count"`
TotalWeiAmount int64 `json:"total_wei_amount" gorm:"column:total_wei_amount"`
EarliestTransactionTime *time.Time `json:"earliest_transaction_time,omitempty" gorm:"column:earliest_transaction_time"`
}
WalletUsageStats represents the usage statistics for a wallet