Documentation
¶
Index ¶
- func DecodeMetadata[T any](metadata any) (T, error)
- type AnvilConfig
- type BlockExplorer
- type Config
- func (c *Config) ChainSelectors() []uint64
- func (c *Config) FilterWith(filters ...NetworkFilter) *Config
- func (c *Config) MarshalYAML() (any, error)
- func (c *Config) Merge(other *Config)
- func (c *Config) NetworkBySelector(selector uint64) (Network, error)
- func (c *Config) Networks() []Network
- func (c *Config) UnmarshalYAML(value *yaml.Node) error
- func (c *Config) Validate() error
- type EVMMetadata
- type LoadOption
- type Manifest
- type Network
- type NetworkFilter
- type NetworkType
- type RPC
- type URLTransformer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeMetadata ¶
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 ¶
NewConfig creates a new config from a slice of networks. Any duplicate chain selectors will be overwritten.
func (*Config) ChainSelectors ¶
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 ¶
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 ¶
Merge merges another config into the current config. It overwrites any networks with the same chain selector.
func (*Config) NetworkBySelector ¶
NetworkBySelector retrieves a network by its chain selector. If the network is not found, an error is returned.
func (*Config) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface for the Config struct.
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 ¶
ChainFamily returns the family of the network based on its chain selector.
type NetworkFilter ¶
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 ¶
PreferredEndpoint returns the correct endpoint based on the preferred URL scheme. By default, it returns the HTTP URL.
type URLTransformer ¶
URLTransformer is a function that transforms a URL.