common

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LedgerReader

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

LedgerReader listens for and reacts to incoming transactions.

func NewLedgerReader

func NewLedgerReader(dbRepo ReadOnlyTransactionRepository, logger *slog.Logger) *LedgerReader

NewLedgerReader returns a ledger reader over a transaction repository.

func (*LedgerReader) IsAlive

func (reader *LedgerReader) IsAlive() bool

IsAlive returns true if the ledger reader is alive and polling for new transactions.

func (*LedgerReader) StartWithCallback

func (reader *LedgerReader) StartWithCallback(callback LedgerReaderCallback) error

StartWithCallback synchronously loads all existing transactions, and then starts a background thread to listen for future transactions.

type LedgerReaderCallback

type LedgerReaderCallback interface {
	// ProcessTransaction processes a newly discovered transaction. For example,
	// an implementation might update it's cache based on the contents of the
	// new transaction.
	ProcessTransaction(transaction model.Transaction)
}

LedgerReaderCallback provides a callback method invoked by ledger reader on discovering new transactions.

type LedgerReaderTransactionRepository

type LedgerReaderTransactionRepository struct {
	DB *gorm.DB
}

LedgerReaderTransactionRepository exposes methods used by LedgerReader.

func NewLedgerReaderTransactionRepository

func NewLedgerReaderTransactionRepository(databaseURI string) (*LedgerReaderTransactionRepository, error)

NewLedgerReaderTransactionRepository returns a new repository over a database.

func (*LedgerReaderTransactionRepository) FindLatest

FindLatest returns all the transaction committed after startID and thus have an id > startID.

func (*LedgerReaderTransactionRepository) LatestTransactionID

func (r *LedgerReaderTransactionRepository) LatestTransactionID() (int64, error)

LatestTransactionID returns the id of the latest transaction, or NULL if none exist.

type ReadOnlyTransactionRepository

type ReadOnlyTransactionRepository interface {
	// LatestTransactionID returns the latest transaction id from the repository.
	LatestTransactionID() (int64, error)
	// FindLatest returns transactions that are more recent than and thus have an
	// id greater than startTransactionID.
	FindLatest(startTransactionID int64) ([]model.TransactionWithID, error)
}

ReadOnlyTransactionRepository is a read-only interface over transaction repository.

Jump to

Keyboard shortcuts

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