orm

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 8 Imported by: 0

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

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 NewPolicy

func NewPolicy(db *gorm.DB) *Policy

NewPolicy creates a new instance of Policy

func (*Policy) Create

func (p *Policy) Create(ctx context.Context, policy *Policy) error

Create creates a new policy record

func (*Policy) Delete

func (p *Policy) Delete(ctx context.Context, apiKey string, policyID int64) error

Delete soft deletes a policy record

func (*Policy) GetByAPIKey

func (p *Policy) GetByAPIKey(ctx context.Context, apiKey string) ([]*Policy, error)

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

func (*Policy) TableName

func (*Policy) TableName() string

TableName returns the database table name for Policy

func (*Policy) Update

func (p *Policy) Update(ctx context.Context, apiKey string, policyID int64, updates map[string]interface{}) error

Update updates a policy record

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

Directories

Path Synopsis
Package migrate provides database migration functionality for the Scroll paymaster service.
Package migrate provides database migration functionality for the Scroll paymaster service.

Jump to

Keyboard shortcuts

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