watchdog

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: 8 Imported by: 0

Documentation

Overview

Package watchdog provides blockchain monitoring services for detecting transactions involving managed addresses. It polls the blockchain for new blocks and mempool transactions, firing events when relevant addresses are involved.

Index

Constants

This section is empty.

Variables

View Source
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

type BlockEvent func(blockNum int64, blockId string)

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.

func (*Config) Load

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

Load reads the configuration from storage. Performs cold start with defaults if no config exists.

func (*Config) Save

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

Save persists the configuration to storage as JSON.

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 for transaction events.

func (*Service) Run

func (w *Service) Run() (err error)

Run starts the watchdog service. Validates configuration, loads state, and starts monitoring loops. Returns an error if required dependencies are not configured.

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 for checking known addresses.

func WithClient

func WithClient(client types.ChainClient) ServiceOption

WithClient sets the blockchain client for querying blocks and transactions.

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.

Jump to

Keyboard shortcuts

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