Documentation ¶
Index ¶
- Variables
- type Accounting
- func (a *Accounting) AsyncNotifyPayment(peer swarm.Address, amount uint64) error
- func (a *Accounting) Balance(peer swarm.Address) (balance int64, err error)
- func (a *Accounting) Balances() (map[string]int64, error)
- func (a *Accounting) CompensatedBalance(peer swarm.Address) (compensated int64, err error)
- func (a *Accounting) CompensatedBalances() (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) NotifyPaymentThreshold(peer swarm.Address, paymentThreshold uint64) error
- func (a *Accounting) Release(peer swarm.Address, price uint64)
- func (a *Accounting) Reserve(ctx context.Context, peer swarm.Address, price uint64) error
- func (a *Accounting) SurplusBalance(peer swarm.Address) (balance int64, err error)
- type FixedPricer
- type Interface
- type Pricer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOverdraft denotes the expected debt in Reserve would exceed the payment thresholds. ErrOverdraft = errors.New("attempted overdraft") // ErrDisconnectThresholdExceeded denotes a peer has exceeded the disconnect threshold. ErrDisconnectThresholdExceeded = errors.New("disconnect threshold exceeded") // ErrPeerNoBalance is the error returned if no balance in store exists for a peer ErrPeerNoBalance = errors.New("no balance for peer") // ErrOverflow denotes an arithmetic operation overflowed. ErrOverflow = errors.New("overflow error") // ErrInvalidValue denotes an invalid value read from store ErrInvalidValue = errors.New("invalid value") )
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( PaymentThreshold, PaymentTolerance, EarlyPayment uint64, Logger logging.Logger, Store storage.StateStorer, Settlement settlement.Interface, Pricing pricing.Interface, ) (*Accounting, error)
NewAccounting creates a new Accounting instance with the provided options.
func (*Accounting) AsyncNotifyPayment ¶ added in v0.4.0
func (a *Accounting) AsyncNotifyPayment(peer swarm.Address, amount uint64) error
AsyncNotifyPayment calls notify payment in a go routine. This is needed when accounting needs to be notified but the accounting lock is already held.
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) CompensatedBalance ¶ added in v0.4.0
func (a *Accounting) CompensatedBalance(peer swarm.Address) (compensated int64, err error)
CompensatedBalance returns balance decreased by surplus balance
func (*Accounting) CompensatedBalances ¶ added in v0.4.0
func (a *Accounting) CompensatedBalances() (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
Metrics returns the prometheus Collector for the accounting service.
func (*Accounting) NotifyPayment ¶
func (a *Accounting) NotifyPayment(peer swarm.Address, amount uint64) error
NotifyPayment is called by Settlement when we receive a payment.
func (*Accounting) NotifyPaymentThreshold ¶ added in v0.3.0
func (a *Accounting) NotifyPaymentThreshold(peer swarm.Address, paymentThreshold uint64) error
NotifyPaymentThreshold should be called to notify accounting of changes in the payment threshold
func (*Accounting) Release ¶
func (a *Accounting) Release(peer swarm.Address, price uint64)
Release releases reserved funds.
func (*Accounting) Reserve ¶
Reserve reserves a portion of the balance for peer and attempts settlements if necessary.
func (*Accounting) SurplusBalance ¶ added in v0.4.0
func (a *Accounting) SurplusBalance(peer swarm.Address) (balance int64, err error)
SurplusBalance returns the current balance for the given peer.
type FixedPricer ¶
type FixedPricer struct {
// contains filtered or unexported fields
}
FixedPricer is a Pricer that has a fixed price for chunks.
func NewFixedPricer ¶
func NewFixedPricer(overlay swarm.Address, poPrice uint64) *FixedPricer
NewFixedPricer returns a new FixedPricer with a given price.
type Interface ¶
type Interface interface { // Reserve reserves a portion of the balance for peer and attempts settlements if necessary. // Returns an error if the operation risks exceeding the disconnect threshold or an attempted settlement failed. // // This has to be called (always in combination with Release) before a // Credit action to prevent overspending in case of concurrent requests. Reserve(ctx context.Context, peer swarm.Address, price uint64) error // Release releases the 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" back). Debit(peer swarm.Address, price uint64) error // Balance returns the current balance for the given peer. Balance(peer swarm.Address) (int64, error) // SurplusBalance returns the current surplus balance for the given peer. SurplusBalance(peer swarm.Address) (int64, error) // Balances returns balances for all known peers. Balances() (map[string]int64, error) // CompensatedBalance returns the current balance deducted by current surplus balance for the given peer. CompensatedBalance(peer swarm.Address) (int64, error) // CompensatedBalances returns the compensated balances for all known peers. CompensatedBalances() (map[string]int64, error) }
Interface is the Accounting interface.