eth

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: MIT Imports: 29 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConflictingGasFlags = errors.New("cannot specify both legacy and EIP-1559 gas flags")
	ErrTooManyPendingTx    = errors.New("too many txs in pending status")
	ErrTooManySubmittingTx = errors.New("too many txs in submitting status")
)
View Source
var (
	// ZeroAddr is all 0s
	ZeroAddr Addr
	// ZeroAddrHex is string of 20 0s
	ZeroAddrHex = Addr2Hex(ZeroAddr)
	// ZeroBigInt is big.NewInt(0)
	ZeroBigInt = big.NewInt(0)
	// ZeroHash is all 0s
	ZeroHash Hash
)
View Source
var (
	ErrTxDropped = errors.New("onchain transaction dropped")
	ErrTxTimeout = errors.New("onchain transaction timeout")
	ErrTxReorg   = errors.New("onchain transaction reorg")
	// an error possibly returned when a transaction is pending
	ErrMissingField = errors.New("missing required field 'transactionHash' for Log")
)

Functions

func Addr2Hex added in v0.3.0

func Addr2Hex(a Addr) string

Addr2Hex returns hex without 0x

func Addr2Hex0x added in v0.3.0

func Addr2Hex0x(a Addr) string

Addr2Hex returns hex with 0x

func AddrFmt added in v0.3.0

func AddrFmt(s string) string

func Bytes2AddrHex added in v0.3.0

func Bytes2AddrHex(b []byte) string

Bytes2AddrHex returns hex without 0x

func Bytes2Hex added in v0.3.0

func Bytes2Hex(b []byte) string

Bytes2Hex returns hex string without 0x prefix

func FormatAddrHex added in v0.3.0

func FormatAddrHex(s string) string

FormatAddrHex formats a string into standard Addr string

func GeneratePrefixedHash

func GeneratePrefixedHash(data []byte) []byte

keccak data first, then prefix "\x19Ethereum Signed Message:\n" and length 32

func GeneratePrefixedHashForRaw added in v0.2.2

func GeneratePrefixedHashForRaw(raw []byte) []byte

add length and raw as is, only does keccak once of the concat result. to be compatible with ethers signmessage behavior

func GetAddrPrivKeyFromKeystore

func GetAddrPrivKeyFromKeystore(keyjson, passphrase string) (common.Address, string, error)

func Hash2Hex added in v0.3.0

func Hash2Hex(h [32]byte) string

Hash2Hex returns hex with 0x

func Hex2Bytes added in v0.3.0

func Hex2Bytes(s string) (b []byte)

Hex2Bytes supports hex string with or without 0x prefix Calls hex.DecodeString directly and ignore err similar to common.FromHex but better

func IsSignatureValid added in v0.1.13

func IsSignatureValid(signer common.Address, data []byte, sig []byte) bool

func Pad20Bytes added in v0.3.0

func Pad20Bytes(in []byte) []byte

if in is 20 bytes, return directly. otherwise return a new []byte w/ len 20, left pad 0x00..[in] if len(in)>20, panic

func Pad32Bytes added in v0.3.0

func Pad32Bytes(in []byte) []byte

func RecoverSigner

func RecoverSigner(data []byte, sig []byte, isRaw ...bool) (common.Address, error)

optional isRaw to support recover raw message. use variadic to be compatible w/ legacy code

func WaitMined

func WaitMined(
	ctx context.Context,
	ec *ethclient.Client,
	tx *types.Transaction,
	opts ...TxOption) (*types.Receipt, error)

func WaitMinedWithTxHash

func WaitMinedWithTxHash(
	ctx context.Context,
	ec *ethclient.Client,
	txHash string,
	opts ...TxOption) (*types.Receipt, error)

WaitMinedWithTxHash only wait with given txhash, without other info such as nonce. Therefore, it cannot tell if a tx is dropped if not yet mined

func WrapFilter added in v0.3.0

func WrapFilter(fromBlock, finalBlock, maxBlockDelta uint64, filterFunc func(f *bind.FilterOpts) error) error

WrapFilter loop calls filterFunc with the block range not exceeding maxBlockDelta. Retries with half the block range on error until all blocks are covered, or the range has shrunk to a single block and filterFunc still returns error.

Types

type Addr added in v0.3.0

type Addr = common.Address

Addr is alias to geth common.Address

func Bytes2Addr added in v0.3.0

func Bytes2Addr(b []byte) Addr

Bytes2Addr returns Address from b Addr.Bytes() does the reverse

func Hex2Addr added in v0.3.0

func Hex2Addr(s string) Addr

Hex2Addr accepts hex string with or without 0x prefix and return Addr

type Address added in v0.3.0

type Address = common.Address

Addr is alias to geth common.Address

type CelerSigner

type CelerSigner = PrivateKeySigner

Backward compatibility: keep the old name temporarily. Deprecated: Use PrivateKeySigner instead.

func NewSigner deprecated

func NewSigner(privateKey string, chainId *big.Int) (*CelerSigner, error)

Deprecated: Use NewPrivateKeySigner.

func NewSignerFromKeystore deprecated

func NewSignerFromKeystore(keyjson, passphrase string, chainId *big.Int) (*CelerSigner, error)

Deprecated: Use NewKeystoreSigner.

type Hash added in v0.3.0

type Hash = common.Hash

Hash is the type for ethereum hash type

func Bytes2Hash added in v0.3.0

func Bytes2Hash(b []byte) Hash

Bytes2Hash converts bytes to Hash

func Hex2Hash added in v0.3.0

func Hex2Hash(s string) Hash

Hex2Hash accepts hex string with or without 0x prefix and return Hash

type KmsSigner added in v0.1.38

type KmsSigner struct {
	Addr common.Address
	// contains filtered or unexported fields
}

impl Signer interface

func NewKmsSigner added in v0.1.38

func NewKmsSigner(region, keyAlias, awsKey, awsSec string, chainId *big.Int) (*KmsSigner, error)

region and keyAlias must be valid, eg. us-west-1 alias/mytestkey if awsKey, awsSec are empty string, will use aws sdk auto search

func (*KmsSigner) NewTransactOpts added in v0.1.41

func (s *KmsSigner) NewTransactOpts() *bind.TransactOpts

return bind.TransactOpts to be used in bound contract tx

func (*KmsSigner) Sign added in v0.1.38

func (s *KmsSigner) Sign(hash []byte) ([]byte, error)

input must be hash, return 65 bytes sig or error. sig[64] is 0 or 1

func (*KmsSigner) SignEthMessage added in v0.1.38

func (s *KmsSigner) SignEthMessage(data []byte) ([]byte, error)

satisfy Signer interface SignEthMessage

func (*KmsSigner) SignEthTransaction added in v0.1.38

func (s *KmsSigner) SignEthTransaction(rawTx []byte) ([]byte, error)

satisfy Signer interface SignEthTransaction

func (*KmsSigner) SignerFn added in v0.1.41

func (s *KmsSigner) SignerFn(addr common.Address, tx *types.Transaction) (*types.Transaction, error)

satisfy bind/base.go SignerFn

type PrivateKeySigner added in v0.3.0

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

PrivateKeySigner signs Ethereum messages and transactions using a local ECDSA private key. It is generic and suitable for use outside Celer-specific projects.

func NewKeystoreSigner added in v0.3.0

func NewKeystoreSigner(keyjson, passphrase string, chainId *big.Int) (*PrivateKeySigner, error)

NewKeystoreSigner creates a signer from a geth keystore JSON and passphrase. chainId may be nil if the signer will only call SignEthMessage/SignRawMessage.

func NewPrivateKeySigner added in v0.3.0

func NewPrivateKeySigner(privateKey string, chainId *big.Int) (*PrivateKeySigner, error)

NewPrivateKeySigner creates a signer backed by a hex-encoded ECDSA private key. chainId may be nil if the signer will only call SignEthMessage/SignRawMessage.

func (*PrivateKeySigner) SignEthMessage added in v0.3.0

func (s *PrivateKeySigner) SignEthMessage(data []byte) ([]byte, error)

input data: a byte array of raw message to be signed return a byte array signature in the R,S,V format

func (*PrivateKeySigner) SignEthTransaction added in v0.3.0

func (s *PrivateKeySigner) SignEthTransaction(rawTx []byte) ([]byte, error)

input rawTx: a byte array of a RLP-encoded unsigned Ethereum raw transaction return a byte array signed raw tx in RLP-encoded format

func (*PrivateKeySigner) SignRawMessage added in v0.3.0

func (s *PrivateKeySigner) SignRawMessage(data []byte) ([]byte, error)

input data: a byte array of raw message to be signed, note the raw data and its length will be used unlike SignEthMessage which does keccak first to avoid malleability issue return a byte array signature in the R,S,V format

type PubKeyAsn added in v0.1.38

type PubKeyAsn struct {
	Algo   pkix.AlgorithmIdentifier
	PubKey asn1.BitString
}

type RS added in v0.1.38

type RS struct {
	R, S *big.Int
}

type Signer

type Signer interface {
	// input data: a byte array of raw message to be signed
	// return a byte array signature in the R,S,V format
	// The implementation should hash data w/ keccak256, and add
	// "\x19Ethereum Signed Message:\n32" prefix (32 is the length of hash result)
	// for ECDSA sign. If some library handles prefix automatically, pass hash
	// result is sufficient
	SignEthMessage(data []byte) ([]byte, error)
	// input rawTx: a byte array of a RLP-encoded unsigned Ethereum raw transaction
	// return a byte array signed raw tx in RLP-encoded format
	SignEthTransaction(rawTx []byte) ([]byte, error)
}

func CreateSigner added in v0.3.0

func CreateSigner(ksfile, passphrase string, chainid *big.Int) (Signer, common.Address, error)

return signer, address

type TransactionStateHandler

type TransactionStateHandler struct {
	OnMined func(receipt *types.Receipt)
	OnError func(tx *types.Transaction, err error)
}

type Transactor

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

func NewTransactor

func NewTransactor(
	keyjson string,
	passphrase string,
	client *ethclient.Client,
	chainId *big.Int,
	opts ...TxOption) (*Transactor, error)

func NewTransactorByExternalSigner

func NewTransactorByExternalSigner(
	address common.Address,
	signer Signer,
	client *ethclient.Client,
	chainId *big.Int,
	opts ...TxOption) *Transactor

func (*Transactor) Address

func (t *Transactor) Address() common.Address

func (*Transactor) ContractCaller

func (t *Transactor) ContractCaller() bind.ContractCaller

func (*Transactor) Transact

func (t *Transactor) Transact(
	handler *TransactionStateHandler,
	method TxMethod,
	opts ...TxOption) (*types.Transaction, error)

func (*Transactor) TransactWaitMined

func (t *Transactor) TransactWaitMined(
	description string,
	method TxMethod,
	opts ...TxOption) (*types.Receipt, error)

func (*Transactor) WaitMined

func (t *Transactor) WaitMined(txHash string, opts ...TxOption) (*types.Receipt, error)

type TransactorConfig

type TransactorConfig struct {
	Keyjson    string
	Passphrase string
}

func NewTransactorConfig

func NewTransactorConfig(keyjson string, passphrase string) *TransactorConfig

type TransactorPool

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

func NewTransactorPool

func NewTransactorPool(transactors []*Transactor) (*TransactorPool, error)

func NewTransactorPoolFromConfig

func NewTransactorPoolFromConfig(
	client *ethclient.Client,
	configs []*TransactorConfig,
	chainId *big.Int,
	opts ...TxOption) (*TransactorPool, error)

func (*TransactorPool) ContractCaller

func (p *TransactorPool) ContractCaller() bind.ContractCaller

func (*TransactorPool) Submit

func (p *TransactorPool) Submit(
	handler *TransactionStateHandler,
	method TxMethod,
	opts ...TxOption) (*types.Transaction, error)

func (*TransactorPool) SubmitWaitMined

func (p *TransactorPool) SubmitWaitMined(
	description string,
	method TxMethod,
	opts ...TxOption) (*types.Receipt, error)

func (*TransactorPool) WaitMined

func (p *TransactorPool) WaitMined(txHash string, opts ...TxOption) (*types.Receipt, error)

type TxMethod

type TxMethod func(transactor bind.ContractTransactor, opts *bind.TransactOpts) (*types.Transaction, error)

func SimpleTransferTx added in v0.3.0

func SimpleTransferTx(to common.Address) TxMethod

type TxOption added in v0.1.13

type TxOption interface {
	// contains filtered or unexported methods
}

func WithAddGasEstimateRatio added in v0.1.26

func WithAddGasEstimateRatio(r float64) TxOption

func WithAddGasFeeRatio added in v0.2.0

func WithAddGasFeeRatio(r float64) TxOption

func WithAddGasGwei added in v0.1.13

func WithAddGasGwei(g float64) TxOption

func WithAddPriorityFeePerGasGwei added in v0.1.64

func WithAddPriorityFeePerGasGwei(g float64) TxOption

func WithBlockDelay added in v0.1.13

func WithBlockDelay(d uint64) TxOption

func WithDropDetection added in v0.1.21

func WithDropDetection(d bool) TxOption

func WithEthValue added in v0.1.13

func WithEthValue(v *big.Int) TxOption

func WithForceGasGwei added in v0.1.29

func WithForceGasGwei(g string) TxOption

func WithGasLimit added in v0.1.13

func WithGasLimit(l uint64) TxOption

func WithMaxFeePerGasGwei added in v0.1.40

func WithMaxFeePerGasGwei(g float64) TxOption

func WithMaxGasGwei added in v0.1.13

func WithMaxGasGwei(g float64) TxOption

func WithMaxPendingTxNum added in v0.1.54

func WithMaxPendingTxNum(n uint64) TxOption

func WithMaxPriorityFeePerGasGwei added in v0.1.40

func WithMaxPriorityFeePerGasGwei(g float64) TxOption

func WithMaxSubmittingTxNum added in v0.1.54

func WithMaxSubmittingTxNum(n uint64) TxOption

func WithMinGasGwei added in v0.1.13

func WithMinGasGwei(g float64) TxOption

func WithNoNonceRetry added in v0.3.0

func WithNoNonceRetry() TxOption

func WithNonce added in v0.1.64

func WithNonce(n uint64) TxOption

func WithPollingInterval added in v0.1.13

func WithPollingInterval(t time.Duration) TxOption

func WithQueryRetryInterval added in v0.1.13

func WithQueryRetryInterval(t time.Duration) TxOption

func WithQueryTimeout added in v0.1.13

func WithQueryTimeout(t time.Duration) TxOption

func WithTimeout added in v0.1.13

func WithTimeout(t time.Duration) TxOption

func WithTxLogInfo added in v0.3.0

func WithTxLogInfo(enabled bool) TxOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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