Documentation ¶
Overview ¶
Package eth provides general functionality for interacting with the Ethereum network, smart contracts, etc.
Index ¶
- Constants
- Variables
- func AddressPerLine(r io.Reader) ([]common.Address, error)
- func AddressesFromReader(r io.Reader, split bufio.SplitFunc) ([]common.Address, error)
- func Ether(e int64) *big.Int
- func EtherFraction(numerator, denominator int64) *big.Int
- func LastBlockBy(ctx context.Context, blocks BlockFetcher, minedBy uint64, hint *BlockRange) (_ *types.Block, retErr error)
- func NewMnemonic(bitSize int) (string, error)
- func RWDemuxBackend(r, w bind.ContractBackend) bind.ContractBackend
- func RandFromHash(h common.Hash) *rand.Rand
- func WithPersonalMessagePrefix(message []byte) []byte
- type BlockFetcher
- type BlockRange
- type Dialer
- type HDPathPrefix
- type NullableAddress
- type NullableUint256
- type Signer
- func (s *Signer) Address() common.Address
- func (s *Signer) Mnemonic() string
- func (s *Signer) PersonalSign(buf []byte) ([]byte, error)
- func (s *Signer) PersonalSignAddress(addr common.Address) ([]byte, error)
- func (s *Signer) PersonalSignWithNonce(buf []byte) ([]byte, [32]byte, error)
- func (s *Signer) RawSign(buf []byte) ([]byte, error)
- func (s *Signer) Sign(buf []byte) ([]byte, error)
- func (s *Signer) String() string
- func (s *Signer) TransactorWithChainID(chainID *big.Int) (*bind.TransactOpts, error)
Constants ¶
const DefaultHDPathPrefix = HDPathPrefix("m/44'/60'/0'/0/")
DefaultHDPathPrefix is the default format for derived accounts when using SignerFromSeedPhrase().
const DialerFlag = "dialer_eth_node_url"
DialerFlag is the flag name configured by NewDialerFromFlags.
const Symbol = `Ξ`
Symbol is the ETH symbol.
Variables ¶
var ErrBlockNotFound = errors.New("block not found")
ErrBlockNotFound is returned by LastBlockBy if no block was mined by the requested time.
Functions ¶
func AddressPerLine ¶
AddressPerLine returns AddressesFromReader(r, bufio.ScanLines). It therefore reads each non-empty line of r and parses it as an Address. Empty lines are skipped.
func AddressesFromReader ¶
AddressesFromReader scans the Reader, splitting according to the split function, and parses each non-empty chunk as an address after trimming surrounding space (i.e. the split function does not have to trim). Empty chunks are skipped.
func EtherFraction ¶
EtherFraction returns numerator/denominator ETH in Wei.
func LastBlockBy ¶
func LastBlockBy(ctx context.Context, blocks BlockFetcher, minedBy uint64, hint *BlockRange) (_ *types.Block, retErr error)
LastBlockBy performs a binary search to find and return the last block mined by the specified unix timestamp, inclusive. If a nil hint is provided, the search defaults to [0,blocks.BlockNumber()]. If hint.Last == 0, it defaults to the latest block.
func NewMnemonic ¶
NewMnemonic is a convenience wrapper around go-bip39 entropy and mnemonic creation.
func RWDemuxBackend ¶
func RWDemuxBackend(r, w bind.ContractBackend) bind.ContractBackend
An RWDemuxBackend splits calls to ContractBackend methods to a read-only and write-only backend. This is useful when using a regular node (e.g. Infura) for reading, but Flashbots for writing.
Everything except for SendTransaction() and EstimateGas() are sent to the read backend. EstimateGas is included as a "write" because it may leak sensitive information.
func RandFromHash ¶
RandFromHash returns a new *rand.Rand seeded by the Hash. The Hash is converted to a uint256 and each of its four uint64 words are folded into one by xor. The raw bits of the resulting uint64 are treated as an int64 passed to rand.NewSource().
func WithPersonalMessagePrefix ¶
WithPersonalMessagePrefix converts a given message to conform to the signed data standard according to EIP-191.
Types ¶
type BlockFetcher ¶
type BlockFetcher interface { BlockNumber(context.Context) (uint64, error) BlockByNumber(context.Context, *big.Int) (*types.Block, error) }
A BlockFetcher can fetch information about blocks. Typically this would be an *ethclient.Client.
type BlockRange ¶
type BlockRange struct {
First, Last uint64
}
BlockRange is an inclusive range of block numbers.
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
A Dialer dials an Ethereum node URL that it sources from a secret store. This is to protect API keys that may be stored in the URL.
func MustNewDialerFromFlag ¶
type HDPathPrefix ¶
type HDPathPrefix string
An HDPathPrefix is a prefix for use in deriving private keys from BIP39 mnemonics. It is appended with the account number. Values MUST include a trailing slash.
func (HDPathPrefix) SignerFromPRF ¶
SignerFromPRF deterministically derives a private key from the pseudo-random function and the input bytes. By definition, the output of a PRF is indistinguishable from a random function.
The input parameter allows for different sets of HD wallets to be derived from the same underlying PRF key. Only the PRF key need be secret.
SignerFromPRF can be thought of as a method for securely creating new mnemonic seed phrases from a single underlying key and different input parameters. Although the resulting mnemonic is accessible, SignerFromPRF is intended for use in an automated environment, which is why it relies on Google Tink.
func (HDPathPrefix) SignerFromPRFSet ¶
SignerFromPRFSet returns hdp.SifnerFromPRF() using the set's primary PRF. This is simply a convenience function as the prf package doesn't accomodate direct creation of a prf.PRF.
func (HDPathPrefix) SignerFromSeedPhrase ¶
func (hdp HDPathPrefix) SignerFromSeedPhrase(mnemonic, password string, account uint) (*Signer, error)
SignerFromSeedPhrase confirms that the mnemonic is valid under BIP39 and then uses it to derive a private key (see HDPathF)
type NullableAddress ¶
A NullableAddress contains a common.Address that can be flagged as being Valid or not (i.e. null). Unlike a pointer, a NullableAddress can be reliably marshalled to and from JSON and CSV. The zero value is equivalent to null.
func (NullableAddress) MarshalCSV ¶
func (n NullableAddress) MarshalCSV() (string, error)
MarshalCSV marshals the Address to a hex string. It returns ("", nil) if Null.
func (NullableAddress) MarshalJSON ¶
func (n NullableAddress) MarshalJSON() ([]byte, error)
MarshalJSON marshals the Address to JSON. It returns []byte("null"), nil if Null (i.e. explicit JSON null). A non-Null marshalled value is a hex string.
func (*NullableAddress) UnmarshalCSV ¶
func (n *NullableAddress) UnmarshalCSV(s string) error
UnmarshalCSV unmarshals the Address from a hex string.
func (*NullableAddress) UnmarshalJSON ¶
func (n *NullableAddress) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the Address from JSON.
type NullableUint256 ¶
A NullableUint256 contains a uint256.Int that can be flagged as being Valid or not (i.e. null). Unlike a pointer, a NullableUint256 can be reliably marshalled to and from JSON and CSV. The zero value is equivalent to null.
func (NullableUint256) MarshalCSV ¶
func (n NullableUint256) MarshalCSV() (string, error)
MarshalCSV marshals the Int to a hex string. It returns ("", nil) if Null.
func (NullableUint256) MarshalJSON ¶
func (n NullableUint256) MarshalJSON() ([]byte, error)
MarshalJSON marshals the Int to JSON. It returns []byte("null"), nil if Null (i.e. explicit JSON null). A non-Null marshalled value is a hex string.
func (*NullableUint256) UnmarshalCSV ¶
func (n *NullableUint256) UnmarshalCSV(s string) error
UnmarshalCSV unmarshals the Int from a hex string.
func (*NullableUint256) UnmarshalJSON ¶
func (n *NullableUint256) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the Int from JSON.
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
A Signer abstracts signing of arbitrary messages by wrapping an ECDSA private key and, optionally, its associated BIP39 mnemonic.
func NewSigner ¶
NewSigner is equivalent to DefaultHDPathPrefix.SignerFromSeedPhrase(NewMnemonic(), "", 0).
func (*Signer) Mnemonic ¶
Mnemonic returns the mnemonic used to derive the Signer's private key. USE WITH CAUTION.
func (*Signer) PersonalSign ¶
PersonalSign returns an EIP-191 conform personal ECDSA signature of buf Convenience wrapper for s.CompactSign(WithPersonalMessagePrefix(buf))
func (*Signer) PersonalSignAddress ¶
SignAddress is a convenience wrapper for s.PersonalSign(addr.Bytes()).
func (*Signer) PersonalSignWithNonce ¶
PersonalSignWithNonce generates a 32-byte nonce with crypto/rand and returns s.PersonalSign(append(buf, nonce)).
func (*Signer) RawSign ¶
RawSign returns an ECDSA signature of buf. USE WITH CAUTION as signed data SHOULD be hashed first to avoid chosen-plaintext attacks. Prefer Signer.Sign().
func (*Signer) TransactorWithChainID ¶
TransactorWithChainID returns bind.NewKeyedTransactorWithChainID(<key>, chainID) where <key> is the Signer's private key.