Documentation ¶
Index ¶
- Variables
- func BatchCalculateFromCacheWithAccountRecords(ctx context.Context, data code_data.Provider, ...) (map[string]uint64, error)
- func BatchCalculateFromCacheWithTokenAccounts(ctx context.Context, data code_data.Provider, tokenAccounts ...*common.Account) (map[string]uint64, error)
- func Calculate(ctx context.Context, tokenAccount *common.Account, initialBalance uint64, ...) (balance uint64, err error)
- func CalculateBatch(ctx context.Context, tokenAccounts []string, strategies ...BatchStrategy) (balanceByTokenAccount map[string]uint64, err error)
- func CalculateFromCache(ctx context.Context, data code_data.Provider, tokenAccount *common.Account) (uint64, error)
- func GetPrivateBalance(ctx context.Context, data code_data.Provider, owner *common.Account) (uint64, error)
- type BatchCalculator
- type BatchState
- type BatchStrategy
- type Calculator
- type Source
- type State
- type Strategy
- func FundingFromExternalDeposits(ctx context.Context, data code_data.Provider) Strategy
- func FundingFromExternalDepositsForPrePrivacy2022Accounts(ctx context.Context, data code_data.Provider) Strategy
- func NetBalanceFromIntentActions(ctx context.Context, data code_data.Provider) Strategy
- func NetBalanceFromPrePrivacy2022Intents(ctx context.Context, data code_data.Provider) Strategy
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNegativeBalance indicates that a balance calculation resulted in a // negative value. ErrNegativeBalance = errors.New("balance calculation resulted in negative value") // ErrNotManagedByCode indicates that an account is not owned by Code. // It's up to callers to determine how to handle this situation within // the context of a balance. ErrNotManagedByCode = errors.New("explicitly not handling account not managed by code") // ErrUnhandledAccount indicates that the balance calculator does not // have strategies to handle the provided account. ErrUnhandledAccount = errors.New("unhandled account") )
Functions ¶
func BatchCalculateFromCacheWithAccountRecords ¶ added in v1.3.0
func BatchCalculateFromCacheWithAccountRecords(ctx context.Context, data code_data.Provider, accountRecordsBatch ...*common.AccountRecords) (map[string]uint64, error)
BatchCalculateFromCacheWithAccountRecords is the default and recommended batch strategy or reliably estimating a set of token accounts' balance when common.AccountRecords are available.
Note: Use this method when calculating balances for accounts that are managed by Code (ie. Timelock account) and operate within the L2 system.
Note: This only supports post-privacy accounts. Use CalculateFromCache instead.
func BatchCalculateFromCacheWithTokenAccounts ¶ added in v1.3.0
func BatchCalculateFromCacheWithTokenAccounts(ctx context.Context, data code_data.Provider, tokenAccounts ...*common.Account) (map[string]uint64, error)
BatchCalculateFromCacheWithTokenAccounts is the default and recommended batch strategy or reliably estimating a set of token accounts' balance when common.Account are available.
Note: Use this method when calculating balances for accounts that are managed by Code (ie. Timelock account) and operate within the L2 system.
Note: This only supports post-privacy accounts. Use CalculateFromCache instead.
func Calculate ¶
func Calculate(ctx context.Context, tokenAccount *common.Account, initialBalance uint64, strategies ...Strategy) (balance uint64, err error)
Calculate calculates a token account's balance using a starting point and a set of strategies. Each may be incomplete individually, but in total must form a complete balance calculation.
func CalculateBatch ¶
func CalculateBatch(ctx context.Context, tokenAccounts []string, strategies ...BatchStrategy) (balanceByTokenAccount map[string]uint64, err error)
CalculateBatch calculates a set of token accounts' balance using a starting point and a set of strategies. Each may be incomplete individually, but in total must form a complete balance calculation.
func CalculateFromCache ¶ added in v1.3.0
func CalculateFromCache(ctx context.Context, data code_data.Provider, tokenAccount *common.Account) (uint64, error)
CalculateFromCache is the default and recommended strategy for reliably estimating a token account's balance using cached values.
Note: Use this method when calculating balances for accounts that are managed by Code (ie. Timelock account) and operate within the L2 system.
Types ¶
type BatchCalculator ¶
type BatchCalculator func(ctx context.Context, data code_data.Provider, accountRecordsBatch []*common.AccountRecords) (map[string]uint64, error)
BatchCalculator is a functiona that calculates a batch of accounts' balances
type BatchState ¶
type BatchState struct {
// contains filtered or unexported fields
}
type BatchStrategy ¶
type BatchStrategy func(ctx context.Context, tokenAccounts []string, state *BatchState) (*BatchState, error)
func FundingFromExternalDepositsBatch ¶
func FundingFromExternalDepositsBatch(ctx context.Context, data code_data.Provider) BatchStrategy
FundingFromExternalDepositsBatch is a balance calculation strategy that adds funding from deposits from external accounts.
func NetBalanceFromIntentActionsBatch ¶
func NetBalanceFromIntentActionsBatch(ctx context.Context, data code_data.Provider) BatchStrategy
NetBalanceFromIntentActionsBatch is a balance calculation strategy that incorporates the net balance by applying payment intents to the current balance.
type Calculator ¶
type Calculator func(ctx context.Context, data code_data.Provider, tokenAccount *common.Account) (uint64, error)
Calculator is a function that calculates a token account's balance
type Source ¶ added in v1.3.2
type Source uint8
func CalculateFromBlockchain ¶ added in v1.3.0
func CalculateFromBlockchain(ctx context.Context, data code_data.Provider, tokenAccount *common.Account) (uint64, Source, error)
CalculateFromBlockchain is the default and recommended strategy for reliably estimating a token account's balance from the blockchain. This strategy is resistant to various RPC failure nodes, and may return a cached value. The source of the balance calculation is returned.
Note: Use this method when calculating token account balances that are external and not managed by Code and outside the L2 system.
todo: add a batching variant
type Strategy ¶
func FundingFromExternalDeposits ¶
FundingFromExternalDeposits is a balance calculation strategy that adds funding from deposits from external accounts.
func NetBalanceFromIntentActions ¶
NetBalanceFromIntentActions is a balance calculation strategy that incorporates the net balance by applying payment intents to the current balance.