ethx

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(numLike ...any) *big.Int

func Address

func Address(addressLike any) common.Address

Address addressLike is non-nil

func AddressSlice

func AddressSlice(addressLikeArr any) (addresses []common.Address)

AddressSlice parse any to []common.Address

func BigInt

func BigInt(numLike any) *big.Int

func BigIntSlice

func BigIntSlice(bigLikeArr any) (bigInts []*big.Int)

BigIntSlice parse any to []*big.Int

func CheckRpcConn

func CheckRpcConn(rpcLike ...string) (reliableRpcList, badRpcList []string, reliableClients []*ethclient.Client, reliableRpcMap map[*ethclient.Client]string)

CheckRpcConn returns what rpcs are reliable and what rpcs are bad example:

  1. CheckRpcConn("https://bsc-dataseed1.defibit.io", "https://bsc-dataseed4.binance.org")
  2. CheckRpcConn("https://bsc-dataseed1.defibit.io\t29599361\t1.263s\t\t\nConnect Wallet\nhttps://bsc-dataseed4.binance.org") // auto resolve rpc list

func CheckRpcSpeed

func CheckRpcSpeed(rpcLike ...string) (rpcSpeedMap map[string]time.Duration)

CheckRpcSpeed returns the rpc speed list example:

  1. CheckRpcSpeed("https://bsc-dataseed1.defibit.io", "https://bsc-dataseed4.binance.org")
  2. CheckRpcSpeed("https://bsc-dataseed1.defibit.io\t29599361\t1.263s\t\t\nConnect Wallet\nhttps://bsc-dataseed4.binance.org")

func Div

func Div(numLike0, numLike1 any) *big.Int

func Gt

func Gt(numLike0, numLike1 any, isAbs ...bool) bool

func Gte

func Gte(numLike0, numLike1 any, isAbs ...bool) bool

func Hash

func Hash(hashLike any) common.Hash

Hash hashLike is non-nil

func HashSlice

func HashSlice(hashLikeArr any) (hashes []common.Hash)

HashSlice parse any to []common.Hash

func Int64

func Int64(numLike any) int64

func Is0b

func Is0b(s string) bool

func Is0o

func Is0o(s string) bool

func Is0x

func Is0x(s string) bool

func Lt

func Lt(numLike0, numLike1 any, isAbs ...bool) bool

func Lte

func Lte(numLike0, numLike1 any, isAbs ...bool) bool

func Mul

func Mul(numLike ...any) *big.Int

func MulDiv

func MulDiv(numLike0, numLike1, numLike2 any) *big.Int

func RandBytes

func RandBytes(len int) []byte

func Sub

func Sub(numBase any, numLike ...any) *big.Int

func Sum

func Sum(numLike ...any) *big.Int

func TypeSlice

func TypeSlice[T any](arr any) []T

TypeSlice assert any to []T

func Uint64

func Uint64(numLike any) uint64

Types

type AddressTopicLogsMap

type AddressTopicLogsMap = map[common.Address]map[common.Hash][]*types.Log

type Clientx

type Clientx struct {
	*Iterator[*ethclient.Client]
	Ctx             context.Context
	RpcMap          map[*ethclient.Client]string
	NotFoundBlocks  uint64
	AutoBlockNumber uint64
}

Clientx defines typed wrappers for the Ethereum RPC API of a set of the Ethereum Clients.

func NewClientx

func NewClientx(rpcList []string, weights []int, notFoundBlocks uint64, limiter ...*rate.Limiter) *Clientx

NewClientx connects clients to the given URLs, to provide a reliable Ethereum RPC API call, includes a timer to regularly update block height(AutoBlockNumber). If weight <= 1, the weight is always 1. Note: If len(weightList) == 0, then default weight = 1 will be active.

func (*Clientx) BalanceAt

func (c *Clientx) BalanceAt(account, blockNumber any) (balance *big.Int)

BalanceAt returns the wei balance of the given account. The block number can be nil, in which case the balance is taken from the latest known block.

func (*Clientx) BlockByHash

func (c *Clientx) BlockByHash(hash any, notFoundBlocks ...uint64) (block *types.Block, err 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 (*Clientx) BlockByNumber

func (c *Clientx) BlockByNumber(blockNumber any, notFoundBlocks ...uint64) (block *types.Block, err 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 (*Clientx) BlockNumber

func (c *Clientx) BlockNumber() (blockNumber uint64)

BlockNumber returns the most recent block number

func (*Clientx) ChainID

func (c *Clientx) ChainID() (chainID *big.Int)

ChainID retrieves the current chain ID for transaction replay protection.

func (*Clientx) Close

func (c *Clientx) Close()

Close all clients connections.

func (*Clientx) CodeAt

func (c *Clientx) CodeAt(account, blockNumber any) (code []byte)

CodeAt returns the contract code of the given account. The block number can be nil, in which case the code is taken from the latest known block.

func (*Clientx) FeeHistory

func (c *Clientx) FeeHistory(blockCount uint64, lastBlock any, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory)

FeeHistory retrieves the fee market history.

func (*Clientx) FilterLogs

func (c *Clientx) FilterLogs(q ethereum.FilterQuery) (logs []types.Log)

FilterLogs executes a filter query.

func (*Clientx) HeaderByHash

func (c *Clientx) HeaderByHash(hash any, notFoundBlocks ...uint64) (header *types.Header, err error)

HeaderByHash returns the block header with the given hash.

func (*Clientx) HeaderByNumber

func (c *Clientx) HeaderByNumber(blockNumber any, notFoundBlocks ...uint64) (header *types.Header, err error)

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

func (*Clientx) NetworkID

func (c *Clientx) NetworkID() (networkID *big.Int)

NetworkID returns the network ID.

func (*Clientx) NewMust

func (c *Clientx) NewMust(constructor any, addressLike any, maxErrNum ...int) func(f any, args ...any) []any

func (*Clientx) NewScanner

func (c *Clientx) NewScanner(topics [][]common.Hash, addresses []common.Address, intervalBlocks, overrideBlocks, delayBlocks uint64) *Scanner

NewScanner returns the next Ethereum Client.

func (*Clientx) NonceAt

func (c *Clientx) NonceAt(account, blockNumber any) (nonce uint64)

NonceAt returns the account nonce of the given account. The block number can be nil, in which case the nonce is taken from the latest known block.

func (*Clientx) PendingBalanceAt

func (c *Clientx) PendingBalanceAt(account any) (balance *big.Int)

PendingBalanceAt returns the wei balance of the given account in the pending state.

func (*Clientx) PendingCodeAt

func (c *Clientx) PendingCodeAt(account any) (code []byte)

PendingCodeAt returns the contract code of the given account in the pending state.

func (*Clientx) PendingNonceAt

func (c *Clientx) PendingNonceAt(account any) (nonce uint64)

PendingNonceAt returns the account nonce of the given account in the pending state. This is the nonce that should be used for the next transaction.

func (*Clientx) PendingStorageAt

func (c *Clientx) PendingStorageAt(account, keyHash any) (storage []byte)

PendingStorageAt returns the value of key in the contract storage of the given account in the pending state.

func (*Clientx) PendingTransactionCount

func (c *Clientx) PendingTransactionCount() (count uint)

PendingTransactionCount returns the total number of transactions in the pending state.

func (*Clientx) StorageAt

func (c *Clientx) StorageAt(account, keyHash, blockNumber any) (storage []byte)

StorageAt returns the value of key in the contract storage of the given account. The block number can be nil, in which case the value is taken from the latest known block.

func (*Clientx) SuggestGasPrice

func (c *Clientx) SuggestGasPrice() (gasPrice *big.Int)

SuggestGasPrice retrieves the currently suggested gas price to allow a timely execution of a transaction.

func (*Clientx) SuggestGasTipCap

func (c *Clientx) SuggestGasTipCap() (gasTipCap *big.Int)

SuggestGasTipCap retrieves the currently suggested gas tip cap after 1559 to allow a timely execution of a transaction.

func (*Clientx) TransactionByHash

func (c *Clientx) TransactionByHash(hash any, notFoundBlocks ...uint64) (tx *types.Transaction, isPending bool, err error)

TransactionByHash returns the transaction with the given hash.

func (*Clientx) TransactionCount

func (c *Clientx) TransactionCount(blockHash any, notFoundBlocks ...uint64) (count uint, err error)

TransactionCount returns the total number of transactions in the given block.

func (*Clientx) TransactionInBlock

func (c *Clientx) TransactionInBlock(blockHash any, index uint, notFoundBlocks ...uint64) (tx *types.Transaction, err error)

TransactionInBlock returns a single transaction at index in the given block.

func (*Clientx) TransactionReceipt

func (c *Clientx) TransactionReceipt(txHash any, notFoundBlocks ...uint64) (receipt *types.Receipt, err error)

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

func (*Clientx) TransactionSender

func (c *Clientx) TransactionSender(tx *types.Transaction, blockHash any, index uint, notFoundBlocks ...uint64) (sender common.Address, err 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.

func (*Clientx) WaitDeployed

func (c *Clientx) WaitDeployed(tx *types.Transaction, confirmBlocks uint64, notFoundBlocks ...uint64) (common.Address, error)

WaitDeployed waits for a contract deployment transaction and returns the on-chain contract address when it is mined. It stops waiting when Ctx is canceled.

func (*Clientx) WaitMined

func (c *Clientx) WaitMined(tx *types.Transaction, confirmBlocks uint64, notFoundBlocks ...uint64) (*types.Receipt, error)

WaitMined waits for tx to be mined on the blockchain. It stops waiting when the context is canceled. ethereum/go-ethereum@v1.11.6/accounts/abi/bind/util.go:32

type Iterator

type Iterator[T any] struct {
	Limit *rate.Limiter
	// contains filtered or unexported fields
}

func NewIterator

func NewIterator[T any](list []T, limiter ...*rate.Limiter) *Iterator[T]

func (*Iterator[T]) All

func (r *Iterator[T]) All() []T

func (*Iterator[T]) Call

func (r *Iterator[T]) Call(c func(t T) bool, isWait ...bool)

func (*Iterator[T]) Len

func (r *Iterator[T]) Len() int

func (*Iterator[T]) Limiter

func (r *Iterator[T]) Limiter() *rate.Limiter

func (*Iterator[T]) Next

func (r *Iterator[T]) Next() T

func (*Iterator[T]) Shuffle

func (r *Iterator[T]) Shuffle() *Iterator[T]

func (*Iterator[T]) WaitNext

func (r *Iterator[T]) WaitNext() T

type Scanner

type Scanner struct {
	*Clientx
	Addresses      []common.Address
	Topics         [][]common.Hash
	OverrideBlocks uint64
	IntervalBlocks uint64
	DelayBlocks    uint64
	TxHashSet      mapset.Set[string]
	Mu             sync.Mutex
}

func (*Scanner) Scan

func (s *Scanner) Scan(from, to uint64) (logs []types.Log, addressTopicLogsMap AddressTopicLogsMap)

Jump to

Keyboard shortcuts

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