Documentation
¶
Overview ¶
Package hookdb wraps a database to fire async callbacks on write operations. This enables real-time indexing without polling.
Index ¶
- func BlockPrefixes() [][]byte
- func EVMPrefixes() [][]byte
- type Config
- type Database
- func (db *Database) Close() error
- func (db *Database) Compact(start, limit []byte) error
- func (db *Database) Delete(key []byte) error
- func (db *Database) Get(key []byte) ([]byte, error)
- func (db *Database) Has(key []byte) (bool, error)
- func (db *Database) HealthCheck(ctx context.Context) (interface{}, error)
- func (db *Database) NewBatch() database.Batch
- func (db *Database) NewIterator() database.Iterator
- func (db *Database) NewIteratorWithPrefix(prefix []byte) database.Iterator
- func (db *Database) NewIteratorWithStart(start []byte) database.Iterator
- func (db *Database) NewIteratorWithStartAndPrefix(start, prefix []byte) database.Iterator
- func (db *Database) Put(key, value []byte) error
- func (db *Database) RegisterHandler(prefix []byte, handler Handler)
- func (db *Database) Sync() error
- type Event
- type EventType
- type Handler
- type IndexerEvent
- type IndexerNotifier
- type NotifierConfig
- type PrefixHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlockPrefixes ¶
func BlockPrefixes() [][]byte
BlockPrefixes returns common block-related key prefixes to watch
func EVMPrefixes ¶
func EVMPrefixes() [][]byte
EVMPrefixes returns EVM-specific key prefixes to watch
Types ¶
type Config ¶
type Config struct {
// BufferSize for the async event channel (default: 10000)
BufferSize int
// Workers is the number of async workers (default: 4)
Workers int
}
Config for the hook database
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database wraps another database to fire callbacks on writes
func (*Database) HealthCheck ¶
func (*Database) NewIterator ¶
func (*Database) NewIteratorWithPrefix ¶
func (*Database) NewIteratorWithStart ¶
func (*Database) NewIteratorWithStartAndPrefix ¶
func (*Database) RegisterHandler ¶
RegisterHandler adds a handler for a specific key prefix Pass nil prefix to receive all events
type Event ¶
type Event struct {
Type EventType
Key []byte
Value []byte
Prefix []byte // Which prefix triggered this event
}
Event represents a database write event
type Handler ¶
type Handler func(Event)
Handler is called when a write event occurs Handlers are called asynchronously and should not block
type IndexerEvent ¶
type IndexerEvent struct {
ChainID string `json:"chain_id"`
Type string `json:"type"` // "put" or "delete"
Prefix string `json:"prefix"`
Key string `json:"key"`
Value []byte `json:"value,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
IndexerEvent is sent to the indexer service
type IndexerNotifier ¶
type IndexerNotifier struct {
// contains filtered or unexported fields
}
IndexerNotifier sends database events to an indexer service
func NewNotifier ¶
func NewNotifier(cfg NotifierConfig) *IndexerNotifier
NewNotifier creates a new indexer notifier
func (*IndexerNotifier) Close ¶
func (n *IndexerNotifier) Close()
Close stops the notifier and flushes remaining events
func (*IndexerNotifier) Handler ¶
func (n *IndexerNotifier) Handler(chainID string) Handler
Handler returns a hook handler for a specific chain
type NotifierConfig ¶
type NotifierConfig struct {
// Endpoint is the indexer service URL (e.g., "http://localhost:8090/api/v2/events")
Endpoint string
// ChainID identifies this chain
ChainID string
// BatchSize is the max events per batch (default: 100)
BatchSize int
// FlushInterval is how often to flush batches (default: 100ms)
FlushInterval time.Duration
// Timeout for HTTP requests (default: 5s)
Timeout time.Duration
}
NotifierConfig configures the indexer notifier
type PrefixHandler ¶
PrefixHandler registers a handler for a specific key prefix