Help us shape the future of Go! Take the 2026 Go Developer Survey

chain

package
v1.39.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All() map[string]ChainType

All returns a copy of all registered chain types.

func Build

func Build(lggr *zerolog.Logger)

Build instantiates every registered chain type with the given logger. Must be called once at command startup before All()/Get() return meaningful results.

func CollectAllCLIInputs

func CollectAllCLIInputs(v *viper.Viper) map[string]string

CollectAllCLIInputs gathers CLI inputs from every registered chain type.

func Names

func Names() []string

Names returns sorted registered chain type names.

func ParseTriggerChainSelector

func ParseTriggerChainSelector(prefix, id string) (uint64, bool)

ParseTriggerChainSelector extracts the chain selector from a trigger ID of the form "<prefix>:ChainSelector:<digits>..." (case-insensitive). The prefix anchor ensures each chain family only claims its own IDs. Returns 0, false if the ID does not match.

func Register

func Register(name string, factory Factory, flagDefs []CLIFlagDef)

Register adds a chain type factory and its CLI flag definitions to the registry. Called from chain type package init(); the factory is invoked later in Build(). Panics on duplicate registration (programming error).

func RegisterAllCLIFlags

func RegisterAllCLIFlags(cmd *cobra.Command)

RegisterAllCLIFlags registers CLI flags from every registered chain type's flag definitions. Called at command setup time before Build().

Types

type CLIFlagDef

type CLIFlagDef struct {
	Name         string
	Description  string
	DefaultValue string // empty string for string flags, or special handling
	FlagType     CLIFlagType
}

CLIFlagDef describes a CLI flag a chain type needs registered.

type CLIFlagType

type CLIFlagType int

CLIFlagType indicates the Go type of a CLI flag.

const (
	CLIFlagString CLIFlagType = iota
	CLIFlagInt
)

type CapabilityConfig

type CapabilityConfig struct {
	Registry   *capreg.Registry
	Clients    map[uint64]ChainClient
	Forwarders map[uint64]string
	PrivateKey interface{} // chain-type-specific key type; EVM uses *ecdsa.PrivateKey
	Broadcast  bool
	Limits     *cresettings.Workflows // nil disables enforcement
	Logger     logger.Logger
}

CapabilityConfig holds everything a chain type needs to register capabilities.

type ChainClient

type ChainClient interface{}

ChainClient is an opaque handle to a chain-specific RPC client. Each chain type casts this to its concrete type internally.

type ChainConfig

type ChainConfig struct {
	Selector  uint64
	Forwarder string // chain-type-specific forwarding address
}

ChainConfig identifies a supported chain within a chain type.

type ChainType

type ChainType interface {
	// Name returns the chain type identifier (e.g., "evm", "aptos").
	Name() string

	// ResolveClients creates RPC clients for all chains this chain type can
	// simulate, including both supported and experimental chains. Returns a
	// ResolvedChains bundle containing clients keyed by chain selector,
	// forwarder addresses, and any chain-type-agnostic metadata (e.g.
	// experimental-selector set) that later interface methods need.
	ResolveClients(v *viper.Viper) (ResolvedChains, error)

	// ResolveKey parses and validates this chain type's signing key from
	// settings. If broadcast is true, missing or default-sentinel keys
	// are a hard error; otherwise a sentinel may be used with a warning.
	// Returns the parsed key (chain-type-specific) or nil if the chain
	// type does not use a signing key.
	ResolveKey(creSettings *settings.Settings, broadcast bool) (interface{}, error)

	// ResolveTriggerData produces the chain-type-specific trigger payload for
	// a given chain selector, using runtime parameters from the caller.
	ResolveTriggerData(ctx context.Context, selector uint64, params TriggerParams) (interface{}, error)

	// RegisterCapabilities creates capability servers for this chain type's
	// chains and adds them to the registry. Returns the underlying services
	// (e.g., per-selector chain fakes) so the caller can manage their lifecycle.
	RegisterCapabilities(ctx context.Context, cfg CapabilityConfig) ([]services.Service, error)

	// ExecuteTrigger fires a chain-specific trigger for a given selector.
	// Each chain type defines what triggerData looks like.
	ExecuteTrigger(ctx context.Context, selector uint64, registrationID string, triggerData interface{}) error

	// Supports reports whether this chain type has an initialised capability
	// for the given selector in the current run (supported + RPC configured).
	Supports(selector uint64) bool

	// ParseTriggerChainSelector extracts this family's selector from a trigger
	// subscription ID (e.g. "evm:ChainSelector:123@1.0.0"). Returns 0, false if
	// the ID does not belong to this chain type.
	ParseTriggerChainSelector(triggerID string) (uint64, bool)

	// RunHealthCheck validates RPC connectivity for all resolved clients.
	// The resolved argument is the same bundle ResolveClients returned,
	// threaded back by the caller so RunHealthCheck is self-contained and
	// does not depend on hidden state on the ChainType instance.
	RunHealthCheck(resolved ResolvedChains) error

	// SupportedChains returns the list of chains this chain type supports
	// out of the box (for display/documentation purposes).
	SupportedChains() []ChainConfig

	// CollectCLIInputs reads this chain type's CLI flags from viper and
	// returns them as key-value pairs for TriggerParams.ChainTypeInputs.
	CollectCLIInputs(v *viper.Viper) map[string]string
}

ChainType defines what a chain type plugin must implement to participate in workflow simulation.

func Get

func Get(name string) (ChainType, error)

Get returns a registered chain type by name.

type Factory

type Factory func(lggr *zerolog.Logger) ChainType

Factory constructs a ChainType with the logger the simulator uses. Registered at init() time; invoked during Build() at command runtime.

type Limits

type Limits struct {
	ReportSize int
	GasLimit   uint64
}

Limits is the common per-family limits contract enforced by the LimitedChain wrappers.

type ListeningChainType added in v1.19.0

type ListeningChainType interface {
	NewTriggerListener(ctx context.Context, selector uint64, params TriggerParams) (TriggerListener, error)
}

ListeningChainType is an optional extension for chain types that can keep listening for trigger events and produce a fresh trigger payload each time.

type ResolvedChains

type ResolvedChains struct {
	Clients    map[uint64]ChainClient
	Forwarders map[uint64]string
	// ExperimentalSelectors marks selectors that came from experimental-chain
	// config rather than the chain type's built-in supported list. Used for
	// error labelling (e.g. "experimental chain N" vs a chain name).
	ExperimentalSelectors map[uint64]bool
}

ResolvedChains is the result of ChainType.ResolveClients: the RPC clients, forwarders, and any chain-type-agnostic metadata later interface methods (e.g. RunHealthCheck) depend on.

type TriggerListener added in v1.19.0

type TriggerListener interface {
	Next(ctx context.Context) (interface{}, error)
}

TriggerListener streams chain trigger payloads that match the selected workflow subscription until the caller's context is cancelled.

type TriggerParams

type TriggerParams struct {
	Clients         map[uint64]ChainClient
	Interactive     bool
	Listen          bool
	Limits          *cresettings.Workflows
	ChainTypeInputs map[string]string
	// TriggerPayload is the protobuf Any payload from the selected
	// pb.TriggerSubscription. Chain types unmarshal it into their own
	// trigger-config message (e.g. evm.FilterLogTriggerRequest) to learn what
	// the workflow is actually subscribed to.
	TriggerPayload *anypb.Any
	// WorkflowName is used to render replay-command hints in interactive copy.
	WorkflowName string
}

TriggerParams carries chain-type-agnostic inputs needed to resolve trigger data for a given chain trigger. ChainTypeInputs is a free-form bag of CLI-supplied strings; each chain type interprets the keys it knows about and ignores the rest.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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