Documentation
¶
Index ¶
- Constants
- Variables
- func AddressBookContains(ab AddressBook, chain uint64, addrToFind string) (bool, error)
- func ConfirmIfNoError(chain cldf_evm.Chain, tx *types.Transaction, err error) (uint64, error)
- func ConfirmIfNoErrorWithABI(chain cldf_evm.Chain, tx *types.Transaction, abi string, err error) (uint64, error)
- func DecodeErr(encodedABI string, err error) error
- func DecodedErrFromABIIfDataErr(err error, abi string) error
- func EnsureDeduped(addrs map[string]TypeAndVersion, bundle []TypeAndVersion) (bool, error)
- func IsValidChainSelector(cs uint64) error
- func MaybeDataErr(err error) error
- func MergeChangesetOutput(env Environment, dest *ChangesetOutput, src ChangesetOutput) error
- func SearchAddressBook(ab AddressBook, chain uint64, typ ContractType) (string, error)
- func SimTransactOpts() *bind.TransactOpts
- 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 ChangeLogic
- type ChangeSet
- type ChangeSetV2
- type ChangesetOutput
- type ContractDeploy
- type ContractType
- type Environment
- type EnvironmentOption
- type LabelSet
- type MultiClient
- func (mc *MultiClient) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
- 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) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)
- func (mc *MultiClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
- func (mc *MultiClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, 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) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
- func (mc *MultiClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
- func (mc *MultiClient) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (mc *MultiClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
- func (mc *MultiClient) SuggestGasPrice(ctx context.Context) (*big.Int, error)
- func (mc *MultiClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
- func (mc *MultiClient) WaitMined(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)
- type OCRSecrets
- type PreconditionVerifier
- type ProposedJob
- type RPC
- type RPCConfig
- type RetryConfig
- type TypeAndVersion
- type URLSchemePreference
- type ViewState
- type ViewStateV2
Constants ¶
const ( // Default retry configuration for RPC calls RPCDefaultRetryAttempts = 1 RPCDefaultRetryDelay = 1000 * time.Millisecond RPCDefaultRetryTimeout = 10 * time.Second // Default retry configuration for dialing RPC endpoints RPCDefaultDialRetryAttempts = 1 RPCDefaultDialRetryDelay = 1000 * time.Millisecond RPCDefaultDialTimeout = 10 * time.Second // Default timeout for health checks RPCDefaultHealthCheckTimeout = 2 * time.Second )
Variables ¶
var ( ErrInvalidChainSelector = errors.New("invalid chain selector") ErrInvalidAddress = errors.New("invalid address") ErrChainNotFound = errors.New("chain not found") )
var ( ErrInvalidConfig = errors.New("invalid changeset config") ErrInvalidEnvironment = errors.New("invalid environment") )
var ( // ErrMnemonicRequired is returned when the OCR mnemonic is not set ErrMnemonicRequired = errors.New("xsigners or xproposers required") )
Functions ¶
func AddressBookContains ¶
func AddressBookContains(ab AddressBook, chain uint64, addrToFind string) (bool, error)
func ConfirmIfNoError ¶ added in v0.0.12
ConfirmIfNoError confirms the transaction if no error occurred. if the error is a DataError, it will return the decoded error message and data.
func ConfirmIfNoErrorWithABI ¶ added in v0.0.12
func ConfirmIfNoErrorWithABI(chain cldf_evm.Chain, tx *types.Transaction, abi string, err error) (uint64, error)
ConfirmIfNoErrorWithABI confirms the transaction if no error occurred. if the error is a DataError, it will return the decoded error message and data.
func DecodeErr ¶ added in v0.0.13
DecodeErr decodes an error from a contract call using the contract's ABI. If the error is not decodable, it returns the original error.
func DecodedErrFromABIIfDataErr ¶ added in v0.0.12
DecodedErrFromABIIfDataErr decodes the error message and data from a DataError.
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 IsValidChainSelector ¶ added in v0.0.13
IsValidChainSelector checks if the chain selector is valid.
func MaybeDataErr ¶
func MergeChangesetOutput ¶ added in v0.0.6
func MergeChangesetOutput(env Environment, dest *ChangesetOutput, src ChangesetOutput) error
MergeChangesetOutput merges the source ChangesetOutput into the destination ChangesetOutput. It is useful to combine multiple ChangesetOutput objects into one to create one consolidated changeset from multiple granular changesets. Ensure to run proposalutils.AggregateProposals at the end of consolidated changeset to ensure the proposals are merged correctly.
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.
func SimTransactOpts ¶ added in v0.0.13
func SimTransactOpts() *bind.TransactOpts
SimTransactOpts is useful to generate just the calldata for a given gethwrapper method.
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 ChangeLogic ¶ added in v0.0.6
type ChangeLogic[C any] func(e Environment, config C) (ChangesetOutput, error)
ChangeLogic encapsulates the active behavior of a ChangeSetV2. The config struct contains environment-specific inputs for this logical change. For example, it might contain the chainSelectors against which this change logic should be applied, or certain contract addresses or configuration values to be used in this change. The function should perform any deployment or configuration tasks, compose and propose job-specs, and generate any MCMS proposals necessary. This is the standalone version of ChangeSetV2.Apply for use with CreateChangeSet
ChangeLogic functions should operate on a modest number of chains to reduce the risk of partial failures.
type ChangeSet ¶ added in v0.0.6
type ChangeSet[C any] func(e Environment, config C) (ChangesetOutput, error)
ChangeSet is equivalent to ChangeLogic Deprecated: use the ChangeLogic type, or an instance of a ChangeSetV2 in infrastructure or validation code.
type ChangeSetV2 ¶ added in v0.0.6
type ChangeSetV2[C any] interface { // Apply performs the logic of the changeset, including any side effects, such as on-chain (non-MCMS) writes or // contract deployments, job-spec creation and Job-Distributor interaction, MCMS proposal creation, etc. It should // return the ingredients of the side effects in a ChangesetOutput. Apply(e Environment, config C) (ChangesetOutput, error) // VerifyPreconditions function verifies the preconditions of the config. It should have no side effects, instead // returning an error if the ChangeSetV2 should not be applied, or nil if the ChangeSetV2 is safe to apply. VerifyPreconditions(e Environment, config C) error }
ChangeSetV2 is a type which encapsulates the logic to perform a set of changes to be made to an environment, in the context of deploying Chainlink's product operations - namely deploying and configuring contracts, generating and proposing TOML job-specs and interacting with the Job Distributor, and creating MCMS proposals.
ChangeSetV2 has a pre-validation function which is optional (can be implemented as a no-op), which execution environments (such as the migrations infrastructure in chainlink-deployments) should execute before invoking the Apply method.
> Note: ChangeSetV2 replaces ChangeSet, though its Apply method is identical in signature to a ChangeSet function.
func CreateChangeSet ¶ added in v0.0.6
func CreateChangeSet[C any](applyFunc ChangeLogic[C], verifyFunc func(e Environment, config C) error) ChangeSetV2[C]
CreateChangeSet creates a ChangeSetV2 from an existing execution function (or an older ChangeSet) and a precondition verification function.
func CreateLegacyChangeSet ¶ added in v0.0.6
func CreateLegacyChangeSet[C any](changeset ChangeSet[C]) ChangeSetV2[C]
type ChangesetOutput ¶ added in v0.0.6
type ChangesetOutput struct { // Deprecated: Prefer Jobs instead. JobSpecs map[string][]string `deprecated:"true"` Jobs []ProposedJob MCMSTimelockProposals []mcms.TimelockProposal DescribedTimelockProposals []string MCMSProposals []mcms.Proposal // Deprecated: AddressBook is deprecated and will be removed in future versions. // Please use DataStore instead. If you still need to use AddressBook in your code, // be aware that you may encounter CI failures due to linting errors. // To work around this, you can disable the linter for that specific line using the //nolint directive. AddressBook AddressBook DataStore datastore.MutableDataStore // Reports are populated by the Operations API with the // results of the operations executed in the changeset. Reports []operations.Report[any, any] }
ChangesetOutput is the output of a Changeset function. Think of it like a state transition output. The address book here should contain only new addresses created in this changeset.
type ContractDeploy ¶ added in v0.0.12
type ContractDeploy[C any] struct { Address common.Address // We leave this incase a Go binding doesn't have Address() Contract C // Expected to be a Go binding Tx *types.Transaction // Incase the caller needs for example tx hash info for Tv TypeAndVersion Err error }
ContractDeploy represents the result of an EVM contract deployment via an abigen Go binding. It contains all the return values as they are useful in different ways.
func DeployContract ¶ added in v0.0.12
func DeployContract[C any]( lggr logger.Logger, chain cldf_evm.Chain, addressBook AddressBook, deploy func(chain cldf_evm.Chain) ContractDeploy[C], ) (*ContractDeploy[C], error)
DeployContract deploys an EVM contract and records the address in the provided address book if the deployment was confirmed onchain. Deploying and saving the address is a very common pattern so this helps to reduce boilerplate. It returns an error if the deployment failed, the tx was not confirmed or the address could not be saved.
type ContractType ¶
type ContractType string
ContractType is a simple string type for identifying contract types.
func (ContractType) String ¶
func (ct ContractType) String() string
type Environment ¶ added in v0.0.6
type Environment struct { Name string Logger logger.Logger // Deprecated: AddressBook is deprecated and will be removed in future versions. // Please use DataStore instead. If you still need to use AddressBook in your code, // be aware that you may encounter CI failures due to linting errors. // To work around this, you can disable the linter for that specific line using the //nolint directive. ExistingAddresses AddressBook DataStore datastore.DataStore Catalog datastore.CatalogStore NodeIDs []string Offchain offchain.Client GetContext func() context.Context OCRSecrets OCRSecrets // OperationsBundle contains dependencies required by the operations API. OperationsBundle operations.Bundle // BlockChains is the container of all chains in the environment. BlockChains chain.BlockChains }
Environment represents an instance of a deployed product including on and offchain components. It is intended to be cross-family to enable a coherent view of a product deployed to all its chains. TODO: Add SolChains, AptosChain etc. using Go bindings/libraries from their respective repositories i.e. chainlink-solana, chainlink-cosmos You can think of ExistingAddresses as a set of family agnostic "onchain pointers" meant to be used in conjunction with chain fields to read/write relevant chain state. Similarly, you can think of NodeIDs as "offchain pointers" to be used in conjunction with the Offchain client to read/write relevant offchain state (i.e. state in the DON(s)).
func NewEnvironment ¶ added in v0.0.6
func NewEnvironment( name string, logger logger.Logger, existingAddrs AddressBook, dataStore datastore.DataStore, nodeIDs []string, offchain offchain.Client, ctx func() context.Context, secrets OCRSecrets, blockChains chain.BlockChains, opts ...EnvironmentOption, ) *Environment
NewEnvironment creates a new environment for CLDF.
func (Environment) Clone ¶ added in v0.0.6
func (e Environment) Clone() Environment
Clone creates a copy of the environment with a new reference to the address book.
type EnvironmentOption ¶ added in v0.18.0
type EnvironmentOption func(*Environment)
EnvironmentOption is a functional option for configuring an Environment
func WithCatalog ¶ added in v0.18.0
func WithCatalog(catalog datastore.CatalogStore) EnvironmentOption
WithCatalog sets the catalog store for the environment
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) EstimateGas ¶ added in v0.0.8
func (mc *MultiClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)
func (*MultiClient) FilterLogs ¶ added in v0.0.8
func (*MultiClient) HeaderByNumber ¶ added in v0.0.8
func (*MultiClient) NonceAtHash ¶
func (*MultiClient) PendingCodeAt ¶ added in v0.0.8
func (*MultiClient) PendingNonceAt ¶ added in v0.0.8
func (*MultiClient) SendTransaction ¶
func (mc *MultiClient) SendTransaction(ctx context.Context, tx *types.Transaction) error
func (*MultiClient) SubscribeFilterLogs ¶ added in v0.0.8
func (*MultiClient) SuggestGasPrice ¶ added in v0.0.8
func (*MultiClient) SuggestGasTipCap ¶ added in v0.0.8
func (*MultiClient) WaitMined ¶
func (mc *MultiClient) WaitMined(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)
WaitMined waits for a transaction to be mined and returns the receipt. Note: retryConfig timeout settings are not used for this operation, a timeout can be set in the context.
type OCRSecrets ¶ added in v0.0.5
type OCRSecrets struct { EphemeralSk [32]byte }
OCRSecrets are used to disseminate a shared secret to OCR nodes through the blockchain where OCR configuration is stored. Its a low value secret used to derive transmission order etc. They are extracted here such that they can common across signers when multiple signers are signing the same OCR config.
func GenerateSharedSecrets ¶ added in v0.22.0
func GenerateSharedSecrets(xSigners, xProposers string) (OCRSecrets, error)
SharedSecrets generates shared secrets from the BIP39 mnemonic phrases for the OCR signers and proposers.
Lifted from here https://github.com/smartcontractkit/offchain-reporting/blob/14a57d70e50474a2104aa413214e464d6bc69e16/lib/offchainreporting/internal/config/shared_secret_test.go#L32 Historically signers (fixed secret) and proposers (ephemeral secret) were combined in this manner. We simply leave that as is.
func XXXGenerateTestOCRSecrets ¶ added in v0.0.5
func XXXGenerateTestOCRSecrets() OCRSecrets
func (OCRSecrets) IsEmpty ¶ added in v0.0.5
func (s OCRSecrets) IsEmpty() bool
type PreconditionVerifier ¶ added in v0.0.6
type PreconditionVerifier[C any] func(e Environment, config C) error
PreconditionVerifier functions should evaluate the supplied config, in the context of an environment, to ensure that the config struct is correct, and that the environmental preconditions are as expected. This is the standalone version of ChangeSetV2.VerifyPreconditions for use with CreateChangeSet
If the configuration is unexpected type or format, the changeset should return ErrInvalidConfig. If there are surprising aspects in the environment (a contract expected to be present cannot be located, etc.), then ErrInvalidEnvironment should be returned.
type ProposedJob ¶ added in v0.0.6
ProposedJob represents a job spec which has been proposed to a node, with the JobID returned by the Job Distributor.
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
type ViewState ¶ added in v0.0.6
type ViewState func(e Environment) (json.Marshaler, error)
ViewState produces a product specific JSON representation of the on and offchain state of the environment.