eth

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustGetV6ContractEventID added in v0.8.8

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.

Types

type CallArgs added in v0.8.8

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

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 added in v0.8.8

type CallerSubscriber interface {
	Call(result interface{}, method string, args ...interface{}) error
	Subscribe(context.Context, interface{}, ...interface{}) (Subscription, error)
	GethClient(func(gethClient GethClient) error) 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 added in v0.8.8

type CallerSubscriberClient struct {
	CallerSubscriber
}

CallerSubscriberClient implements the ethereum Client interface using a CallerSubscriber instance.

func (*CallerSubscriberClient) GetBlockByNumber added in v0.8.8

func (client *CallerSubscriberClient) GetBlockByNumber(hex string) (models.Block, error)

GetBlockByNumber returns the block for the passed hex, or "latest", "earliest", "pending". Includes all transactions

func (*CallerSubscriberClient) GetBlockHeight added in v0.8.8

func (client *CallerSubscriberClient) GetBlockHeight() (uint64, error)

func (*CallerSubscriberClient) GetChainID added in v0.8.8

func (client *CallerSubscriberClient) GetChainID() (*big.Int, error)

GetChainID returns the ethereum ChainID.

func (*CallerSubscriberClient) GetERC20Balance added in v0.8.8

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 added in v0.8.8

func (client *CallerSubscriberClient) GetEthBalance(address common.Address) (*assets.Eth, error)

GetEthBalance returns the balance of the given addresses in Ether.

func (*CallerSubscriberClient) GetLatestBlock added in v0.8.8

func (client *CallerSubscriberClient) GetLatestBlock() (models.Block, error)

GetLatestBlock returns the last committed block of the best blockchain the blockchain node is aware of.

func (*CallerSubscriberClient) GetLogs added in v0.8.8

func (client *CallerSubscriberClient) GetLogs(q ethereum.FilterQuery) ([]models.Log, error)

GetLogs returns all logs that respect the passed filter query.

func (*CallerSubscriberClient) GetNonce added in v0.8.8

func (client *CallerSubscriberClient) GetNonce(address common.Address) (uint64, error)

GetNonce returns the nonce (transaction count) for a given address.

func (*CallerSubscriberClient) GetTxReceipt added in v0.8.8

func (client *CallerSubscriberClient) GetTxReceipt(hash common.Hash) (*models.TxReceipt, error)

GetTxReceipt returns the transaction receipt for the given transaction hash.

func (*CallerSubscriberClient) SendRawTx added in v0.8.8

func (client *CallerSubscriberClient) SendRawTx(bytes []byte) (common.Hash, error)

SendRawTx sends a signed transaction to the transaction pool.

func (*CallerSubscriberClient) SubscribeToLogs added in v0.8.8

func (client *CallerSubscriberClient) SubscribeToLogs(
	ctx context.Context,
	channel chan<- models.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 added in v0.8.8

func (client *CallerSubscriberClient) SubscribeToNewHeads(
	ctx context.Context,
	channel chan<- gethTypes.Header,
) (Subscription, error)

SubscribeToNewHeads registers a subscription for push notifications of new blocks.

type Client added in v0.8.8

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) (*models.TxReceipt, error)
	GetBlockHeight() (uint64, error)
	GetLatestBlock() (models.Block, error)
	GetBlockByNumber(hex string) (models.Block, error)
	GetChainID() (*big.Int, error)
	SubscribeToNewHeads(ctx context.Context, channel chan<- gethTypes.Header) (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 added in v0.8.8

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

func GetContractCodec added in v0.8.8

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 added in v0.8.8

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 added in v0.8.8

type GethClient interface {
	SendTransaction(context.Context, *gethTypes.Transaction) error
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*gethTypes.Receipt, error)
	HeaderByNumber(ctx context.Context, n *big.Int) (*gethTypes.Header, 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 added in v0.8.3

type LogBroadcast interface {
	Log() interface{}
	UpdateLog(models.RawLog)
	WasAlreadyConsumed() (bool, error)
	MarkConsumed() error
}

The LogBroadcast type wraps an 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()
	Register(address common.Address, listener LogListener) (connected bool)
	Unregister(address common.Address, listener LogListener)
	Stop()
}

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 orm, 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
}

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 LogSubscriber added in v0.8.8

type LogSubscriber interface {
	GetLogs(q ethereum.FilterQuery) ([]models.Log, error)
	SubscribeToLogs(ctx context.Context, channel chan<- models.Log, q ethereum.FilterQuery) (Subscription, error)
}

LogSubscriber encapsulates only the methods needed for subscribing to ethereum log events.

type ManagedSubscription added in v0.8.3

type ManagedSubscription interface {
	Err() <-chan error
	Logs() chan models.Log
	Unsubscribe()
}

A ManagedSubscription acts as wrapper for the Subscription. Specifically, the ManagedSubscription closes the log channel as soon as the unsubscribe request is made

type Subscription added in v0.8.8

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 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