evm

package
v0.0.0-...-e69715a Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EClient

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

EClient defines typed wrappers for the Ethereum RPC API.

func Dial

func Dial(rawurl string) (*EClient, error)

Dial connects a client to the given URL.

func (*EClient) BlockByHash

func (ec *EClient) BlockByHash(ctx context.Context, hash string) (*xycommon.RpcBlock, 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.

func (*EClient) BlockByNumber

func (ec *EClient) BlockByNumber(ctx context.Context, number *big.Int) (*xycommon.RpcBlock, error)

BlockByNumber returns a block from the current canonical chain. If number is nil, the latest known block is returned.

Note that loading full blocks requires two requests. Use HeaderByNumber if you don't need all transactions or uncle headers.

func (*EClient) BlockNumber

func (ec *EClient) BlockNumber(ctx context.Context) (uint64, error)

BlockNumber returns the most recent block number

func (*EClient) ChainID

func (ec *EClient) ChainID(ctx context.Context) (*big.Int, error)

ChainID retrieves the current chain ID for transaction replay protection.

func (*EClient) Client

func (ec *EClient) Client() *rpc.Client

EClient gets the underlying RPC client.

func (*EClient) Close

func (ec *EClient) Close()

Close closes the underlying RPC connection.

func (*EClient) FilterLogs

func (ec *EClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]xycommon.RpcLog, error)

FilterLogs executes a filter query.

func (*EClient) HeaderByNumber

func (ec *EClient) HeaderByNumber(ctx context.Context, number *big.Int) (*xycommon.RpcHeader, error)

func (*EClient) SubscribeFilterLogs

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

SubscribeFilterLogs subscribes to the results of a streaming filter query.

func (*EClient) SubscribeNewHead

func (ec *EClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header, ct chan<- *xycommon.RpcBlock) (ethereum.Subscription, error)

SubscribeNewHead subscribes to notifications about the current blockchain head on the given channel.

func (*EClient) TransactionReceipt

func (ec *EClient) TransactionReceipt(ctx context.Context, txHashStr string) (*xycommon.RpcReceipt, error)

TransactionReceipt returns the receipt of a transaction by transaction hash. Note that the receipt is not available for pending transactions.

func (*EClient) TransactionSender

func (ec *EClient) TransactionSender(ctx context.Context, txHashStr, blockHashStr string, txIndex uint) (string, error)

TransactionSender returns the sender address of the given transaction. The transaction must be known to the remote node and included in the blockchain at the given block and index. The sender is the one derived by the protocol at the time of inclusion.

There is a fast-path for transactions retrieved by TransactionByHash and TransactionInBlock. Getting their sender address can be done without an RPC interaction.

type RawClient

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

RawClient defines typed wrappers for the Ethereum RPC API.

func DialContext

func DialContext(ctx context.Context, rawurl string) (*RawClient, error)

DialContext connects a client to the given URL with context.

func NewClient

func NewClient(c *rpc.Client) *RawClient

NewClient creates a client that uses the given RPC client.

func (*RawClient) BlockByHash

func (ec *RawClient) BlockByHash(ctx context.Context, hash common.Hash) (*RpcBlock, 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.

func (*RawClient) BlockByNumber

func (ec *RawClient) BlockByNumber(ctx context.Context, number *big.Int) (*RpcBlock, error)

BlockByNumber returns a block from the current canonical chain. If number is nil, the latest known block is returned.

Note that loading full blocks requires two requests. Use HeaderByNumber if you don't need all transactions or uncle headers.

func (*RawClient) BlockNumber

func (ec *RawClient) BlockNumber(ctx context.Context) (uint64, error)

BlockNumber returns the most recent block number

func (*RawClient) CallContext

func (ec *RawClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) (err error)

func (*RawClient) ChainID

func (ec *RawClient) ChainID(ctx context.Context) (*big.Int, error)

ChainID retrieves the current chain ID for transaction replay protection.

func (*RawClient) Client

func (ec *RawClient) Client() *rpc.Client

Client gets the underlying RPC client.

func (*RawClient) Close

func (ec *RawClient) Close()

Close closes the underlying RPC connection.

func (*RawClient) FilterLogs

func (ec *RawClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]RpcLog, error)

FilterLogs executes a filter query.

func (*RawClient) HeaderByNumber

func (ec *RawClient) HeaderByNumber(ctx context.Context, number *big.Int) (*RpcHeader, error)

func (*RawClient) IsContract

func (ec *RawClient) IsContract(ctx context.Context, address common.Address) (ok bool, err error)

func (*RawClient) SubscribeFilterLogs

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

SubscribeFilterLogs subscribes to the results of a streaming filter query.

func (*RawClient) SubscribeNewHead

func (ec *RawClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)

SubscribeNewHead subscribes to notifications about the current blockchain head on the given channel.

func (*RawClient) TransactionByHash

func (ec *RawClient) TransactionByHash(ctx context.Context, hash common.Hash) (tx *RpcTransaction, isPending bool, err error)

func (*RawClient) TransactionReceipt

func (ec *RawClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*RpcReceipt, error)

TransactionReceipt returns the receipt of a transaction by transaction hash. Note that the receipt is not available for pending transactions.

func (*RawClient) TransactionSender

func (ec *RawClient) TransactionSender(ctx context.Context, txHash common.Hash, blockHash common.Hash, txIndex uint) (common.Address, error)

TransactionSender returns the sender address of the given transaction. The transaction must be known to the remote node and included in the blockchain at the given block and index. The sender is the one derived by the protocol at the time of inclusion.

There is a fast-path for transactions retrieved by TransactionByHash and TransactionInBlock. Getting their sender address can be done without an RPC interaction.

type RpcBlock

type RpcBlock struct {
	ParentHash common.Hash    `json:"parentHash"       gencodec:"required"`
	Coinbase   common.Address `json:"miner"`
	Bloom      types.Bloom    `json:"logsBloom"        gencodec:"required"`
	Number     *hexutil.Big   `json:"number"           gencodec:"required"`
	GasLimit   *hexutil.Big   `json:"gasLimit"         gencodec:"required"`
	GasUsed    *hexutil.Big   `json:"gasUsed"          gencodec:"required"`
	Time       hexutil.Uint64 `json:"timestamp"`

	TxHash       common.Hash       `json:"transactionsRoot" gencodec:"required"`
	Hash         common.Hash       `json:"hash"`
	Transactions []*RpcTransaction `json:"transactions"`
	TraceId      string            `json:"-"`
}

type RpcHeader

type RpcHeader struct {
	ParentHash common.Hash    `json:"parentHash"       gencodec:"required"`
	Coinbase   common.Address `json:"miner"`
	Bloom      types.Bloom    `json:"logsBloom"        gencodec:"required"`
	Number     *hexutil.Big   `json:"number"           gencodec:"required"`
	GasLimit   *hexutil.Big   `json:"gasLimit"         gencodec:"required"`
	GasUsed    *hexutil.Big   `json:"gasUsed"          gencodec:"required"`
	Time       hexutil.Uint64 `json:"timestamp"`
	TxHash     common.Hash    `json:"transactionsRoot" gencodec:"required"`
	Hash       common.Hash    `json:"hash"`
}

type RpcLog

type RpcLog 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 hexutil.Bytes `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 *hexutil.Big `json:"blockNumber"`
	// hash of the transaction
	TxHash common.Hash `json:"transactionHash" gencodec:"required"`
	// index of the transaction in the block
	TxIndex *hexutil.Big `json:"transactionIndex"`
	// hash of the block in which the transaction was included
	BlockHash common.Hash `json:"blockHash"`
	// index of the xylog in the block
	Index *hexutil.Big `json:"logIndex"`

	// The Removed field is true if this xylog 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"`
}

type RpcReceipt

type RpcReceipt struct {
	// Consensus fields: These fields are defined by the Yellow Paper
	Type              *hexutil.Big  `json:"type,omitempty"`
	PostState         hexutil.Bytes `json:"root"`
	Status            *hexutil.Big  `json:"status"`
	CumulativeGasUsed *hexutil.Big  `json:"cumulativeGasUsed" gencodec:"required"`
	Logs              []*RpcLog     `json:"logs"              gencodec:"required"`

	// Implementation fields: These fields are added by geth when processing a transaction.
	TxHash            common.Hash     `json:"transactionHash" gencodec:"required"`
	ContractAddress   *common.Address `json:"contractAddress"`
	GasUsed           *hexutil.Big    `json:"gasUsed" gencodec:"required"`
	EffectiveGasPrice *hexutil.Big    `json:"effectiveGasPrice"` // required, but tag omitted for backwards compatibility

	// Inclusion information: These fields provide information about the inclusion of the
	// transaction corresponding to this receipt.
	BlockHash        common.Hash  `json:"blockHash,omitempty"`
	BlockNumber      *hexutil.Big `json:"blockNumber,omitempty"`
	TransactionIndex *hexutil.Big `json:"transactionIndex"`
}

RpcReceipt represents the results of a transaction.

type RpcTransaction

type RpcTransaction struct {
	BlockHash   common.Hash     `json:"blockHash"`
	BlockNumber *hexutil.Big    `json:"blockNumber"`
	TxIndex     *hexutil.Big    `json:"transactionIndex"`
	Type        *hexutil.Big    `json:"type"`
	Hash        common.Hash     `json:"hash"`
	ChainID     *hexutil.Big    `json:"chainId,omitempty"`
	From        *common.Address `json:"from"`
	To          *common.Address `json:"to"`
	Input       string          `json:"input"`
	Value       *hexutil.Big    `json:"value"`

	Gas                  hexutil.Uint64 `json:"gas"`
	GasPrice             *hexutil.Big   `json:"gasPrice"`
	MaxPriorityFeePerGas *hexutil.Big   `json:"maxPriorityFeePerGas"`
	MaxFeePerGas         *hexutil.Big   `json:"maxFeePerGas"`
	MaxFeePerDataGas     *hexutil.Big   `json:"maxFeePerDataGas,omitempty"`
}

Jump to

Keyboard shortcuts

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