eth

package
v0.0.0-...-e348512 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsParityQueriedReceiptTooEarly

func IsParityQueriedReceiptTooEarly(e error) bool

Parity can return partially hydrated Log entries if you query a receipt while the transaction is still in the mempool. Go-ethereum's built-in client raises an error since this is a required field. There is no easy way to ignore the error or pass in a custom struct, so we use this hack to detect it instead.

func MustGetV6ContractEventID

func MustGetV6ContractEventID(name, eventName string) common.Hash

MustGetV6ContractEventID finds the event for the given contract by searching embedded contract assets from evm/, or panics if not found.

func NewClient

func NewClient(rpcUrl string, secondaryRPCURLs ...string) (*client, error)

func NewClientWith

func NewClientWith(rpcClient RPCClient, gethClient GethClient) *client

This alternate constructor exists for testing purposes.

Types

type CallArgs

type CallArgs struct {
	To   common.Address `json:"to"`
	Data hexutil.Bytes  `json:"data"`
}

CallArgs represents the data used to call the balance method of a contract. "To" is the address of the ERC contract. "Data" is the message sent to the contract.

type Client

type Client interface {
	GethClient

	Dial(ctx context.Context) error
	Close()

	GetERC20Balance(address common.Address, contractAddress common.Address) (*big.Int, error)
	GetLINKBalance(linkAddress common.Address, address common.Address) (*assets.Link, error)

	SendRawTx(bytes []byte) (common.Hash, error)
	Call(result interface{}, method string, args ...interface{}) error
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

	// These methods are reimplemented due to a difference in how block header hashes are
	// calculated by Parity nodes running on Kovan.  We have to return our own wrapper
	// type to capture the correct hash from the RPC response.
	HeaderByNumber(ctx context.Context, n *big.Int) (*models.Head, error)
	SubscribeNewHead(ctx context.Context, ch chan<- *models.Head) (ethereum.Subscription, error)
}

Client is the interface used to interact with an ethereum node.

type ConnectedContract

type ConnectedContract interface {
	ContractCodec
	Call(result interface{}, methodName string, args ...interface{}) error
	SubscribeToLogs(listener LogListener) (connected bool, _ UnsubscribeFunc)
}

func NewConnectedContract

func NewConnectedContract(
	codec ContractCodec,
	address common.Address,
	ethClient Client,
	logBroadcaster LogBroadcaster,
) ConnectedContract

type ContractCodec

type ContractCodec interface {
	ABI() *abi.ABI
	GetMethodID(method string) ([]byte, error)
	EncodeMessageCall(method string, args ...interface{}) ([]byte, error)
	UnpackLog(out interface{}, event string, log types.Log) error
}

func GetContractCodec

func GetContractCodec(name string) (ContractCodec, error)

GetContract loads the contract JSON file from ../../evm-contracts/abi/v0.4 and parses the ABI JSON contents into an abi.ABI object

NB: These contracts can be built by running

yarn setup:contracts

in the base project directory.

func GetV6ContractCodec

func GetV6ContractCodec(name string) (ContractCodec, error)

GetV6Contract loads the contract JSON file from ../../evm-contracts/abi/v0.6 and parses the ABI JSON contents into an abi.ABI object

NB: These contracts can be built by running

yarn setup:contracts

in the base project directory.

type GethClient

type GethClient interface {
	ChainID(ctx context.Context) (*big.Int, error)
	SendTransaction(ctx context.Context, tx *types.Transaction) error
	PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
	EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
}

GethClient is an interface that represents go-ethereum's own ethclient https://github.com/ethereum/go-ethereum/blob/master/ethclient/ethclient.go

type LogBroadcast

type LogBroadcast interface {
	DecodedLog() interface{}
	RawLog() types.Log
	SetDecodedLog(interface{})
	WasAlreadyConsumed() (bool, error)
	MarkConsumed() error
}

The LogBroadcast type wraps a models.Log but provides additional functionality for determining whether or not the log has been consumed and for marking the log as consumed

type LogBroadcaster

type LogBroadcaster interface {
	utils.DependentAwaiter
	Start() error
	Stop() error
	Register(address common.Address, listener LogListener) (connected bool)
	Unregister(address common.Address, listener LogListener)
}

The LogBroadcaster manages log subscription requests for the Chainlink node. Instead of creating a new websocket subscription for each request, it multiplexes all subscriptions to all of the relevant contracts over a single connection and forwards the logs to the relevant subscribers.

func NewLogBroadcaster

func NewLogBroadcaster(ethClient Client, orm ormInterface, backfillDepth uint64) LogBroadcaster

NewLogBroadcaster creates a new instance of the logBroadcaster

type LogListener

type LogListener interface {
	OnConnect()
	OnDisconnect()
	HandleLog(lb LogBroadcast, err error)
	JobID() *models.ID
	JobIDV2() int32
	IsV2Job() bool
}

The LogListener responds to log events through HandleLog, and contains setup/tear-down callbacks in the On* functions.

func NewDecodingLogListener

func NewDecodingLogListener(codec ContractCodec, nativeLogTypes map[common.Hash]interface{}, innerListener LogListener) LogListener

NewDecodingLogListener creates a new decodingLogListener

type MaybeHeader

type MaybeHeader struct {
	Header models.Head
	Error  error
}

type NullClient

type NullClient struct{}

NullClient satisfies the Client but has no side effects

func (*NullClient) BalanceAt

func (nc *NullClient) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)

func (*NullClient) BlockByNumber

func (nc *NullClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)

func (*NullClient) Call

func (nc *NullClient) Call(result interface{}, method string, args ...interface{}) error

func (*NullClient) CallContext

func (nc *NullClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

func (*NullClient) CallContract

func (nc *NullClient) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

func (*NullClient) ChainID

func (nc *NullClient) ChainID(ctx context.Context) (*big.Int, error)

func (*NullClient) Close

func (nc *NullClient) Close()

func (*NullClient) CodeAt

func (nc *NullClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)

func (*NullClient) Dial

func (nc *NullClient) Dial(ctx context.Context) error

func (*NullClient) EstimateGas

func (nc *NullClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)

func (*NullClient) FilterLogs

func (nc *NullClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)

func (*NullClient) GetERC20Balance

func (nc *NullClient) GetERC20Balance(address common.Address, contractAddress common.Address) (*big.Int, error)

func (*NullClient) GetLINKBalance

func (nc *NullClient) GetLINKBalance(linkAddress common.Address, address common.Address) (*assets.Link, error)

func (*NullClient) HeaderByNumber

func (nc *NullClient) HeaderByNumber(ctx context.Context, n *big.Int) (*models.Head, error)

func (*NullClient) PendingCodeAt

func (nc *NullClient) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

func (*NullClient) PendingNonceAt

func (nc *NullClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*NullClient) SendRawTx

func (nc *NullClient) SendRawTx(bytes []byte) (common.Hash, error)

func (*NullClient) SendTransaction

func (nc *NullClient) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (*NullClient) SubscribeFilterLogs

func (nc *NullClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

func (*NullClient) SubscribeNewHead

func (nc *NullClient) SubscribeNewHead(ctx context.Context, ch chan<- *models.Head) (ethereum.Subscription, error)

func (*NullClient) SuggestGasPrice

func (nc *NullClient) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*NullClient) TransactionReceipt

func (nc *NullClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

type RPCClient

type RPCClient interface {
	Call(result interface{}, method string, args ...interface{}) error
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
	BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
	EthSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (ethereum.Subscription, error)
	Close()
}

RPCClient is an interface that represents go-ethereum's own rpc.Client. https://github.com/ethereum/go-ethereum/blob/master/rpc/client.go

type SendError

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

fatal means this transaction can never be accepted even with a different nonce or higher gas price

func NewFatalSendError

func NewFatalSendError(e error) *SendError

func NewFatalSendErrorS

func NewFatalSendErrorS(s string) *SendError

func NewSendError

func NewSendError(e error) *SendError

func NewSendErrorS

func NewSendErrorS(s string) *SendError

func (*SendError) Error

func (s *SendError) Error() string

func (*SendError) Fatal

func (s *SendError) Fatal() bool

Fatal indicates whether the error should be considered fatal or not Fatal errors mean that no matter how many times the send is retried, no node will ever accept it

func (*SendError) IsInsufficientEth

func (s *SendError) IsInsufficientEth() bool

func (*SendError) IsNonceTooLowError

func (s *SendError) IsNonceTooLowError() bool

func (*SendError) IsReplacementUnderpriced

func (s *SendError) IsReplacementUnderpriced() bool

IsReplacementUnderpriced indicates that a transaction already exists in the mempool with this nonce but a different gas price or payload

func (*SendError) IsTemporarilyUnderpriced

func (s *SendError) IsTemporarilyUnderpriced() bool

func (*SendError) IsTerminallyUnderpriced

func (s *SendError) IsTerminallyUnderpriced() bool

IsTerminallyUnderpriced indicates that this transaction is so far underpriced the node won't even accept it in the first place

func (*SendError) IsTransactionAlreadyInMempool

func (s *SendError) IsTransactionAlreadyInMempool() bool

Geth/parity returns this error if the transaction is already in the node's mempool

func (*SendError) StrPtr

func (s *SendError) StrPtr() *string

type Subscription

type Subscription interface {
	Err() <-chan error
	Unsubscribe()
}

This interface only exists so that we can generate a mock for it. It is identical to `ethereum.Subscription`.

type UnsubscribeFunc

type UnsubscribeFunc func()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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