Documentation ¶
Index ¶
- Variables
- type AccountManager
- func (am *AccountManager) Balance(accountID rhpv3.Account) (types.Currency, error)
- func (am *AccountManager) Budget(accountID rhpv3.Account, amount types.Currency) (*Budget, error)
- func (am *AccountManager) Credit(accountID rhpv3.Account, amount types.Currency, expiration time.Time, ...) (types.Currency, error)
- type AccountStore
- type Budget
- type Settings
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInsufficientFunds is returned when an account does not have enough // funds to cover a debit. ErrInsufficientFunds = errors.New("ephemeral account balance was insufficient") // note: text is required for compatibility with siad // ErrBalanceExceeded is returned when an account's balance exceeds the // maximum balance. ErrBalanceExceeded = errors.New("ephemeral account maximum balance exceeded") // note: text is required for compatibility with siad )
Functions ¶
This section is empty.
Types ¶
type AccountManager ¶
type AccountManager struct {
// contains filtered or unexported fields
}
An AccountManager manages deposits and withdrawals for accounts. It is primarily a synchronization wrapper around a store.
func NewManager ¶
func NewManager(store AccountStore, settings Settings) *AccountManager
NewManager creates a new account manager
type AccountStore ¶
type AccountStore interface { // AccountBalance returns the balance of the account with the given ID. AccountBalance(accountID rhpv3.Account) (types.Currency, error) // CreditAccount adds the specified amount to the account with the given ID. CreditAccount(accountID rhpv3.Account, amount types.Currency, expiration time.Time) (types.Currency, error) // DebitAccount subtracts the specified amount from the account with the given // ID. Returns the remaining balance of the account. DebitAccount(accountID rhpv3.Account, amount types.Currency) (types.Currency, error) }
An AccountStore stores and updates account balances.
type Budget ¶
type Budget struct {
// contains filtered or unexported fields
}
A Budget transactionally manages an account's balance. It is not safe for concurrent use.
func (*Budget) Commit ¶
Commit commits the budget's spending to the account. If the budget has already been committed, Commit will panic.
func (*Budget) Refund ¶
Refund returns amount back to the budget. Refund will panic if the budget has already been committed or the refund is greater than the amount spent.
Click to show internal directories.
Click to hide internal directories.