ethx

package
v1.7.13 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 25 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, isPri ...bool) common.Address

Address addressLike is non-nil Attention: str without 0x will be treated as hex, eg: "10" => 0x10.

func AddressPtr added in v1.7.3

func AddressPtr(addressLike any, isPri ...bool) *common.Address

func AddressSlice

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

AddressSlice parse any to []common.Address, eg: []string to []common.Address

func BigInt

func BigInt(numLike any) *big.Int

BigInt Attention: str without 0x will be treated as decimal, eg: "10" => 10.

func BigIntSlice

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

BigIntSlice parse any to []*big.Int, eg: []string to []*big.Int

func CallMsg added in v1.6.0

func CallMsg(fromAddress any, tx *types.Transaction) (callMsg ethereum.CallMsg)

CallMsg create ethereum.CallMsg from *types.Transaction

func CheckRpcLogged added in v1.5.7

func CheckRpcLogged(rpcLike ...string) (reliableList []string, rpcSpeedMap map[string]time.Duration)

CheckRpcLogged returns what rpcs are reliable for filter logs example:

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

func CheckRpcSpeed

func CheckRpcSpeed(rpcLike ...string) (reliableList []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 Attention: str without 0x will be treated as hex, eg: "10" => 0x10.

func HashPtr added in v1.7.9

func HashPtr(hashLike any) *common.Hash

func HashSlice

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

HashSlice parse any to []common.Hash, eg: []string 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 PrivateKey added in v1.6.0

func PrivateKey(priLike any) *ecdsa.PrivateKey

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 Type added in v1.5.6

func Type[T any](x any) T

Type smart assert any to T

func Uint64

func Uint64(numLike any) uint64

Types

type Clientx

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

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

func NewClientx

func NewClientx(rpcList []string, weights []int, config *ClientxConfig, 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 NewSimpleClientx added in v1.6.0

func NewSimpleClientx(rpcList []string, concurrency ...int) *Clientx

NewSimpleClientx create *Clientx concurrency is the concurrency per seconds of any rpc, default 1/s see NewClientx

func (*Clientx) BalanceAt

func (c *Clientx) BalanceAt(account any, 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) CodeAt

func (c *Clientx) CodeAt(account any, 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) EstimateGas added in v1.6.0

func (c *Clientx) EstimateGas(msg ethereum.CallMsg, maxTry ...int) (gasLimit uint64, err error)

EstimateGas estimate tx gasUsed with maxTry.

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) GetRPCs added in v1.6.1

func (c *Clientx) GetRPCs() (rpcList []string)

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) NewMustContract added in v1.6.6

func (c *Clientx) NewMustContract(constructor any, addressLike any, config ...*ClientxConfig) *MustContract

NewMustContract is safe contract caller

func (*Clientx) NewRawLogger added in v1.6.6

func (c *Clientx) NewRawLogger(addresses []common.Address, topics [][]common.Hash, eventConfig ...*ClientxConfig) *RawLogger

NewRawLogger returns the RawLogger EventConfig require IntervalBlocks + OverrideBlocks <= 2000, eg: 800,800 addresses []common.Address : optional, could be nil topics topics [][]common.Hash : optional, could be nil

func (*Clientx) NextClient added in v1.6.3

func (c *Clientx) NextClient() *ethclient.Client

func (*Clientx) NonceAt

func (c *Clientx) NonceAt(account any, 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) SendTransaction added in v1.6.0

func (c *Clientx) SendTransaction(tx *types.Transaction, maxTry ...int) (err error)

SendTransaction send Transaction with maxTry.

func (*Clientx) Shuffle added in v1.6.6

func (c *Clientx) Shuffle() *Clientx

func (*Clientx) StorageAt

func (c *Clientx) StorageAt(account, keyHash any, 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) TransactOpts added in v1.6.0

func (c *Clientx) TransactOpts(privateKeyLike any) *bind.TransactOpts

TransactOpts create *bind.TransactOpts, and panic if privateKey err privateKeyLike eg: 0xf1...3, f1...3, []byte, *ecdsa.PrivateKey...

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) Transfer added in v1.6.0

func (c *Clientx) Transfer(privateKeyLike, to, amount any, options ...TransferOption) (tx *types.Transaction, err error)

Transfer build transaction and send TransferOption is optional. see more: github.com/ethereum/go-ethereum/internal/ethapi/transaction_args.go:284

func (*Clientx) TransferETH added in v1.7.5

func (c *Clientx) TransferETH(privateKeyLike, to any, value ...any) (tx *types.Transaction, err error)

func (*Clientx) UpdateRPCs added in v1.6.1

func (c *Clientx) UpdateRPCs(newRPCs []string)

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 ClientxConfig added in v1.6.9

type ClientxConfig struct {
	Event            EventConfig // MustContract and RawLogger
	GasLimit         uint64      // Clientx
	NotFundBlocks    uint64      // Clientx
	GasTipAdditional *big.Int    // Clientx
	MaxMustErrNumR   int         // MustContract
	MaxMustErrNumW   int         // MustContract
}

func NewClientxConfig added in v1.6.9

func NewClientxConfig() *ClientxConfig

type EventConfig added in v1.6.6

type EventConfig struct {
	IntervalBlocks, OverrideBlocks, DelayBlocks uint64
}

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

func NewIterator

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

func (*Iterator[T]) Add added in v1.6.0

func (r *Iterator[T]) Add(item ...T)

func (*Iterator[T]) All

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

func (*Iterator[T]) Len

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

func (*Iterator[T]) Limiter

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

func (*Iterator[T]) NewCall added in v1.6.0

func (r *Iterator[T]) NewCall(maxTry ...int) func(f any, args ...any) []any

func (*Iterator[T]) Remove added in v1.6.1

func (r *Iterator[T]) Remove(item ...T)

func (*Iterator[T]) Shuffle

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

func (*Iterator[T]) UnwaitNext added in v1.6.0

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

func (*Iterator[T]) WaitNext

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

type MustContract added in v1.6.6

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

func (*MustContract) Call added in v1.6.6

func (m *MustContract) Call(maxErrNum int, f any, args ...any) (ret []any, err error)

Call fit unsafe action, eg: maybe write failed If READ: missing the first *bind.CallOpts is legal If WRITE: missing the first *bind.CallOpts or PrivateKey is illegal

func (*MustContract) Read added in v1.6.13

func (m *MustContract) Read(f any, args ...any) []any

Read from contract safely, return all(not include last error) Attention: missing the first param/*bind.CallOpts is legal

func (*MustContract) Read0 added in v1.6.13

func (m *MustContract) Read0(f any, args ...any) any

Read0 read from contract safely, return first Attention: missing the first param/*bind.CallOpts is legal

func (*MustContract) Subscribe added in v1.6.6

func (m *MustContract) Subscribe(ch any, from any, index ...any) (sub event.Subscription, blockNumber chan uint64)

Subscribe contract event eventName is from ch, so just pass ch!

func (*MustContract) Write added in v1.6.13

func (m *MustContract) Write(f any, args ...any) (*types.Transaction, error)

Write to contract Attention: missing the first *bind.CallOpts or PrivateKey is illegal

type RawLogger added in v1.6.14

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

func (*RawLogger) Filter added in v1.6.14

func (r *RawLogger) Filter(from, to uint64) (chLogs chan types.Log, chNewStart chan uint64)

Filter get logs from any blocks range, eg: (0, 10000000) Example Usage :

for l := range chLogs {
	// DO 1: log handle
}

// DO 2: get next turn new start/from chNewStart := <-chNewStart

type TransferOption added in v1.6.0

type TransferOption struct {
	AccessList types.AccessList   // option
	Opts       *bind.TransactOpts // option
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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