orm

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 6 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 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 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"`
	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
)

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