Documentation
¶
Index ¶
- Constants
- Variables
- func AddressBookContains(ab AddressBook, chain uint64, addrToFind string) (bool, error)
- func EnsureDeduped(addrs map[string]TypeAndVersion, bundle []TypeAndVersion) (bool, error)
- func MaybeDataErr(err error) error
- func SearchAddressBook(ab AddressBook, chain uint64, typ ContractType) (string, error)
- type AddressBook
- type AddressBookMap
- func (m *AddressBookMap) Addresses() (map[uint64]map[string]TypeAndVersion, error)
- func (m *AddressBookMap) AddressesForChain(chainSelector uint64) (map[string]TypeAndVersion, error)
- func (m *AddressBookMap) Merge(ab AddressBook) error
- func (m *AddressBookMap) Remove(ab AddressBook) error
- func (m *AddressBookMap) Save(chainSelector uint64, address string, typeAndVersion TypeAndVersion) error
- type AddressesByChain
- type ContractType
- type LabelSet
- type MultiClient
- func (mc *MultiClient) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
- func (mc *MultiClient) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
- func (mc *MultiClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
- func (mc *MultiClient) CodeAtHash(ctx context.Context, account common.Address, blockHash common.Hash) ([]byte, error)
- func (mc *MultiClient) NonceAt(ctx context.Context, account common.Address, block *big.Int) (uint64, error)
- func (mc *MultiClient) NonceAtHash(ctx context.Context, account common.Address, blockHash common.Hash) (uint64, error)
- func (mc *MultiClient) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (mc *MultiClient) WaitMined(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)
- type OnchainClient
- type RPC
- type RPCConfig
- type RetryConfig
- type TypeAndVersion
- type URLSchemePreference
Constants ¶
const ( // Default retry configuration for RPC calls RPCDefaultRetryAttempts = 10 RPCDefaultRetryDelay = 1000 * time.Millisecond // Default retry configuration for dialing RPC endpoints RPCDefaultDialRetryAttempts = 10 RPCDefaultDialRetryDelay = 1000 * time.Millisecond )
Variables ¶
Functions ¶
func AddressBookContains ¶
func AddressBookContains(ab AddressBook, chain uint64, addrToFind string) (bool, error)
func EnsureDeduped ¶
func EnsureDeduped(addrs map[string]TypeAndVersion, bundle []TypeAndVersion) (bool, error)
EnsureDeduped ensures that each contract in the bundle only appears once in the address map. It returns an error if there are more than one instance of a contract. Returns true if every value in the bundle is found once, false otherwise.
func MaybeDataErr ¶
func SearchAddressBook ¶
func SearchAddressBook(ab AddressBook, chain uint64, typ ContractType) (string, error)
SearchAddressBook search an address book for a given chain and contract type and return the first matching address.
Types ¶
type AddressBook ¶
type AddressBook interface {
Save(chainSelector uint64, address string, tv TypeAndVersion) error
Addresses() (map[uint64]map[string]TypeAndVersion, error)
AddressesForChain(chain uint64) (map[string]TypeAndVersion, error)
// Allows for merging address books (e.g. new deployments with existing ones)
Merge(other AddressBook) error
Remove(ab AddressBook) error
}
AddressBook is a simple interface for storing and retrieving contract addresses across chains. It is family agnostic as the keys are chain selectors. We store rather than derive typeAndVersion as some contracts do not support it. For ethereum addresses are always stored in EIP55 format.
type AddressBookMap ¶
type AddressBookMap struct {
// contains filtered or unexported fields
}
func NewMemoryAddressBook ¶
func NewMemoryAddressBook() *AddressBookMap
TODO: Maybe could add an environment argument which would ensure only mainnet/testnet chain selectors are used for further safety?
func NewMemoryAddressBookFromMap ¶
func NewMemoryAddressBookFromMap(addressesByChain map[uint64]map[string]TypeAndVersion) *AddressBookMap
func (*AddressBookMap) Addresses ¶
func (m *AddressBookMap) Addresses() (map[uint64]map[string]TypeAndVersion, error)
func (*AddressBookMap) AddressesForChain ¶
func (m *AddressBookMap) AddressesForChain(chainSelector uint64) (map[string]TypeAndVersion, error)
func (*AddressBookMap) Merge ¶
func (m *AddressBookMap) Merge(ab AddressBook) error
Merge will merge the addresses from another address book into this one. It will error on any existing addresses.
func (*AddressBookMap) Remove ¶
func (m *AddressBookMap) Remove(ab AddressBook) error
Remove removes the address book addresses specified via the argument from the AddressBookMap. Errors if all the addresses in the given address book are not contained in the AddressBookMap.
func (*AddressBookMap) Save ¶
func (m *AddressBookMap) Save(chainSelector uint64, address string, typeAndVersion TypeAndVersion) error
Save will save an address for a given chain selector. It will error if there is a conflicting existing address. thread safety version of the save method
type AddressesByChain ¶
type AddressesByChain map[uint64]map[string]TypeAndVersion
type ContractType ¶
type ContractType string
ContractType is a simple string type for identifying contract types.
func (ContractType) String ¶
func (ct ContractType) String() string
type LabelSet ¶
type LabelSet map[string]struct{}
LabelSet represents a set of labels on an address book entry.
func NewLabelSet ¶
NewLabelSet initializes a new LabelSet with any number of labels.
type MultiClient ¶
type MultiClient struct {
*ethclient.Client
Backups []*ethclient.Client
RetryConfig RetryConfig
// contains filtered or unexported fields
}
func NewMultiClient ¶
func NewMultiClient(lggr logger.Logger, rpcsCfg RPCConfig, opts ...func(client *MultiClient)) (*MultiClient, error)
func (*MultiClient) CallContract ¶
func (*MultiClient) CallContractAtHash ¶
func (*MultiClient) CodeAtHash ¶
func (*MultiClient) NonceAtHash ¶
func (*MultiClient) SendTransaction ¶
func (mc *MultiClient) SendTransaction(ctx context.Context, tx *types.Transaction) error
func (*MultiClient) WaitMined ¶
func (mc *MultiClient) WaitMined(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)
type OnchainClient ¶
type OnchainClient interface {
bind.ContractBackend
bind.DeployBackend
BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
}
OnchainClient is an EVM chain client. For EVM specifically we can use existing geth interface to abstract chain clients.
type RPC ¶
type RPC struct {
Name string
WSURL string
HTTPURL string
PreferredURLScheme URLSchemePreference
}
func (RPC) ToEndpoint ¶
ToEndpoint returns the correct endpoint based on the preferred URL scheme If the preferred URL scheme is not set, it will return the WS URL If the preferred URL scheme is set to WS, it will return the WS URL If the preferred URL scheme is set to HTTP, it will return the HTTP URL
type RPCConfig ¶
RPCConfig is a configuration for a chain. It contains a chain selector and a list of RPCs
type RetryConfig ¶
type TypeAndVersion ¶
type TypeAndVersion struct {
Type ContractType `json:"Type"`
Version semver.Version `json:"Version"`
Labels LabelSet `json:"Labels,omitempty"`
}
func MustTypeAndVersionFromString ¶
func MustTypeAndVersionFromString(s string) TypeAndVersion
func NewTypeAndVersion ¶
func NewTypeAndVersion(t ContractType, v semver.Version) TypeAndVersion
func TypeAndVersionFromString ¶
func TypeAndVersionFromString(s string) (TypeAndVersion, error)
Note this will become useful for validation. When we want to assert an onchain call to typeAndVersion yields whats expected.
func (*TypeAndVersion) AddLabel ¶
func (tv *TypeAndVersion) AddLabel(label string)
AddLabel adds a string to the LabelSet in the TypeAndVersion.
func (TypeAndVersion) Equal ¶
func (tv TypeAndVersion) Equal(other TypeAndVersion) bool
func (TypeAndVersion) String ¶
func (tv TypeAndVersion) String() string
type URLSchemePreference ¶
type URLSchemePreference int
const ( URLSchemePreferenceNone URLSchemePreference = iota URLSchemePreferenceWS URLSchemePreferenceHTTP )
func URLSchemePreferenceFromString ¶
func URLSchemePreferenceFromString(s string) (URLSchemePreference, error)
func (*URLSchemePreference) UnmarshalText ¶
func (u *URLSchemePreference) UnmarshalText(text []byte) error