Documentation ¶
Index ¶
- Constants
- Variables
- func MustGetV6ContractEventID(name, eventName string) common.Hash
- type Block
- type BlockHeader
- type CallArgs
- type CallerSubscriber
- type CallerSubscriberClient
- func (client *CallerSubscriberClient) GetBlockByNumber(hex string) (Block, error)
- func (client *CallerSubscriberClient) GetBlockHeight() (uint64, error)
- func (client *CallerSubscriberClient) GetChainID() (*big.Int, error)
- func (client *CallerSubscriberClient) GetERC20Balance(address common.Address, contractAddress common.Address) (*big.Int, error)
- func (client *CallerSubscriberClient) GetEthBalance(address common.Address) (*assets.Eth, error)
- func (client *CallerSubscriberClient) GetLatestBlock() (Block, error)
- func (client *CallerSubscriberClient) GetLogs(q ethereum.FilterQuery) ([]Log, error)
- func (client *CallerSubscriberClient) GetNonce(address common.Address) (uint64, error)
- func (client *CallerSubscriberClient) GetTxReceipt(hash common.Hash) (*TxReceipt, error)
- func (client *CallerSubscriberClient) SendRawTx(bytes []byte) (common.Hash, error)
- func (client *CallerSubscriberClient) SubscribeToLogs(ctx context.Context, channel chan<- Log, q ethereum.FilterQuery) (Subscription, error)
- func (client *CallerSubscriberClient) SubscribeToNewHeads(ctx context.Context, channel chan<- BlockHeader) (Subscription, error)
- type Client
- type ContractCodec
- type FunctionSelector
- func (f FunctionSelector) Bytes() []byte
- func (f FunctionSelector) MarshalJSON() ([]byte, error)
- func (f FunctionSelector) Scan(value interface{}) error
- func (f *FunctionSelector) SetBytes(b []byte)
- func (f FunctionSelector) String() string
- func (f *FunctionSelector) UnmarshalJSON(input []byte) error
- func (f FunctionSelector) Value() (driver.Value, error)
- func (f FunctionSelector) WithoutPrefix() string
- type Log
- type LogSubscriber
- type RawLog
- type Subscription
- type Transaction
- type TxReceipt
- type UntrustedBytes
Constants ¶
const FunctionSelectorLength = 4
FunctionSelectorLength should always be a length of 4 as a byte.
Variables ¶
var ChainlinkFulfilledTopic = utils.MustHash("ChainlinkFulfilled(bytes32)")
ChainlinkFulfilledTopic is the signature for the event emitted after calling ChainlinkClient.validateChainlinkCallback(requestId). See ../../evm-contracts/src/v0.6/ChainlinkClient.sol
WeiPerEth is amount of Wei currency units in one Eth.
Functions ¶
func MustGetV6ContractEventID ¶
MustGetV6ContractEventID finds the event for the given contract by searching embedded contract assets from evm/, or panics if not found.
Types ¶
type Block ¶
type Block struct { Number hexutil.Uint64 `json:"number"` Transactions []Transaction `json:"transactions"` }
Block represents a full block See: https://github.com/ethereum/go-ethereum/blob/0e6ea9199ca701ee4c96220e873884327c8d18ff/core/types/block.go#L147
type BlockHeader ¶
type BlockHeader struct { ParentHash common.Hash `json:"parentHash"` UncleHash common.Hash `json:"sha3Uncles"` Coinbase common.Address `json:"miner"` Root common.Hash `json:"stateRoot"` TxHash common.Hash `json:"transactionsRoot"` ReceiptHash common.Hash `json:"receiptsRoot"` Bloom types.Bloom `json:"logsBloom"` Difficulty hexutil.Big `json:"difficulty"` Number hexutil.Big `json:"number"` GasLimit hexutil.Uint64 `json:"gasLimit"` GasUsed hexutil.Uint64 `json:"gasUsed"` Time hexutil.Big `json:"timestamp"` Extra hexutil.Bytes `json:"extraData"` Nonce types.BlockNonce `json:"nonce"` GethHash common.Hash `json:"mixHash"` ParityHash common.Hash `json:"hash"` }
BlockHeader represents a block header in the Ethereum blockchain. Deliberately does not have required fields because some fields aren't present depending on the Ethereum node. i.e. Parity does not always send mixHash
func (BlockHeader) Hash ¶
func (h BlockHeader) Hash() common.Hash
Hash will return GethHash if it exists otherwise it returns the ParityHash
type CallArgs ¶
CallArgs represents the data used to call the balance method of an ERC contract. "To" is the address of the ERC contract. "Data" is the message sent to the contract.
type CallerSubscriber ¶
type CallerSubscriber interface { Call(result interface{}, method string, args ...interface{}) error Subscribe(context.Context, interface{}, ...interface{}) (Subscription, error) }
CallerSubscriber implements the Call and Subscribe functions. Call performs a JSON-RPC call with the given arguments and Subscribe registers a subscription, using an open stream to receive updates from ethereum node.
type CallerSubscriberClient ¶
type CallerSubscriberClient struct {
CallerSubscriber
}
CallerSubscriberClient implements the ethereum Client interface using a CallerSubscriber instance.
func (*CallerSubscriberClient) GetBlockByNumber ¶
func (client *CallerSubscriberClient) GetBlockByNumber(hex string) (Block, error)
GetBlockByNumber returns the block for the passed hex, or "latest", "earliest", "pending". Includes all transactions
func (*CallerSubscriberClient) GetBlockHeight ¶
func (client *CallerSubscriberClient) GetBlockHeight() (uint64, error)
func (*CallerSubscriberClient) GetChainID ¶
func (client *CallerSubscriberClient) GetChainID() (*big.Int, error)
GetChainID returns the ethereum ChainID.
func (*CallerSubscriberClient) GetERC20Balance ¶
func (client *CallerSubscriberClient) GetERC20Balance(address common.Address, contractAddress common.Address) (*big.Int, error)
GetERC20Balance returns the balance of the given address for the token contract address.
func (*CallerSubscriberClient) GetEthBalance ¶
GetEthBalance returns the balance of the given addresses in Ether.
func (*CallerSubscriberClient) GetLatestBlock ¶ added in v0.8.3
func (client *CallerSubscriberClient) GetLatestBlock() (Block, error)
func (*CallerSubscriberClient) GetLogs ¶
func (client *CallerSubscriberClient) GetLogs(q ethereum.FilterQuery) ([]Log, error)
GetLogs returns all logs that respect the passed filter query.
func (*CallerSubscriberClient) GetNonce ¶
func (client *CallerSubscriberClient) GetNonce(address common.Address) (uint64, error)
GetNonce returns the nonce (transaction count) for a given address.
func (*CallerSubscriberClient) GetTxReceipt ¶
func (client *CallerSubscriberClient) GetTxReceipt(hash common.Hash) (*TxReceipt, error)
GetTxReceipt returns the transaction receipt for the given transaction hash.
func (*CallerSubscriberClient) SendRawTx ¶
func (client *CallerSubscriberClient) SendRawTx(bytes []byte) (common.Hash, error)
SendRawTx sends a signed transaction to the transaction pool.
func (*CallerSubscriberClient) SubscribeToLogs ¶
func (client *CallerSubscriberClient) SubscribeToLogs( ctx context.Context, channel chan<- Log, q ethereum.FilterQuery, ) (Subscription, error)
SubscribeToLogs registers a subscription for push notifications of logs from a given address.
Inspired by the eth client's SubscribeToLogs: https://github.com/ethereum/go-ethereum/blob/762f3a48a00da02fe58063cb6ce8dc2d08821f15/ethclient/ethclient.go#L359
func (*CallerSubscriberClient) SubscribeToNewHeads ¶
func (client *CallerSubscriberClient) SubscribeToNewHeads( ctx context.Context, channel chan<- BlockHeader, ) (Subscription, error)
SubscribeToNewHeads registers a subscription for push notifications of new blocks.
type Client ¶
type Client interface { CallerSubscriber LogSubscriber GetNonce(address common.Address) (uint64, error) GetEthBalance(address common.Address) (*assets.Eth, error) GetERC20Balance(address common.Address, contractAddress common.Address) (*big.Int, error) SendRawTx(bytes []byte) (common.Hash, error) GetTxReceipt(hash common.Hash) (*TxReceipt, error) GetBlockHeight() (uint64, error) GetLatestBlock() (Block, error) GetBlockByNumber(hex string) (Block, error) GetChainID() (*big.Int, error) SubscribeToNewHeads(ctx context.Context, channel chan<- BlockHeader) (Subscription, error) }
Client is the interface used to interact with an ethereum node.
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 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 FunctionSelector ¶
type FunctionSelector [FunctionSelectorLength]byte
FunctionSelector is the first four bytes of the call data for a function call and specifies the function to be called.
func BytesToFunctionSelector ¶
func BytesToFunctionSelector(b []byte) FunctionSelector
BytesToFunctionSelector converts the given bytes to a FunctionSelector.
func HexToFunctionSelector ¶
func HexToFunctionSelector(s string) FunctionSelector
HexToFunctionSelector converts the given string to a FunctionSelector.
func (FunctionSelector) Bytes ¶
func (f FunctionSelector) Bytes() []byte
Bytes returns the FunctionSelector as a byte slice
func (FunctionSelector) MarshalJSON ¶
func (f FunctionSelector) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of f
func (FunctionSelector) Scan ¶
func (f FunctionSelector) Scan(value interface{}) error
Scan returns the selector from its serialization in the database
func (*FunctionSelector) SetBytes ¶
func (f *FunctionSelector) SetBytes(b []byte)
SetBytes sets the FunctionSelector to that of the given bytes (will trim).
func (FunctionSelector) String ¶
func (f FunctionSelector) String() string
String returns the FunctionSelector as a string type.
func (*FunctionSelector) UnmarshalJSON ¶
func (f *FunctionSelector) UnmarshalJSON(input []byte) error
UnmarshalJSON parses the raw FunctionSelector and sets the FunctionSelector type to the given input.
func (FunctionSelector) Value ¶
func (f FunctionSelector) Value() (driver.Value, error)
Value returns this instance serialized for database storage
func (FunctionSelector) WithoutPrefix ¶
func (f FunctionSelector) WithoutPrefix() string
WithoutPrefix returns the FunctionSelector as a string without the '0x' prefix.
type Log ¶
type Log struct { // Consensus fields: // address of the contract that generated the event Address common.Address `json:"address" gencodec:"required"` // list of topics provided by the contract. Topics []common.Hash `json:"topics" gencodec:"required"` // supplied by the contract, usually ABI-encoded Data UntrustedBytes `json:"data" gencodec:"required"` // Derived fields. These fields are filled in by the node // but not secured by consensus. // block in which the transaction was included BlockNumber uint64 `json:"blockNumber"` // hash of the transaction TxHash common.Hash `json:"transactionHash"` // index of the transaction in the block TxIndex uint `json:"transactionIndex"` // hash of the block in which the transaction was included BlockHash common.Hash `json:"blockHash"` // index of the log in the receipt Index uint `json:"logIndex"` // The Removed field is true if this log was reverted due to a chain reorganisation. // You must pay attention to this field if you receive logs through a filter query. Removed bool `json:"removed"` }
Log represents a contract log event. These events are generated by the LOG opcode and stored/indexed by the node. NOTE: This is almost (but not quite) a copy of go-ethereum/core/types.Log, in log.go
func (Log) Copy ¶
Copy creates a deep copy of a log. The LogBroadcaster creates a single websocket subscription for all log events that we're interested in and distributes them to the relevant subscribers elsewhere in the codebase. If a given log needs to be distributed to multiple subscribers while avoiding data races, it's necessary to make copies.
func (Log) GetBlockHash ¶ added in v0.8.3
GetBlockHash returns the log's blockhash
func (*Log) UnmarshalJSON ¶
UnmarshalJSON unmarshals from JSON.
type LogSubscriber ¶
type LogSubscriber interface { GetLogs(q ethereum.FilterQuery) ([]Log, error) SubscribeToLogs(ctx context.Context, channel chan<- Log, q ethereum.FilterQuery) (Subscription, error) }
LogSubscriber encapsulates only the methods needed for subscribing to ethereum log events.
type RawLog ¶ added in v0.8.3
The RawLog interface provides a consistent interface for different log types around the app
type Subscription ¶
type Subscription interface { Err() <-chan error Unsubscribe() }
Subscription holds the methods for an ethereum log subscription.
The Unsubscribe method cancels the sending of events. You must call Unsubscribe in all cases to ensure that resources related to the subscription are released. It can be called any number of times.
type Transaction ¶
type TxReceipt ¶
type TxReceipt struct { BlockNumber *utils.Big `json:"blockNumber"` BlockHash *common.Hash `json:"blockHash"` Hash common.Hash `json:"transactionHash"` Logs []Log `json:"logs"` }
TxReceipt holds the block number and the transaction hash of a signed transaction that has been written to the blockchain.
func (TxReceipt) FulfilledRunLog ¶
FulfilledRunLog returns true if this tx receipt is the result of a fulfilled run log.
func (*TxReceipt) Unconfirmed ¶
Unconfirmed returns true if the transaction is not confirmed.
type UntrustedBytes ¶
type UntrustedBytes []byte
This data can contain anything and is submitted by user on-chain, so we must be extra careful how we interact with it
func (UntrustedBytes) SafeByteSlice ¶
func (ary UntrustedBytes) SafeByteSlice(start int, end int) ([]byte, error)
SafeByteSlice returns an error on out of bounds access to a byte array, where a normal slice would panic instead