Documentation
¶
Overview ¶
Package watchdog provides blockchain monitoring services for detecting transactions involving managed addresses. It polls for new blocks and mempool transactions, firing events when relevant addresses are involved.
The service can resume from persisted state and supports overriding the startup block height for reprocessing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConfigStorageEmpty is returned when config storage is not configured. ErrConfigStorageEmpty = errors.New("config storage not set") // ErrAddressPoolNotSet is returned when the address manager is not configured. ErrAddressPoolNotSet = errors.New("address pool not set") // ErrChainClientNotSet is returned when the blockchain client is not configured. ErrChainClientNotSet = errors.New("blockchain client not set") )
Error definitions for watchdog service operations.
Functions ¶
This section is empty.
Types ¶
type BlockEvent ¶
BlockEvent is a callback function invoked when a new block is detected.
type Config ¶
type Config struct {
Run bool `json:"run"`
PullInterval int `json:"pullInterval"`
PullByExternalEvent bool `json:"pullByExternalEvent"`
PullByTimer bool `json:"pullByTimer"`
Confirmations int64 `json:"confirmations"`
Debug bool `json:"debug"`
// contains filtered or unexported fields
}
Config holds the watchdog service configuration. Controls polling behavior, confirmations, and debug logging.
type PullEvent ¶
type PullEvent struct {
// contains filtered or unexported fields
}
PullEvent represents an external event request for transaction or block lookup.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the main watchdog service that monitors the blockchain. It polls for new blocks and mempool content, detecting transactions involving managed addresses and firing events for subscribers.
func NewService ¶
func NewService(options ...ServiceOption) *Service
NewService creates a new watchdog service with the specified options.
func (*Service) RegisterBlockEventListen ¶
func (w *Service) RegisterBlockEventListen(handler BlockEvent)
RegisterBlockEventListen adds a handler to be called when new blocks are detected.
func (*Service) RegisterTransactionEventListen ¶
func (w *Service) RegisterTransactionEventListen(handler TransactionEvent)
RegisterTransactionEventListen adds a handler to be called for transaction events.
type ServiceOption ¶
type ServiceOption func(s *Service)
ServiceOption is a function that configures a Service.
func SetLastStateTo ¶
func SetLastStateTo(newState int64) ServiceOption
SetLastStateTo overrides the last processed block number on startup. Useful for reprocessing historical blocks.
func WithAddressManager ¶
func WithAddressManager(pool *address.Manager) ServiceOption
WithAddressManager sets the address manager used to match known addresses.
func WithClient ¶
func WithClient(client types.ChainClient) ServiceOption
WithClient sets the blockchain client used to query blocks and mempool data.
func WithConfigStorage ¶
func WithConfigStorage(storage storage.BinStorage) ServiceOption
WithConfigStorage sets the storage backend for watchdog configuration.
func WithStateStorage ¶
func WithStateStorage(storage storage.BinStorage) ServiceOption
WithStateStorage sets the storage backend for watchdog state persistence.
type TransactionEvent ¶
type TransactionEvent func(transactionInfo *types.TransferInfo)
TransactionEvent is a callback function invoked when a transaction involving a managed address is detected.