listener

package module
v0.0.0-...-5d19a40 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: LGPL-3.0 Imports: 8 Imported by: 0

README

listener

event listener for smart contracts

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contract

type Contract struct {
	Name    string
	ABI     abi.ABI
	Address common.Address
	// contains filtered or unexported fields
}

func NewContract

func NewContract(name string, abiJSON string, address common.Address) (*Contract, error)

type ContractEvent

type ContractEvent struct {
	// block in which the transaction was included
	BlockNumber uint64
	// hash of the block in which the transaction was included
	BlockHash common.Hash
	// hash of the transaction
	TxHash common.Hash

	// contract which the event belongs to
	Contract *Contract
	// name of the contract event
	Name string
	// supplied by the contract, usually ABI-encoded
	Data []byte

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

type EthClient

type EthClient interface {
	// SubscribeNewHead subscribes to notifications about the current blockchain head
	// on the given channel.
	SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
	// FilterLogs executes a filter query.
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
	// SubscribeFilterLogs subscribes to the results of a streaming filter query.
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
	// TransactionReceipt returns the receipt of a transaction by transaction hash.
	// Note that the receipt is not available for pending transactions.
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	// BlockByHash returns the given full block.
	//
	// Note that loading full blocks requires two requests. Use HeaderByHash
	// if you don't need all transactions or uncle headers.
	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
}

type EventListener

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

func NewEventListener

func NewEventListener(client EthClient,
	contracts []*Contract) *EventListener

func (*EventListener) Listen

func (el *EventListener) Listen(fromBlock *big.Int, eventCh chan<- *ContractEvent, stop <-chan struct{}) error

func (*EventListener) Parse

func (el *EventListener) Parse(l types.Log) *ContractEvent

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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