chain

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 15 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 RedactURL

func RedactURL(rawURL string) string

RedactURL returns a version of the URL with path segments and query parameters masked to avoid leaking secrets that may have been resolved from environment variables. For example, "https://rpc.example.com/v1/my-secret-key" becomes "https://rpc.example.com/v1/***".

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   *capabilities.Registry
	Clients    map[uint64]ChainClient
	Forwarders map[uint64]string
	PrivateKey interface{} // chain-type-specific key type; EVM uses *ecdsa.PrivateKey
	Broadcast  bool
	Limits     Limits // nil disables limit 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 interface {
	ChainWriteReportSizeLimit() int
}

Limits exposes the chain-write limits that every chain type's capability enforcement layer needs. Chain-type-specific accessors (e.g. EVM gas limit) live on chain-type-scoped extension interfaces in the family package so non-EVM chain types cannot accidentally depend on EVM semantics.

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 TriggerParams

type TriggerParams struct {
	Clients         map[uint64]ChainClient
	Interactive     bool
	ChainTypeInputs map[string]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