Documentation ¶
Index ¶
- Variables
- type Accounting
- func (a *Accounting) Balance(peer swarm.Address) (balance int64, err error)
- func (a *Accounting) Balances() (map[string]int64, error)
- func (a *Accounting) Credit(peer swarm.Address, price uint64) error
- func (a *Accounting) Debit(peer swarm.Address, price uint64) error
- func (a *Accounting) Metrics() []prometheus.Collector
- func (a *Accounting) NotifyPayment(peer swarm.Address, amount uint64) error
- func (a *Accounting) Release(peer swarm.Address, price uint64)
- func (a *Accounting) Reserve(peer swarm.Address, price uint64) error
- type FixedPricer
- type Interface
- type Options
- type Pricer
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrOverdraft is the error returned if the expected debt in Reserve would exceed the payment thresholds ErrOverdraft = errors.New("attempted overdraft") // ErrDisconnectThresholdExceeded is the error returned if a peer has exceeded the disconnect threshold ErrDisconnectThresholdExceeded = errors.New("disconnect threshold exceeded") // ErrInvalidPaymentTolerance is the error returned if the payment tolerance is too high compared to the payment threshold ErrInvalidPaymentTolerance = errors.New("payment tolerance must be less than half the payment threshold") )
Functions ¶
This section is empty.
Types ¶
type Accounting ¶
type Accounting struct {
// contains filtered or unexported fields
}
Accounting is the main implementation of the accounting interface
func NewAccounting ¶
func NewAccounting(o Options) (*Accounting, error)
NewAccounting creates a new Accounting instance with the provided options
func (*Accounting) Balance ¶
func (a *Accounting) Balance(peer swarm.Address) (balance int64, err error)
Balance returns the current balance for the given peer
func (*Accounting) Balances ¶
func (a *Accounting) Balances() (map[string]int64, error)
Balances gets balances for all peers from store
func (*Accounting) Credit ¶
func (a *Accounting) Credit(peer swarm.Address, price uint64) error
Credit increases the amount of credit we have with the given peer (and decreases existing debt).
func (*Accounting) Debit ¶
func (a *Accounting) Debit(peer swarm.Address, price uint64) error
Debit increases the amount of debt we have with the given peer (and decreases existing credit)
func (*Accounting) Metrics ¶
func (a *Accounting) Metrics() []prometheus.Collector
func (*Accounting) NotifyPayment ¶
func (a *Accounting) NotifyPayment(peer swarm.Address, amount uint64) error
NotifyPayment is called by Settlement when we received payment Implements the PaymentObserver interface
type FixedPricer ¶
type FixedPricer struct {
// contains filtered or unexported fields
}
func NewFixedPricer ¶
func NewFixedPricer(overlay swarm.Address, poPrice uint64) *FixedPricer
type Interface ¶
type Interface interface { // Reserve reserves a portion of the balance for peer // It returns an error if the operation would risk exceeding the disconnect threshold // This should be called (always in combination with Release) before a Credit action to prevent overspending in case of concurrent requests Reserve(peer swarm.Address, price uint64) error // Release releases reserved funds Release(peer swarm.Address, price uint64) // Credit increases the balance the peer has with us (we "pay" the peer) Credit(peer swarm.Address, price uint64) error // Debit increases the balance we have with the peer (we get "paid") Debit(peer swarm.Address, price uint64) error // Balance returns the current balance for the given peer Balance(peer swarm.Address) (int64, error) // Balances returns balances for all known peers Balances() (map[string]int64, error) }
Interface is the main interface for Accounting
type Options ¶
type Options struct { PaymentThreshold uint64 PaymentTolerance uint64 Logger logging.Logger Store storage.StateStorer Settlement settlement.Interface }
Options for accounting
Click to show internal directories.
Click to hide internal directories.