ledger

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package ledger implements the ledger for payer balances.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAmount      = errors.New("amount must be greater than 0")
	ErrInvalidEventID     = errors.New("event ID must be greater than 0")
	ErrWithdrawalNotFound = errors.New(
		"trying to cancel a withdrawal that has not been stored",
	)
	ErrWithdrawalAlreadyCanceled = errors.New("withdrawal already canceled")
)

Functions

This section is empty.

Types

type EventID

type EventID [32]byte

func BuildEventID

func BuildEventID(log types.Log) EventID

BuildEventID builds an EventID for an event in the context of a specific block In the case of reorgs, we want to reverse the original event and then if the transaction is included a new block, add that event to the ledger with a new event ID.

func (EventID) String

func (e EventID) String() string

type EventType

type EventType int16

type ILedger

type ILedger interface {
	// Register a deposit event to a payer's balance
	Deposit(
		ctx context.Context,
		payerID int32,
		amount currency.PicoDollar,
		eventID EventID,
	) error
	// Register a withdrawal event, which immediately reduces the payer's balance
	InitiateWithdrawal(
		ctx context.Context,
		payerID int32,
		amount currency.PicoDollar,
		eventID EventID,
	) error
	// Cancel a previous withdrawal
	CancelWithdrawal(ctx context.Context, payerID int32, eventID EventID) error
	// Decrement a payer's balance when usage is settled
	SettleUsage(
		ctx context.Context,
		payerID int32,
		amount currency.PicoDollar,
		eventID EventID,
	) error
	// Get the balance for a payer from the settled usage ledger
	GetBalance(ctx context.Context, payerID int32) (currency.PicoDollar, error)
	FindOrCreatePayer(ctx context.Context, payerAddress common.Address) (int32, error)
}

ILedger interface handles settled balances from the blockchain.

type Ledger

type Ledger struct {
	// contains filtered or unexported fields
}

func NewLedger

func NewLedger(logger *zap.Logger, querier *queries.Queries) *Ledger

func (*Ledger) CancelWithdrawal

func (l *Ledger) CancelWithdrawal(ctx context.Context, payerID int32, eventID EventID) error

func (*Ledger) Deposit

func (l *Ledger) Deposit(
	ctx context.Context,
	payerID int32,
	amount currency.PicoDollar,
	eventID EventID,
) error

func (*Ledger) FindOrCreatePayer

func (l *Ledger) FindOrCreatePayer(
	ctx context.Context,
	payerAddress common.Address,
) (int32, error)

func (*Ledger) GetBalance

func (l *Ledger) GetBalance(ctx context.Context, payerID int32) (currency.PicoDollar, error)

func (*Ledger) InitiateWithdrawal

func (l *Ledger) InitiateWithdrawal(
	ctx context.Context,
	payerID int32,
	amount currency.PicoDollar,
	eventID EventID,
) error

func (*Ledger) SettleUsage

func (l *Ledger) SettleUsage(
	ctx context.Context,
	payerID int32,
	amount currency.PicoDollar,
	eventID EventID,
) error

Jump to

Keyboard shortcuts

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