module

package
v0.29.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: 6 Imported by: 7 modules, 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 the engine-neutral contract an application's overlay module satisfies in Go: the topic managers and lookup services an overlay host mounts, the payloads the host hands them, and the host they are built against. It is the Go twin of the TypeScript package's engine-types (ts/src/engine-types.ts).

A module never imports an engine. It is written against these shapes, expressed in go-sdk's own types (a parsed BEEF, an outpoint, admittance instructions, a lookup question and answer), and an engine's host adapts them to whatever that engine calls. So the same module runs on any Go overlay host that carries the adapter, and a widening of an engine's interface cannot break a module's build.

The twins

The TypeScript contract is declared structurally and marks some members optional. Go has neither, so an optional member is an optional interface a host asserts for, and a union payload is one struct with a Mode field that says which members are set.

TypeScript (engine-types.ts)       Go (this package)
AdmittanceInstructions             overlay.AdmittanceInstructions (go-sdk)
TopicManager                       TopicManager
  identifyAdmissibleOutputs          IdentifyAdmissibleOutputs
  identifyNeededInputs (optional)    InputIdentifier.IdentifyNeededInputs
  getDocumentation                   GetDocumentation
  getMetaData                        GetMetaData (*overlay.MetaData)
OutputAdmittedByTopic              OutputAdmittedByTopic
  mode                               Mode (AdmissionMode)
  txid, outputIndex                  Outpoint (transaction.Outpoint)
  topic                              Topic
  satoshis                           Satoshis
  lockingScript                      LockingScript
  atomicBEEF                         AtomicBEEF
  offChainValues (optional)          OffChainValues (nil when absent)
OutputSpent                        OutputSpent
  mode                               Mode (SpendNotificationMode)
  txid, outputIndex                  Outpoint
  topic                              Topic
  spendingTxid                       SpendingTxid
  inputIndex                         InputIndex
  unlockingScript                    UnlockingScript
  sequenceNumber                     SequenceNumber
  spendingAtomicBEEF                 SpendingAtomicBEEF
  offChainValues (optional)          OffChainValues (nil when absent)
LookupFormula                      []lookup.LookupFormula (go-sdk)
LookupQuestion                     *lookup.LookupQuestion (go-sdk)
LookupServiceMetaData              *overlay.MetaData (go-sdk)
LookupService                      LookupService
  admissionMode                      AdmissionMode()
  spendNotificationMode              SpendNotificationMode()
  outputAdmittedByTopic              OutputAdmittedByTopic
  outputSpent (optional)             SpendListener.OutputSpent
  outputNoLongerRetainedInHistory    RetentionListener.OutputNoLongerRetainedInHistory
    (optional)
  outputEvicted                      OutputEvicted
  lookup                             Lookup (*lookup.LookupAnswer)
  getDocumentation                   GetDocumentation
  getMetaData                        GetMetaData
  restore (optional)                 Restorer.Restore
Output                             Output
  txid, outputIndex                  Outpoint
  outputScript                       OutputScript
  satoshis                           Satoshis
  topic                              Topic
  spent                              Spent
  outputsConsumed                    OutputsConsumed
  consumedBy                         ConsumedBy
  beef (optional)                    Beef (nil when absent)
  blockHeight (optional)             BlockHeight (0 when unmined)
  score (optional)                   Score
ModuleHost                         Host
  log                                Log
  metrics.inc                        Metrics().Inc
  metrics.preset                     Metrics().Preset
  metrics.gauge                      Metrics().Gauge
RestoreStorage                     RestoreStorage
  findOutput                         FindOutput
Module                             Module
  topics                             Topics
  lookups                            Lookups
default export (host) => Module    Factory

Two TypeScript arguments have no Go member. identifyAdmissibleOutputs takes offChainValues and a mode on the TypeScript side; a Go engine hands a manager neither, so a module that admits on either is not portable and does not exist. The TypeScript lookupFormula's context has no go-sdk field either; no module sets one.

A lookup answer's metadata (name, shortDescription, iconURL, version, informationURL) and admittance instructions (outputsToAdmit, coinsToRetain, coinsRemoved) cross the wire as JSON, and go-sdk's types carry exactly the TypeScript field names as their JSON tags; the package's test holds them to it, and holds this table to the TypeScript source.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Submission added in v0.28.0

func Submission(ctx context.Context) ([]byte, bool)

Submission is the submission's bytes as they arrived, when the host put them in ctx (WithSubmission).

func WithSubmission added in v0.28.0

func WithSubmission(ctx context.Context, raw []byte) context.Context

WithSubmission carries a submission's bytes, exactly as they arrived at the host, in ctx for the topic managers the host then calls; Submission reads them. A host that verifies and parses the bytes before a manager runs still hands them whole, because some managers decide on the wire form (which transactions a BEEF carries, in what order, with which proofs), which a parsed BEEF, merged with what the host already held, no longer shows. The TypeScript engine hands a manager the bytes themselves; this is the Go host's way of doing the same.

Types

type AdmissionMode

type AdmissionMode string

AdmissionMode is the shape a lookup service wants an admitted output in.

const (
	// AdmitLockingScript: the host hands the output's locking script,
	// satoshis and outpoint.
	AdmitLockingScript AdmissionMode = "locking-script"
	// AdmitWholeTx: the host hands the whole transaction as Atomic BEEF.
	AdmitWholeTx AdmissionMode = "whole-tx"
)

The admission modes.

type Factory

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

Factory builds a module for one host. It is the TypeScript module's default export.

type Host

type Host interface {
	Log(msg string, extra map[string]any)
	Metrics() Metrics
}

Host is what a module is built against: the host's log and metrics. A module keeps no logger or registry of its own.

type HydratedOutput added in v0.27.0

type HydratedOutput struct {
	Beef        []byte
	OutputIndex uint32
	Context     []byte
}

HydratedOutput is one output of an answer a lookup service hydrated itself: its BEEF (Atomic BEEF), its index, and the context the class gives it (nil when none). A service that must put a context on an output (the TypeScript engine carries a formula's context to the output; go-sdk's OutputListItem has no such member) answers a LookupAnswer of type output-list with Outputs filled as usual and Result set to a []HydratedOutput; a host that serves the answer over HTTP renders Result when it is one, and Outputs otherwise. An engine passes an output-list answer through untouched, so the convention costs it nothing.

type InputIdentifier

type InputIdentifier interface {
	IdentifyNeededInputs(ctx context.Context, beef *transaction.Beef, txid *chainhash.Hash) ([]*transaction.Outpoint, error)
}

InputIdentifier is a TopicManager that can name inputs the host must fetch before admission (TypeScript identifyNeededInputs). A manager that needs none leaves it out.

type LookupService

type LookupService interface {
	// AdmissionMode is the shape OutputAdmittedByTopic arrives in.
	AdmissionMode() AdmissionMode
	// SpendNotificationMode is how much OutputSpent carries. A service
	// that answers SpendNone need not be a SpendListener.
	SpendNotificationMode() SpendNotificationMode
	// OutputAdmittedByTopic indexes one admitted output.
	OutputAdmittedByTopic(ctx context.Context, payload *OutputAdmittedByTopic) error
	// OutputEvicted removes an output from every index; it must never be
	// answered again.
	OutputEvicted(ctx context.Context, outpoint *transaction.Outpoint) error
	// Lookup answers one question.
	Lookup(ctx context.Context, question *lookup.LookupQuestion) (*lookup.LookupAnswer, error)
	// GetDocumentation is the service's documentation, Markdown.
	GetDocumentation() string
	// GetMetaData names the service.
	GetMetaData() *overlay.MetaData
}

LookupService indexes admitted outputs and answers questions about them.

type Metrics

type Metrics interface {
	// Inc adds by to a counter, creating it on first use.
	Inc(name string, labels map[string]string, by float64)
	// Preset creates a counter series at zero, so an alert over it finds a
	// series before the first event.
	Preset(name string, labels map[string]string)
	// Gauge registers a gauge read from fn at each scrape.
	Gauge(name string, fn func() float64)
}

Metrics is a module's view of the host's metrics. Names are the module's own, under its own prefix; the host owns the registry.

type Module

type Module struct {
	Topics  map[string]TopicManager
	Lookups map[string]LookupService
}

Module is what a factory returns: topic managers keyed by topic name and lookup services keyed by service name. Either map may be empty.

type Output

type Output struct {
	Outpoint        transaction.Outpoint
	OutputScript    *script.Script
	Satoshis        uint64
	Topic           string
	Spent           bool
	OutputsConsumed []*transaction.Outpoint
	ConsumedBy      []*transaction.Outpoint
	Beef            []byte
	BlockHeight     uint32
	Score           float64
}

Output is one row of a host's outputs table, as the host hands it to a restore. Beef is nil when the host did not include it; BlockHeight is zero while the output's transaction is unmined.

type OutputAdmittedByTopic

type OutputAdmittedByTopic struct {
	Mode           AdmissionMode
	Outpoint       transaction.Outpoint
	Topic          string
	Satoshis       uint64
	LockingScript  *script.Script
	AtomicBEEF     []byte
	OffChainValues []byte
}

OutputAdmittedByTopic is what a lookup service is told when a topic manager admits an output. Mode says which members are set: under AdmitLockingScript the outpoint, satoshis and locking script; under AdmitWholeTx the outpoint and the Atomic BEEF. Topic and OffChainValues are set under both.

type OutputSpent

type OutputSpent struct {
	Mode               SpendNotificationMode
	Outpoint           transaction.Outpoint
	Topic              string
	SpendingTxid       *chainhash.Hash
	InputIndex         uint32
	UnlockingScript    *script.Script
	SequenceNumber     uint32
	SpendingAtomicBEEF []byte
	OffChainValues     []byte
}

OutputSpent is what a lookup service is told when an output it indexed is spent. Mode says which members are set: the outpoint and topic always; SpendingTxid under SpendTxid, SpendScript and SpendWholeTx; InputIndex, UnlockingScript and SequenceNumber under SpendScript; SpendingAtomicBEEF under SpendWholeTx.

type RestoreStorage

type RestoreStorage interface {
	FindOutput(ctx context.Context, outpoint *transaction.Outpoint, topic string) (*Output, error)
}

RestoreStorage is the one storage call a restore may make: the host's own lookup of one output, spent or not. It is what lets a lookup service read an output that is not among the unspent rows it was handed: a spent funding output, with Spent and ConsumedBy saying who spent it. An empty topic means any topic. An output the host does not hold is (nil, nil).

type Restorer

type Restorer interface {
	Restore(ctx context.Context, outputs []Output, storage RestoreStorage) (int, error)
}

Restorer is a LookupService that rebuilds its index from the host's unspent rows at startup (TypeScript restore). It answers how many it indexed.

type RetentionListener

type RetentionListener interface {
	OutputNoLongerRetainedInHistory(ctx context.Context, outpoint *transaction.Outpoint, topic string) error
}

RetentionListener is a LookupService told when a topic no longer retains an output's history (TypeScript outputNoLongerRetainedInHistory).

type SpendListener

type SpendListener interface {
	OutputSpent(ctx context.Context, payload *OutputSpent) error
}

SpendListener is a LookupService told of spends (TypeScript outputSpent).

type SpendNotificationMode

type SpendNotificationMode string

SpendNotificationMode is how much a lookup service wants to hear about a spend of an output it indexed.

const (
	// SpendNone: the service is not told of spends.
	SpendNone SpendNotificationMode = "none"
	// SpendTxid: the spending transaction's id.
	SpendTxid SpendNotificationMode = "txid"
	// SpendScript: the spending input's script, index and sequence.
	SpendScript SpendNotificationMode = "script"
	// SpendWholeTx: the spending transaction as Atomic BEEF.
	SpendWholeTx SpendNotificationMode = "whole-tx"
)

The spend notification modes.

type TopicManager

type TopicManager interface {
	// IdentifyAdmissibleOutputs answers which outputs of the transaction
	// txid names in beef the topic admits, and which of the previous coins
	// (the inputs' outpoints the host already holds on this topic, by input
	// index) it retains. A transaction that admits nothing is an empty
	// answer, never an error: an error is the manager failing, not the
	// transaction.
	IdentifyAdmissibleOutputs(ctx context.Context, beef *transaction.Beef, txid *chainhash.Hash, previousCoins []uint32) (overlay.AdmittanceInstructions, error)
	// GetDocumentation is the topic's documentation, Markdown.
	GetDocumentation() string
	// GetMetaData names the topic.
	GetMetaData() *overlay.MetaData
}

TopicManager decides which outputs of a transaction a topic admits.

Jump to

Keyboard shortcuts

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