network

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeMetadata

func DecodeMetadata[T any](metadata any) (T, error)

DecodeMetadata converts the metadata field from an any interface to a user-specified type using yaml marshaling. Use your own custom types or one of the predefined common types. Example usage:

type CustomMetadata struct {
	CustomField  string `yaml:"custom_field"`
	AnotherField int    `yaml:"another_field"`
}

customMetadata, err := DecodeMetadata[CustomMetadata](metadata)
if err != nil {
  // handle error
}

Types

type AnvilConfig

type AnvilConfig struct {
	Image          string `yaml:"image"`
	Port           uint64 `yaml:"port"`
	ArchiveHTTPURL string `yaml:"archive_http_url"`
}

AnvilConfig holds the configuration for starting an Anvil node.

func (AnvilConfig) Validate

func (a AnvilConfig) Validate() error

Validate checks if the AnvilConfig has all required fields set.

type BlockExplorer

type BlockExplorer struct {
	Type   string `yaml:"type"`
	APIKey string `yaml:"api_key"`
	URL    string `yaml:"url"`
}

BlockExplorer represents a block explorer configuration in the flattened structure

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config represents the configuration of a collection of networks. This is loaded from the YAML manifest file/s.

func Load

func Load(filePaths []string, opts ...LoadOption) (*Config, error)

Load loads configuration from the specified file paths, and merges them into a single Config.

It accepts load options to customize the loading behavior.

func NewConfig

func NewConfig(networks []Network) *Config

NewConfig creates a new config from a slice of networks. Any duplicate chain selectors will be overwritten.

func (*Config) ChainSelectors

func (c *Config) ChainSelectors() []uint64

ChainSelectors returns a slice of all chain selectors from the Config.

func (*Config) FilterWith

func (c *Config) FilterWith(filters ...NetworkFilter) *Config

FilterWith returns a new Config containing only Networks that pass all provided filter functions. Filters are applied in sequence (AND logic) - a network must pass all filters to be included.

func (*Config) MarshalYAML

func (c *Config) MarshalYAML() (any, error)

MarshalYAML implements the yaml.Marshaler interface for the Config struct. It converts the internal map structure to a YAML format with a top-level "networks" key.

func (*Config) Merge

func (c *Config) Merge(other *Config)

Merge merges another config into the current config. It overwrites any networks with the same chain selector.

func (*Config) NetworkBySelector

func (c *Config) NetworkBySelector(selector uint64) (Network, error)

NetworkBySelector retrieves a network by its chain selector. If the network is not found, an error is returned.

func (*Config) Networks

func (c *Config) Networks() []Network

Networks returns a slice of all networks in the config.

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface for the Config struct.

func (*Config) Validate added in v0.29.0

func (c *Config) Validate() error

Validate ensures that all networks are valid.

type EVMMetadata

type EVMMetadata struct {
	AnvilConfig *AnvilConfig `yaml:"anvil_config,omitempty"`
}

EVMMetadata is a struct that holds metadata specific to EVM networks.

type LoadOption

type LoadOption func(*loadConfig)

LoadOption defines a function which modifies the load configuration.

func WithHTTPURLTransformer added in v0.24.0

func WithHTTPURLTransformer(t URLTransformer) LoadOption

WithHTTPURLTransformer transforms the HTTP URLs of the networks RPCs after loading.

func WithWSURLTransformer added in v0.24.0

func WithWSURLTransformer(t URLTransformer) LoadOption

WithWSURLTransformer transforms the websocket URLs of the networks RPCs after loading.

type Manifest

type Manifest struct {
	// A YAML array of networks.
	Networks []Network `yaml:"networks"`
}

Manifest is the YAML representation of network configuration.

type Network

type Network struct {
	Type          NetworkType   `yaml:"type"`
	ChainSelector uint64        `yaml:"chain_selector"`
	BlockExplorer BlockExplorer `yaml:"block_explorer"`
	RPCs          []RPC         `yaml:"rpcs"`
	Metadata      any           `yaml:"metadata"`
}

Network represents a network configuration.

func (*Network) ChainFamily

func (n *Network) ChainFamily() (string, error)

ChainFamily returns the family of the network based on its chain selector.

func (*Network) ChainID

func (n *Network) ChainID() (string, error)

ChainID returns the chain ID as a string based on the chain selector.

func (*Network) Validate added in v0.29.0

func (n *Network) Validate() error

Validate validates the network configuration to ensure that all required fields are set.

type NetworkFilter

type NetworkFilter func(Network) bool

NetworkFilter defines a function type that filters networks based on certain criteria.

func ChainFamilyFilter

func ChainFamilyFilter(chainFamily string) NetworkFilter

ChainFamilyFilter returns a filter function that matches chains with the specified chain family.

func ChainSelectorFilter

func ChainSelectorFilter(selector uint64) NetworkFilter

ChainSelectorFilter returns a filter function that matches chains with the specified chain selector

func TypesFilter

func TypesFilter(networkTypes ...NetworkType) NetworkFilter

TypesFilter returns a filter function that matches chains with the specified network types.

type NetworkType

type NetworkType string

NetworkType represents the type of network, which can either be mainnet or testnet.

const (
	NetworkTypeMainnet NetworkType = "mainnet"
	NetworkTypeTestnet NetworkType = "testnet"
)

type RPC

type RPC struct {
	RPCName            string `yaml:"rpc_name"`
	PreferredURLScheme string `yaml:"preferred_url_scheme"`
	HTTPURL            string `yaml:"http_url"`
	WSURL              string `yaml:"ws_url"`
}

RPC represents an RPC configuration in the flattened structure

func (*RPC) PreferredEndpoint

func (rpc *RPC) PreferredEndpoint() string

PreferredEndpoint returns the correct endpoint based on the preferred URL scheme. By default, it returns the HTTP URL.

type URLTransformer

type URLTransformer func(string) string

URLTransformer is a function that transforms a URL.

Jump to

Keyboard shortcuts

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