Documentation ¶
Overview ¶
Package accounting provides functionalities needed to do per-peer accounting.
Index ¶
- Variables
- type Accounting
- func (a *Accounting) Balance(peer swarm.Address) (balance *big.Int, err error)
- func (a *Accounting) Balances() (map[string]*big.Int, error)
- func (a *Accounting) Close() error
- func (a *Accounting) CompensatedBalance(peer swarm.Address) (compensated *big.Int, err error)
- func (a *Accounting) CompensatedBalances() (map[string]*big.Int, error)
- func (a *Accounting) Connect(peer swarm.Address)
- func (a *Accounting) Disconnect(peer swarm.Address)
- func (a *Accounting) Metrics() []prometheus.Collector
- func (a *Accounting) NotifyPaymentReceived(peer swarm.Address, amount *big.Int) error
- func (a *Accounting) NotifyPaymentSent(peer swarm.Address, amount *big.Int, receivedError error)
- func (a *Accounting) NotifyPaymentThreshold(peer swarm.Address, paymentThreshold *big.Int) error
- func (a *Accounting) NotifyRefreshmentReceived(peer swarm.Address, amount *big.Int) error
- func (a *Accounting) OriginatedBalance(peer swarm.Address) (balance *big.Int, err error)
- func (a *Accounting) PeerDebt(peer swarm.Address) (*big.Int, error)
- func (a *Accounting) PrepareCredit(peer swarm.Address, price uint64, originated bool) (Action, error)
- func (a *Accounting) PrepareDebit(peer swarm.Address, price uint64) (Action, error)
- func (a *Accounting) SetPayFunc(f PayFunc)
- func (a *Accounting) SetRefreshFunc(f RefreshFunc)
- func (a *Accounting) SurplusBalance(peer swarm.Address) (balance *big.Int, err error)
- type Action
- type FixedPricer
- type Interface
- type PayFunc
- type Pricer
- type RefreshFunc
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") // 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 *big.Int, PaymentTolerance, EarlyPayment int64, Logger logging.Logger, Store storage.StateStorer, Pricing pricing.Interface, refreshRate *big.Int, p2pService p2p.Service, ) (*Accounting, error)
NewAccounting creates a new Accounting instance with the provided options.
func (*Accounting) Balances ¶
func (a *Accounting) Balances() (map[string]*big.Int, error)
Balances gets balances for all peers from store.
func (*Accounting) Close ¶
func (a *Accounting) Close() error
Close hangs up running websockets on shutdown.
func (*Accounting) CompensatedBalance ¶
CompensatedBalance returns balance decreased by surplus balance
func (*Accounting) CompensatedBalances ¶
func (a *Accounting) CompensatedBalances() (map[string]*big.Int, error)
Balances gets balances for all peers from store.
func (*Accounting) Connect ¶
func (a *Accounting) Connect(peer swarm.Address)
func (*Accounting) Disconnect ¶
func (a *Accounting) Disconnect(peer swarm.Address)
func (*Accounting) Metrics ¶
func (a *Accounting) Metrics() []prometheus.Collector
Metrics returns the prometheus Collector for the accounting service.
func (*Accounting) NotifyPaymentReceived ¶
NotifyPayment is called by Settlement when we receive a payment.
func (*Accounting) NotifyPaymentSent ¶
NotifyPaymentSent is triggered by async monetary settlement to update our balance and remove it's price from the shadow reserve
func (*Accounting) NotifyPaymentThreshold ¶
NotifyPaymentThreshold should be called to notify accounting of changes in the payment threshold
func (*Accounting) NotifyRefreshmentReceived ¶
NotifyRefreshmentReceived is called by pseudosettle when we receive a time based settlement.
func (*Accounting) OriginatedBalance ¶
Balance returns the current balance for the given peer.
func (*Accounting) PeerDebt ¶
PeerDebt returns the positive part of the sum of the outstanding balance and the shadow reserve
func (*Accounting) PrepareCredit ¶
func (*Accounting) PrepareDebit ¶
PrepareDebit prepares a debit operation by increasing the shadowReservedBalance
func (*Accounting) SetPayFunc ¶
func (a *Accounting) SetPayFunc(f PayFunc)
func (*Accounting) SetRefreshFunc ¶
func (a *Accounting) SetRefreshFunc(f RefreshFunc)
func (*Accounting) SurplusBalance ¶
SurplusBalance returns the current balance for the given peer.
type Action ¶
type Action interface { // Cleanup cleans up an action. Must be called whether it was applied or not. Cleanup() // Apply applies an action Apply() error }
Action represents an accounting action that can be applied
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 { // Credit action to prevent overspending in case of concurrent requests. PrepareCredit(peer swarm.Address, price uint64, originated bool) (Action, error) // PrepareDebit returns an accounting Action for the later debit to be executed on and to implement shadowing a possibly credited part of reserve on the other side. PrepareDebit(peer swarm.Address, price uint64) (Action, error) // Balance returns the current balance for the given peer. Balance(peer swarm.Address) (*big.Int, error) // SurplusBalance returns the current surplus balance for the given peer. SurplusBalance(peer swarm.Address) (*big.Int, error) // Balances returns balances for all known peers. Balances() (map[string]*big.Int, error) // CompensatedBalance returns the current balance deducted by current surplus balance for the given peer. CompensatedBalance(peer swarm.Address) (*big.Int, error) // CompensatedBalances returns the compensated balances for all known peers. CompensatedBalances() (map[string]*big.Int, error) }
Interface is the Accounting interface.