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 ¶
- Variables
- func LookupService(svc bmodule.LookupService) engine.LookupService
- func Output(o *engine.Output) (*bmodule.Output, error)
- func Register(name string, f Factory)
- func Registered() []string
- func TopicManager(tm bmodule.TopicManager) engine.TopicManager
- type Factory
- type Host
- type Module
- type Mounted
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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 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 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.
type 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 ¶
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
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.