module

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package module is how an application mounts its topic managers and lookup services in the Go overlay engine.

It replaces the TypeScript host's Module/ModuleHost loader. Go has no runtime module loading worth using, so a module is compiled in: its package calls Register from init, the binary imports it, and OVERLAY_MODULES names which registered modules this host mounts. Each module is a thin adapter over its application's Go core: it holds no admission or lookup logic of its own that the core does not already hold.

The interfaces a module satisfies are bcommon's engine-neutral contract (github.com/lightwebinc/bcommon/module: TopicManager, LookupService and their payloads, Host, Module). A module written to that contract imports no engine; this package holds the registry, the runtime Host it is built with, and the adapters that make a contract manager an engine.TopicManager and a contract service an engine.LookupService.

Index

Constants

This section is empty.

Variables

View Source
var ErrCannotEvict = errors.New("module: the storage cannot forget an applied transaction")

ErrCannotEvict is a storage with no way to forget an applied transaction.

Functions

func LookupService added in v0.2.0

func LookupService(svc bmodule.LookupService) engine.LookupService

LookupService makes an engine.LookupService of a contract service. The engine hands every admission as Atomic BEEF; the adapter reshapes it to the service's AdmissionMode, and a spend to its SpendNotificationMode, and leaves out what the service did not ask for.

func Output added in v0.2.0

func Output(o *engine.Output) (*bmodule.Output, error)

Output makes a contract row of an engine row. The script and satoshis come from the row's BEEF, which the engine's reads include when asked; a row read without it has neither, which a restore that needs them refuses through its own check.

func Register

func Register(name string, f Factory)

Register makes a module available under name. Call it from init. A name registered twice panics: two modules under one name is a build error.

func Registered

func Registered() []string

Registered lists registered module names, sorted.

func TopicManager added in v0.2.0

func TopicManager(tm bmodule.TopicManager) engine.TopicManager

TopicManager makes an engine.TopicManager of a contract manager. A manager that is not an InputIdentifier needs no inputs fetched.

Types

type Factory

type Factory func(h Host) (Module, error)

Factory builds a module for one host.

func Adapt added in v0.2.0

func Adapt(f bmodule.Factory) Factory

Adapt makes a Factory of a contract factory, for a module that needs nothing of the runtime Host beyond the contract.

type Host

type Host struct {
	// Topics are the topics this host carries (OVERLAY_TOPICS). A module may
	// claim only topics in this list.
	Topics []string
	// Storage is the engine's storage, for lookup services that answer from
	// it rather than from an index of their own.
	Storage engine.Storage
	// Registerer is the host's metrics registry; a module's families use its
	// own prefix (bstore_, bbox_ ...), never overlay_go_.
	Registerer prometheus.Registerer
	Log        *slog.Logger
}

Host is what a module is handed when it is built: the runtime this engine offers beyond the contract. Contract gives the contract's view of it.

func (Host) Contract added in v0.2.0

func (h Host) Contract() bmodule.Host

Contract is the bcommon module.Host this runtime host presents to a module written against the contract alone: its log and metrics, nothing of the engine.

type Module

type Module = bmodule.Module

Module is what a factory returns: the contract's Module, managers keyed by tm_* topic name and lookup services keyed by ls_* name.

type Mounted

type Mounted struct {
	TopicManagers  map[string]engine.TopicManager
	LookupServices map[string]engine.LookupService
	// Owner says which module mounted each topic and lookup name.
	Owner map[string]string
	// Restorers are the mounted lookup services that rebuild an index at
	// startup, by name. Restore runs them.
	Restorers map[string]bmodule.Restorer
}

Mounted is the result of Mount: what the engine is built with.

func Mount

func Mount(names []string, h Host, m *metrics.Metrics) (*Mounted, error)

Mount builds the named modules in order and merges them. It refuses rather than resolves every conflict, and it refuses a carried topic with no manager: a host must never admit a topic under a manager nobody chose.

  • a name not registered;
  • a topic outside h.Topics, or claimed by two modules;
  • a lookup name claimed by two modules;
  • a carried topic no module claims.

func (*Mounted) Restore added in v0.2.0

func (mt *Mounted) Restore(ctx context.Context, h Host) (map[string]int, error)

Restore hands every mounted Restorer the host's unspent rows on the carried topics, with the storage seam the contract allows, and returns the count each indexed. It runs before the engine serves, as the TypeScript host's restore does. A service that fails is the host failing to start.

Jump to

Keyboard shortcuts

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