explorer

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 28 Imported by: 0

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

func RegisterRoutes(mux chi.Router, svc *Service)

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

func NewNotificationWorker(db *sql.DB, txTable string, logger *slog.Logger) *NotificationWorker

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

func NewService(config Config, logger *slog.Logger) (*Service, error)

NewService creates a Service. It opens the indexer DB and starts the notification worker. Call Close() when done.

func (*Service) Close

func (s *Service) Close()

Close shuts down the notification worker and closes all DB connections.

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.

type WatchEntry

type WatchEntry struct {
	Address        string `json:"address"`
	NotifyIncoming bool   `json:"notify_incoming"`
	NotifyOutgoing bool   `json:"notify_outgoing"`
	WebhookURL     string `json:"url"`
}

WatchEntry describes a single webhook subscription for an address.

Directories

Path Synopsis
Package testutil provides test data factories for explorer tests.
Package testutil provides test data factories for explorer tests.

Jump to

Keyboard shortcuts

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