hookdb

package
v1.2.17 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package hookdb wraps a database to fire async callbacks on write operations. This enables real-time indexing without polling.

Index

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

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults

type Database

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

Database wraps another database to fire callbacks on writes

func New

func New(db database.Database, cfg Config) *Database

New wraps a database with hook capabilities

func (*Database) Close

func (db *Database) Close() error

func (*Database) Compact

func (db *Database) Compact(start, limit []byte) error

func (*Database) Delete

func (db *Database) Delete(key []byte) error

func (*Database) Get

func (db *Database) Get(key []byte) ([]byte, error)

func (*Database) Has

func (db *Database) Has(key []byte) (bool, error)

func (*Database) HealthCheck

func (db *Database) HealthCheck(ctx context.Context) (interface{}, error)

func (*Database) NewBatch

func (db *Database) NewBatch() database.Batch

func (*Database) NewIterator

func (db *Database) NewIterator() database.Iterator

func (*Database) NewIteratorWithPrefix

func (db *Database) NewIteratorWithPrefix(prefix []byte) database.Iterator

func (*Database) NewIteratorWithStart

func (db *Database) NewIteratorWithStart(start []byte) database.Iterator

func (*Database) NewIteratorWithStartAndPrefix

func (db *Database) NewIteratorWithStartAndPrefix(start, prefix []byte) database.Iterator

func (*Database) Put

func (db *Database) Put(key, value []byte) error

func (*Database) RegisterHandler

func (db *Database) RegisterHandler(prefix []byte, handler Handler)

RegisterHandler adds a handler for a specific key prefix Pass nil prefix to receive all events

func (*Database) Sync

func (db *Database) Sync() error

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 EventType

type EventType int

EventType indicates the type of database operation

const (
	EventPut EventType = iota
	EventDelete
	EventBatchWrite
)

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

type PrefixHandler struct {
	Prefix  []byte
	Handler Handler
}

PrefixHandler registers a handler for a specific key prefix

Jump to

Keyboard shortcuts

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