txcache

package
v0.0.0-...-c180733 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package txcache provides transaction caching and confirmation tracking. It stores transaction records with confirmation counts and provides query APIs for retrieving transactions by hash or address.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConfigStorageEmpty is returned when config storage is not configured.
	ErrConfigStorageEmpty = errors.New("config storage is empty")
	// ErrUnknownTransaction is returned when a transaction is not found in cache.
	ErrUnknownTransaction = errors.New("unknown transaction")
)

Error definitions for transaction cache operations.

Functions

This section is empty.

Types

type Config

type Config struct {
	Debug                 bool `json:"debug"`
	Confirmations         int  `json:"confirmations"`
	RegisterConfirmations int  `json:"registerConfirmations"`
	StoreIncomingTx       bool `json:"storeIncomingTx"`
	StoreOutgoingTx       bool `json:"storeOutgoingTx"`
	// contains filtered or unexported fields
}

Config holds the transaction cache configuration. Controls confirmation thresholds and storage behavior.

func NewConfig

func NewConfig() *Config

NewConfig creates a new configuration with default storage.

func (*Config) Load

func (c *Config) Load() (err error)

Load reads the configuration from storage.

func (*Config) Save

func (c *Config) Save() (err error)

Save persists the configuration to storage as JSON.

type Manager

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

Manager manages the transaction cache. Stores transactions with confirmation tracking and provides query APIs.

func NewManager

func NewManager(options ...ManagerOption) (*Manager, error)

NewManager creates a new transaction cache manager with the specified options. Loads configuration and starts the event processing loop.

func (*Manager) BlockEvent

func (m *Manager) BlockEvent(blockNum int64, blockId string)

BlockEvent handles a new block event to update confirmation counts.

func (*Manager) DumpDb

func (m *Manager) DumpDb()

DumpDb is a debug utility that logs all unconfirmed transactions.

func (*Manager) GetTransferInfo

func (m *Manager) GetTransferInfo(txHash string) (tx *types.TransferInfo, err error)

GetTransferInfo retrieves a cached transaction by its hash. Returns ErrUnknownTransaction if not found.

func (*Manager) GetTransfersByAddress

func (m *Manager) GetTransfersByAddress(address string) (txs []*types.TransferInfo, err error)

GetTransfersByAddress retrieves all cached transactions for an address. Returns transactions where the address is sender or recipient, sorted by timestamp.

func (*Manager) TransactionEvent

func (m *Manager) TransactionEvent(transactionInfo *types.TransferInfo)

TransactionEvent handles a new transaction event from the watchdog. Caches the transaction with initial confirmation count.

type ManagerOption

type ManagerOption func(*Manager) error

ManagerOption is a function that configures a Manager.

func WithConfigStorage

func WithConfigStorage(storage storage.BinStorage) ManagerOption

WithConfigStorage sets the storage backend for configuration.

func WithTxStorage

func WithTxStorage(storage *storage.BadgerHoldStorage) ManagerOption

WithTxStorage sets the BadgerHold storage for transaction records.

type TransferInfoCachedRecord

type TransferInfoCachedRecord struct {
	TxID              string   `json:"txId" badgerhold:"key"`
	Timestamp         int64    `json:"timestamp"`
	BlockNum          int      `json:"blockNum"`
	Success           bool     `json:"success"`
	Transfer          bool     `json:"transfer"`
	NativeCoin        bool     `json:"nativeCoin,omitempty"`
	Symbol            string   `json:"symbol,omitempty"`
	SmartContract     bool     `json:"smartContract,omitempty"`
	From              string   `json:"from" storm:"index"`
	To                string   `json:"to" storm:"index"`
	Fee               *big.Int `json:"fee"`
	Amount            *big.Int `json:"amount"`
	Token             string   `json:"token,omitempty"`
	TokenSymbol       string   `json:"tokenSymbol,omitempty"`
	InPool            bool     `json:"inPool"`
	Confirmed         bool     `json:"confirmed"`
	Confirmations     int      `json:"confirmations"`
	Decimals          int      `json:"decimals"`
	ChainSpecificData []byte   `json:"chainSpecificData,omitempty"`
}

TransferInfoCachedRecord is the persistent storage format for cached transactions. Stored in BadgerHold with indexed fields for efficient queries.

Jump to

Keyboard shortcuts

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