processor

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BalanceStorageHandler

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

BalanceStorageHandler is invoked whenever a block is added or removed from block storage so that balance changes can be sent to other functions (ex: reconciler).

func NewBalanceStorageHandler

func NewBalanceStorageHandler(
	logger *logger.Logger,
	reconciler *reconciler.Reconciler,
	reconcile bool,
	interestingAccount *reconciler.AccountCurrency,
) *BalanceStorageHandler

NewBalanceStorageHandler returns a new *BalanceStorageHandler.

func (*BalanceStorageHandler) BlockAdded

func (h *BalanceStorageHandler) BlockAdded(
	ctx context.Context,
	block *types.Block,
	changes []*parser.BalanceChange,
) error

BlockAdded is called whenever a block is committed to BlockStorage.

func (*BalanceStorageHandler) BlockRemoved

func (h *BalanceStorageHandler) BlockRemoved(
	ctx context.Context,
	block *types.Block,
	changes []*parser.BalanceChange,
) error

BlockRemoved is called whenever a block is removed from BlockStorage.

type BalanceStorageHelper

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

BalanceStorageHelper implements the storage.Helper interface.

func NewBalanceStorageHelper

func NewBalanceStorageHelper(
	network *types.NetworkIdentifier,
	fetcher *fetcher.Fetcher,
	lookupBalanceByBlock bool,
	exemptAccounts []*reconciler.AccountCurrency,
	interestingOnly bool,
) *BalanceStorageHelper

NewBalanceStorageHelper returns a new BalanceStorageHelper.

func (*BalanceStorageHelper) AccountBalance

func (h *BalanceStorageHelper) AccountBalance(
	ctx context.Context,
	account *types.AccountIdentifier,
	currency *types.Currency,
	block *types.BlockIdentifier,
) (*types.Amount, error)

AccountBalance attempts to fetch the balance for a missing account in storage. This is necessary for running the "check" command at an arbitrary height instead of syncing from genesis.

func (*BalanceStorageHelper) AddInterestingAddress

func (h *BalanceStorageHelper) AddInterestingAddress(address string)

AddInterestingAddress adds an address to track the balance of. This is often done after generating an account.

func (*BalanceStorageHelper) Asserter

func (h *BalanceStorageHelper) Asserter() *asserter.Asserter

Asserter returns a *asserter.Asserter.

func (*BalanceStorageHelper) ExemptFunc

ExemptFunc returns a parser.ExemptOperation.

type BroadcastStorageHandler

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

BroadcastStorageHandler is invoked whenever a block is added or removed from block storage so that balance changes can be sent to other functions (ex: reconciler).

func NewBroadcastStorageHandler

func NewBroadcastStorageHandler(
	config *configuration.Configuration,
	counterStorage *storage.CounterStorage,
	parser *parser.Parser,
) *BroadcastStorageHandler

NewBroadcastStorageHandler returns a new *BroadcastStorageHandler.

func (*BroadcastStorageHandler) BroadcastFailed

func (h *BroadcastStorageHandler) BroadcastFailed(
	ctx context.Context,
	transactionIdentifier *types.TransactionIdentifier,
	intent []*types.Operation,
) error

BroadcastFailed is called when another transaction broadcast would put it over the provided broadcast limit.

func (*BroadcastStorageHandler) TransactionConfirmed

func (h *BroadcastStorageHandler) TransactionConfirmed(
	ctx context.Context,
	blockIdentifier *types.BlockIdentifier,
	transaction *types.Transaction,
	intent []*types.Operation,
) error

TransactionConfirmed is called when a transaction is observed on-chain for the last time at a block height < current block height - confirmationDepth.

func (*BroadcastStorageHandler) TransactionStale

func (h *BroadcastStorageHandler) TransactionStale(
	ctx context.Context,
	transactionIdentifier *types.TransactionIdentifier,
) error

TransactionStale is called when a transaction has not yet been seen on-chain and is considered stale. This occurs when current block height - last broadcast > staleDepth.

type BroadcastStorageHelper

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

BroadcastStorageHelper implements the storage.Helper interface.

func NewBroadcastStorageHelper

func NewBroadcastStorageHelper(
	network *types.NetworkIdentifier,
	blockStorage *storage.BlockStorage,
	fetcher *fetcher.Fetcher,
) *BroadcastStorageHelper

NewBroadcastStorageHelper returns a new BroadcastStorageHelper.

func (*BroadcastStorageHelper) AtTip

func (h *BroadcastStorageHelper) AtTip(
	ctx context.Context,
	tipDelay int64,
) (bool, error)

AtTip is called before transaction broadcast to determine if we are at tip.

func (*BroadcastStorageHelper) BroadcastTransaction

func (h *BroadcastStorageHelper) BroadcastTransaction(
	ctx context.Context,
	networkTransaction string,
) (*types.TransactionIdentifier, error)

BroadcastTransaction broadcasts a transaction to a Rosetta implementation and returns the *types.TransactionIdentifier returned by the implementation.

func (*BroadcastStorageHelper) CurrentBlockIdentifier

func (h *BroadcastStorageHelper) CurrentBlockIdentifier(
	ctx context.Context,
) (*types.BlockIdentifier, error)

CurrentBlockIdentifier is called before transaction broadcast and is used to determine if a transaction broadcast is stale.

func (*BroadcastStorageHelper) FindTransaction

FindTransaction looks for the provided TransactionIdentifier in processed blocks and returns the block identifier containing the most recent sighting and the transaction seen in that block.

type CoinStorageHelper

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

CoinStorageHelper implements the storage.CoinStorageHelper interface.

func NewCoinStorageHelper

func NewCoinStorageHelper(blockStorage *storage.BlockStorage) *CoinStorageHelper

NewCoinStorageHelper returns a new *CoinStorageHelper.

func (*CoinStorageHelper) CurrentBlockIdentifier

func (c *CoinStorageHelper) CurrentBlockIdentifier(
	ctx context.Context,
	transaction storage.DatabaseTransaction,
) (*types.BlockIdentifier, error)

CurrentBlockIdentifier returns the head *types.BlockIdentifier in the context of a storage.DatabaseTransaction.

type ConstructorHandler

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

ConstructorHandler is invoked by the Constructor when addresses are created or transactions are created.

func NewConstructorHandler

func NewConstructorHandler(
	balanceStorageHelper *BalanceStorageHelper,
	counterStorage *storage.CounterStorage,
) *ConstructorHandler

NewConstructorHandler returns a new *ConstructorHandler.

func (*ConstructorHandler) AddressCreated

func (h *ConstructorHandler) AddressCreated(ctx context.Context, address string) error

AddressCreated adds an address to balance tracking.

func (*ConstructorHandler) TransactionCreated

func (h *ConstructorHandler) TransactionCreated(
	ctx context.Context,
	sender string,
	transactionIdentifier *types.TransactionIdentifier,
) error

TransactionCreated increments the TransactionsCreatedCounter in CounterStorage.

type ConstructorHelper

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

ConstructorHelper implements the constructor.Helper interface.

func NewConstructorHelper

func NewConstructorHelper(
	offlineFetcher *fetcher.Fetcher,
	onlineFetcher *fetcher.Fetcher,
	keyStorage *storage.KeyStorage,
	balanceStorage *storage.BalanceStorage,
	coinStorage *storage.CoinStorage,
	broadcastStorage *storage.BroadcastStorage,
) *ConstructorHelper

NewConstructorHelper returns a new *ConstructorHelper.

func (*ConstructorHelper) AccountBalance

func (c *ConstructorHelper) AccountBalance(
	ctx context.Context,
	accountIdentifier *types.AccountIdentifier,
	currency *types.Currency,
) (*big.Int, error)

AccountBalance returns the balance for a provided address using BalanceStorage. If the address balance does not exist, 0 will be returned.

func (*ConstructorHelper) AllAddresses

func (c *ConstructorHelper) AllAddresses(ctx context.Context) ([]string, error)

AllAddresses returns a slice of all known addresses.

func (*ConstructorHelper) AllBroadcasts

func (c *ConstructorHelper) AllBroadcasts(ctx context.Context) ([]*storage.Broadcast, error)

AllBroadcasts returns a slice of all in-progress broadcasts in BroadcastStorage.

func (*ConstructorHelper) Broadcast

func (c *ConstructorHelper) Broadcast(
	ctx context.Context,
	sender string,
	intent []*types.Operation,
	transactionIdentifier *types.TransactionIdentifier,
	payload string,
) error

Broadcast enqueues a particular intent for broadcast.

func (*ConstructorHelper) ClearBroadcasts

func (c *ConstructorHelper) ClearBroadcasts(ctx context.Context) ([]*storage.Broadcast, error)

ClearBroadcasts deletes all pending broadcasts.

func (*ConstructorHelper) CoinBalance

func (c *ConstructorHelper) CoinBalance(
	ctx context.Context,
	accountIdentifier *types.AccountIdentifier,
	currency *types.Currency,
) (*big.Int, *types.CoinIdentifier, error)

CoinBalance returns the balance of the largest Coin owned by an address.

func (*ConstructorHelper) Combine

func (c *ConstructorHelper) Combine(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	unsignedTransaction string,
	signatures []*types.Signature,
) (string, error)

Combine calls the /construction/combine endpoint using the offline node.

func (*ConstructorHelper) Derive

func (c *ConstructorHelper) Derive(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	publicKey *types.PublicKey,
	metadata map[string]interface{},
) (string, map[string]interface{}, error)

Derive returns a new address for a provided publicKey.

func (*ConstructorHelper) Hash

func (c *ConstructorHelper) Hash(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	networkTransaction string,
) (*types.TransactionIdentifier, error)

Hash calls the /construction/hash endpoint using the offline node.

func (*ConstructorHelper) LockedAddresses

func (c *ConstructorHelper) LockedAddresses(ctx context.Context) ([]string, error)

LockedAddresses returns a slice of all addresses currently sending or receiving funds.

func (*ConstructorHelper) Metadata

func (c *ConstructorHelper) Metadata(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	metadataRequest map[string]interface{},
) (map[string]interface{}, error)

Metadata calls the /construction/metadata endpoint using the online node.

func (*ConstructorHelper) Parse

func (c *ConstructorHelper) Parse(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	signed bool,
	transaction string,
) ([]*types.Operation, []string, map[string]interface{}, error)

Parse calls the /construction/parse endpoint using the offline node.

func (*ConstructorHelper) Payloads

func (c *ConstructorHelper) Payloads(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	intent []*types.Operation,
	requiredMetadata map[string]interface{},
) (string, []*types.SigningPayload, error)

Payloads calls the /construction/payloads endpoint using the offline node.

func (*ConstructorHelper) Preprocess

func (c *ConstructorHelper) Preprocess(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	intent []*types.Operation,
	metadata map[string]interface{},
) (map[string]interface{}, error)

Preprocess calls the /construction/preprocess endpoint on an offline node.

func (*ConstructorHelper) RandomAmount

func (c *ConstructorHelper) RandomAmount(min *big.Int, max *big.Int) *big.Int

RandomAmount returns some integer between min and max.

func (*ConstructorHelper) Sign

func (c *ConstructorHelper) Sign(
	ctx context.Context,
	payloads []*types.SigningPayload,
) ([]*types.Signature, error)

Sign invokes the KeyStorage backend to sign some payloads.

func (*ConstructorHelper) StoreKey

func (c *ConstructorHelper) StoreKey(
	ctx context.Context,
	address string,
	keyPair *keys.KeyPair,
) error

StoreKey stores a KeyPair and address in KeyStorage.

type ReconcilerHandler

type ReconcilerHandler struct {
	InactiveFailure      *reconciler.AccountCurrency
	InactiveFailureBlock *types.BlockIdentifier

	ActiveFailureBlock *types.BlockIdentifier
	// contains filtered or unexported fields
}

ReconcilerHandler implements the Reconciler.Handler interface.

func NewReconcilerHandler

func NewReconcilerHandler(
	logger *logger.Logger,
	haltOnReconciliationError bool,
) *ReconcilerHandler

NewReconcilerHandler creates a new ReconcilerHandler.

func (*ReconcilerHandler) ReconciliationFailed

func (h *ReconcilerHandler) ReconciliationFailed(
	ctx context.Context,
	reconciliationType string,
	account *types.AccountIdentifier,
	currency *types.Currency,
	computedBalance string,
	nodeBalance string,
	block *types.BlockIdentifier,
) error

ReconciliationFailed is called each time a reconciliation fails. In this Handler implementation, we halt if haltOnReconciliationError was set to true. We also cancel the context.

func (*ReconcilerHandler) ReconciliationSucceeded

func (h *ReconcilerHandler) ReconciliationSucceeded(
	ctx context.Context,
	reconciliationType string,
	account *types.AccountIdentifier,
	currency *types.Currency,
	balance string,
	block *types.BlockIdentifier,
) error

ReconciliationSucceeded is called each time a reconciliation succeeds.

type ReconcilerHelper

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

ReconcilerHelper implements the Reconciler.Helper interface.

func NewReconcilerHelper

func NewReconcilerHelper(
	blockStorage *storage.BlockStorage,
	balanceStorage *storage.BalanceStorage,
) *ReconcilerHelper

NewReconcilerHelper returns a new ReconcilerHelper.

func (*ReconcilerHelper) AccountBalance

func (h *ReconcilerHelper) AccountBalance(
	ctx context.Context,
	account *types.AccountIdentifier,
	currency *types.Currency,
	headBlock *types.BlockIdentifier,
) (*types.Amount, *types.BlockIdentifier, error)

AccountBalance returns the balance of an account in block storage. It is necessary to perform this check outside of the Reconciler package to allow for separation from a default storage backend.

func (*ReconcilerHelper) BlockExists

func (h *ReconcilerHelper) BlockExists(
	ctx context.Context,
	block *types.BlockIdentifier,
) (bool, error)

BlockExists returns a boolean indicating if block_storage contains a block. This is necessary to reconcile across reorgs. If the block returned on an account balance fetch does not exist, reconciliation will be skipped.

func (*ReconcilerHelper) CurrentBlock

func (h *ReconcilerHelper) CurrentBlock(
	ctx context.Context,
) (*types.BlockIdentifier, error)

CurrentBlock returns the last processed block and is used to determine which block to check account balances at during inactive reconciliation.

Jump to

Keyboard shortcuts

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