Documentation
¶
Overview ¶
Package ledger implements the ledger for payer balances.
Index ¶
- Variables
- type EventID
- type EventType
- type ILedger
- type Ledger
- func (l *Ledger) CancelWithdrawal(ctx context.Context, payerID int32, eventID EventID) error
- func (l *Ledger) Deposit(ctx context.Context, payerID int32, amount currency.PicoDollar, ...) error
- func (l *Ledger) FindOrCreatePayer(ctx context.Context, payerAddress common.Address) (int32, error)
- func (l *Ledger) GetBalance(ctx context.Context, payerID int32) (currency.PicoDollar, error)
- func (l *Ledger) InitiateWithdrawal(ctx context.Context, payerID int32, amount currency.PicoDollar, ...) error
- func (l *Ledger) SettleUsage(ctx context.Context, payerID int32, amount currency.PicoDollar, ...) error
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 ¶
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.
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 (*Ledger) CancelWithdrawal ¶
func (*Ledger) FindOrCreatePayer ¶
func (*Ledger) GetBalance ¶
func (*Ledger) InitiateWithdrawal ¶
func (*Ledger) SettleUsage ¶
Click to show internal directories.
Click to hide internal directories.