balance

package
v1.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 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)

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 DefaultBatchCalculationWithAccountRecords

func DefaultBatchCalculationWithAccountRecords(ctx context.Context, data code_data.Provider, accountRecordsBatch ...*common.AccountRecords) (map[string]uint64, error)

DefaultBatchCalculationWithAccountRecords is the default and recommended batch strategy or reliably estimating a set of token accounts' balance when common.AccountRecords are available.

Note: This only supports post-privacy accounts. Use DefaultCalculation instead.

func DefaultBatchCalculationWithTokenAccounts

func DefaultBatchCalculationWithTokenAccounts(ctx context.Context, data code_data.Provider, tokenAccounts ...*common.Account) (map[string]uint64, error)

DefaultBatchCalculationWithTokenAccounts is the default and recommended batch strategy or reliably estimating a set of token accounts' balance when common.Account are available.

Note: This only supports post-privacy accounts. Use DefaultCalculation instead.

func DefaultCalculation

func DefaultCalculation(ctx context.Context, data code_data.Provider, tokenAccount *common.Account) (uint64, error)

DefaultCalculation is the default and recommended strategy for reliably estimating a token account's balance.

func GetPrivateBalance

func GetPrivateBalance(ctx context.Context, data code_data.Provider, owner *common.Account) (uint64, error)

GetPrivateBalance gets an owner account's total private balance (ie. everything except the primary account).

todo: consolidate common logic with GetTotalBalance

func GetTotalBalance

func GetTotalBalance(ctx context.Context, data code_data.Provider, owner *common.Account) (uint64, error)

GetTotalBalance gets an owner account's total balance

todo: consolidate common logic with GetPrivateBalance

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 State

type State struct {
	// contains filtered or unexported fields
}

type Strategy

type Strategy func(ctx context.Context, tokenAccount *common.Account, state *State) (*State, error)

func FundingFromExternalDeposits

func FundingFromExternalDeposits(ctx context.Context, data code_data.Provider) Strategy

FundingFromExternalDeposits is a balance calculation strategy that adds funding from deposits from external accounts.

func FundingFromExternalDepositsForPrePrivacy2022Accounts

func FundingFromExternalDepositsForPrePrivacy2022Accounts(ctx context.Context, data code_data.Provider) Strategy

func NetBalanceFromIntentActions

func NetBalanceFromIntentActions(ctx context.Context, data code_data.Provider) Strategy

NetBalanceFromIntentActions is a balance calculation strategy that incorporates the net balance by applying payment intents to the current balance.

func NetBalanceFromPrePrivacy2022Intents

func NetBalanceFromPrePrivacy2022Intents(ctx context.Context, data code_data.Provider) Strategy

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL