Documentation
¶
Overview ¶
Package explorer provides a block explorer API layer. It reads chain data directly from an indexer's SQLite database (read-only) and exposes /v1/explorer/* endpoints for explorer frontends.
Architecture:
indexer → writes SQLite (WAL mode, sole writer) replicate → streams WAL to S3 (age PQ encrypted) Service → reads indexer SQLite (read-only), serves /v1/explorer/* frontend → consumes /v1/explorer/*
The indexer's DB holds chain data (blocks, txs, tokens, contracts). White-label: no chain-specific branding — configure via Config.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowedOrigins ¶
func AllowedOrigins() []string
AllowedOrigins returns the set of permitted CORS origins. Falls back to wildcard only if EXPLORER_CORS_ORIGINS is unset.
func RegisterRoutes ¶
RegisterRoutes mounts all explorer endpoints on the given chi.Router.
Types ¶
type Config ¶
type Config struct {
// IndexerDBPath is the path to the indexer's SQLite database.
// Example: ~/.lux/indexer/cchain/query/indexer.db
IndexerDBPath string
// ChainID is the chain this explorer instance serves (e.g., 96369 for mainnet C-Chain).
ChainID int64
// ChainName is the display name (e.g., "Lux C-Chain").
ChainName string
// CoinSymbol is the native coin symbol (e.g., "LUX").
CoinSymbol string
// CoinDecimals is the native coin decimals (default: 18).
CoinDecimals int
// GChainEndpoint is the G-Chain GraphQL endpoint on the node.
// Default: http://localhost:9650/ext/bc/G/graphql
// Set via GCHAIN_ENDPOINT env var.
GChainEndpoint string
// ChainDBPaths maps chain names to their SQLite DB paths for cross-chain search.
// Example: {"C": "/data/cchain/indexer.db", "Zoo": "/data/zoo/indexer.db"}
// When empty, cross-chain search only queries the local IndexerDBPath.
ChainDBPaths map[string]string
// APIPrefix is the URL prefix for all API routes (default: "/v1/explorer").
APIPrefix string
}
Config configures the explorer service.
type Notification ¶
type Notification struct {
Type string `json:"type"`
Address string `json:"address"`
TxHash string `json:"tx_hash"`
From string `json:"from"`
To string `json:"to"`
Value string `json:"value"`
Timestamp int64 `json:"timestamp"`
}
Notification is the payload POSTed to webhook URLs.
type NotificationWorker ¶
type NotificationWorker struct {
// contains filtered or unexported fields
}
NotificationWorker polls the indexer DB for new transactions matching watchlist entries.
func NewNotificationWorker ¶
NewNotificationWorker creates a stopped worker. Call Start() to begin polling.
func (*NotificationWorker) Entries ¶
func (w *NotificationWorker) Entries() []WatchEntry
Entries returns a snapshot of all watch entries. Thread-safe. Entries returns all webhook subscriptions with URLs redacted for security.
func (*NotificationWorker) Register ¶
func (w *NotificationWorker) Register(entry WatchEntry) error
Register adds a webhook subscription. Thread-safe. Returns error if URL is internal, address is invalid, or watchlist is full. Set allowInternal=true for testing only.
func (*NotificationWorker) Start ¶
func (w *NotificationWorker) Start()
Start begins the polling loop in a goroutine. Call Stop() to shut down.
func (*NotificationWorker) Stop ¶
func (w *NotificationWorker) Stop()
Stop signals the worker to stop and waits for it to finish.
func (*NotificationWorker) Unregister ¶
func (w *NotificationWorker) Unregister(address, webhookURL string)
Unregister removes all subscriptions for an address+URL pair.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns the state for explorer HTTP handlers. No DI framework — construct with NewService.
func NewService ¶
NewService creates a Service. It opens the indexer DB and starts the notification worker. Call Close() when done.
type StandaloneServer ¶
type StandaloneServer struct {
// contains filtered or unexported fields
}
StandaloneServer serves "+p+"/* on a standard net/http mux.
func NewStandaloneServer ¶
func NewStandaloneServer(cfg Config) (*StandaloneServer, error)
func (*StandaloneServer) Close ¶
func (s *StandaloneServer) Close()
func (*StandaloneServer) Handler ¶
func (s *StandaloneServer) Handler() http.Handler
Handler returns the http.Handler with security headers, CORS, and trailing-slash normalization.