Documentation
¶
Index ¶
- Variables
- type Account
- type AccountManager
- func (am *AccountManager) AccountFunding(account rhp3.Account) (srcs []FundingSource, err error)
- func (am *AccountManager) Accounts(limit, offset int) (acc []Account, err error)
- func (am *AccountManager) Balance(accountID rhp3.Account) (types.Currency, error)
- func (am *AccountManager) Budget(accountID rhp3.Account, amount types.Currency) (*Budget, error)
- func (am *AccountManager) Credit(req FundAccountWithContract, refund bool) (types.Currency, error)
- type AccountStore
- type Budget
- type FundAccountWithContract
- type FundingSource
- type Settings
- type Usage
Constants ¶
This section is empty.
Variables ¶
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 Account ¶ added in v0.2.0
type Account struct {
ID rhp3.Account `json:"id"`
Balance types.Currency `json:"balance"`
Expiration time.Time `json:"expiration"`
}
An Account holds the balance and expiration of an ephemeral account.
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
func (*AccountManager) AccountFunding ¶ added in v0.2.0
func (am *AccountManager) AccountFunding(account rhp3.Account) (srcs []FundingSource, err error)
AccountFunding returns the remaining funding sources for an account.
func (*AccountManager) Accounts ¶ added in v0.2.0
func (am *AccountManager) Accounts(limit, offset int) (acc []Account, err error)
Accounts returns a list of active ephemeral accounts
func (*AccountManager) Budget ¶
Budget creates a new budget for an account limited by amount. The spent amount will not be synced to the underlying store until Commit is called.
func (*AccountManager) Credit ¶
func (am *AccountManager) Credit(req FundAccountWithContract, refund bool) (types.Currency, error)
Credit adds the specified amount to the account with the given ID. Credits are synced to the underlying store immediately.
type AccountStore ¶
type AccountStore interface {
// AccountFunding returns the remaining funding sources for an account.
AccountFunding(accountID rhp3.Account) ([]FundingSource, error)
// Accounts returns a list of active ephemeral accounts
Accounts(limit, offset int) ([]Account, error)
// AccountBalance returns the balance of the account with the given ID.
AccountBalance(accountID rhp3.Account) (types.Currency, error)
// CreditAccountWithContract adds the specified amount to the account with the given ID.
CreditAccountWithContract(FundAccountWithContract) (types.Currency, error)
// DebitAccount subtracts the specified amount from the account with the given
// ID. Returns the remaining balance of the account.
DebitAccount(accountID rhp3.Account, usage Usage) (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.
type FundAccountWithContract ¶ added in v0.2.0
type FundAccountWithContract struct {
Account rhp3.Account
Cost types.Currency
Amount types.Currency
Revision contracts.SignedRevision
Expiration time.Time
}
FundAccountWithContract is a helper struct for funding an account with a contract.
type FundingSource ¶ added in v0.2.0
type FundingSource struct {
ContractID types.FileContractID `json:"contractID"`
AccountID rhp3.Account `json:"accountID"`
Amount types.Currency `json:"amount"`
}
FundingSource tracks a funding source for an account.
type Usage ¶ added in v0.2.0
type Usage struct {
RPCRevenue types.Currency `json:"rpc"`
StorageRevenue types.Currency `json:"storage"`
EgressRevenue types.Currency `json:"egress"`
IngressRevenue types.Currency `json:"ingress"`
RegistryRead types.Currency `json:"registryRead"`
RegistryWrite types.Currency `json:"registryWrite"`
}
Usage tracks the usage of an account's funds.