Documentation
¶
Index ¶
- Variables
- func ContainsAccountCurrency(arr []*AccountCurrency, change *AccountCurrency) bool
- func ExtractAmount(balances []*types.Amount, currency *types.Currency) (*types.Amount, error)
- func GetCurrencyBalance(ctx context.Context, fetcher *fetcher.Fetcher, ...) (*types.BlockIdentifier, string, error)
- type AccountCurrency
- type Reconciler
- type StatefulReconciler
- type StatelessReconciler
Constants ¶
This section is empty.
Variables ¶
var ( // ErrHeadBlockBehindLive is returned when the processed // head is behind the live head. Sometimes, it is // preferrable to sleep and wait to catch up when // we are close to the live head (waitToCheckDiff). ErrHeadBlockBehindLive = errors.New("head block behind") // ErrAccountUpdated is returned when the // account was updated at a height later than // the live height (when the account balance was fetched). ErrAccountUpdated = errors.New("account updated") // ErrBlockGone is returned when the processed block // head is greater than the live head but the block // does not exist in the store. This likely means // that the block was orphaned. ErrBlockGone = errors.New("block gone") )
Functions ¶
func ContainsAccountCurrency ¶
func ContainsAccountCurrency( arr []*AccountCurrency, change *AccountCurrency, ) bool
ContainsAccountCurrency returns a boolean indicating if a AccountCurrency slice already contains an Account and Currency combination.
func ExtractAmount ¶
ExtractAmount returns the types.Amount from a slice of types.Balance pertaining to an AccountAndCurrency.
func GetCurrencyBalance ¶
func GetCurrencyBalance( ctx context.Context, fetcher *fetcher.Fetcher, network *types.NetworkIdentifier, account *types.AccountIdentifier, currency *types.Currency, block *types.PartialBlockIdentifier, ) (*types.BlockIdentifier, string, error)
GetCurrencyBalance fetches the balance of a *types.AccountIdentifier for a particular *types.Currency.
Types ¶
type AccountCurrency ¶
type AccountCurrency struct {
Account *types.AccountIdentifier `json:"account_identifier,omitempty"`
Currency *types.Currency `json:"currency,omitempty"`
}
AccountCurrency is a simple struct combining a *types.Account and *types.Currency. This can be useful for looking up balances.
type Reconciler ¶
type Reconciler interface {
QueueChanges(
ctx context.Context,
block *types.BlockIdentifier,
changes []*storage.BalanceChange,
) error
Reconcile(ctx context.Context) error
}
Reconciler defines an interface for comparing computed balances with node balances.
type StatefulReconciler ¶
type StatefulReconciler struct {
// contains filtered or unexported fields
}
StatefulReconciler contains all logic to reconcile balances of types.AccountIdentifiers returned in types.Operations by a Rosetta Server.
func NewStateful ¶
func NewStateful( network *types.NetworkIdentifier, blockStorage *storage.BlockStorage, fetcher *fetcher.Fetcher, logger *logger.Logger, accountConcurrency uint64, lookupBalanceByBlock bool, haltOnReconciliationError bool, ) *StatefulReconciler
NewStateful creates a new StatefulReconciler.
func (*StatefulReconciler) CompareBalance ¶
func (r *StatefulReconciler) CompareBalance( ctx context.Context, account *types.AccountIdentifier, currency *types.Currency, amount string, liveBlock *types.BlockIdentifier, ) (string, int64, error)
CompareBalance checks to see if the computed balance of an account is equal to the live balance of an account. This function ensures balance is checked correctly in the case of orphaned blocks.
func (*StatefulReconciler) QueueChanges ¶
func (r *StatefulReconciler) QueueChanges( ctx context.Context, block *types.BlockIdentifier, balanceChanges []*storage.BalanceChange, ) error
QueueChanges enqueues a slice of *storage.BalanceChanges for reconciliation.
type StatelessReconciler ¶
type StatelessReconciler struct {
// contains filtered or unexported fields
}
StatelessReconciler compares computed balances with the node balance without using any sort of persistent state. If it is not possible to lookup a balance by block, you must use the StatefulReconciler. If you want to perform inactive reconciliation (check for balance changes that occurred that were not in blocks), you must also use the StatefulReconciler. Lastly, the StatelessReconciler does not support re-orgs.
func NewStateless ¶
func NewStateless( network *types.NetworkIdentifier, fetcher *fetcher.Fetcher, logger *logger.Logger, accountConcurrency uint64, haltOnReconciliationError bool, interestingAccounts []*AccountCurrency, ) *StatelessReconciler
NewStateless returns a new StatelessReconciler.
func (*StatelessReconciler) QueueChanges ¶
func (r *StatelessReconciler) QueueChanges( ctx context.Context, block *types.BlockIdentifier, balanceChanges []*storage.BalanceChange, ) error
QueueChanges enqueues a slice of *storage.BalanceChanges for reconciliation.