client

package
v0.0.0-...-26d7e6f Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FastN = 2
	FastP = 1
)
View Source
const EthereumMessageHashPrefix = "\x19Ethereum Signed Message:\n32"

EthereumMessageHashPrefix is a Geth-originating message prefix that seeks to prevent arbitrary message data to be representable as a valid Ethereum transaction For more information, see: https://github.com/ethereum/go-ethereum/issues/3731

Variables

DefaultScryptParams is for use in production. It used geth's standard level of encryption and is relatively expensive to decode. Avoid using this in tests.

View Source
var ErrKeyStoreLocked = errors.New("keystore is locked (HINT: did you forget to call keystore.Unlock?)")
View Source
var FastScryptParams = ScryptParams{N: FastN, P: FastP}

FastScryptParams is for use in tests, where you don't want to wear out your CPU with expensive key derivations, do not use it in production, or your encrypted keys will be easy to brute-force!

Functions

func IsParityQueriedReceiptTooEarly

func IsParityQueriedReceiptTooEarly(e error) bool

Parity can return partially hydrated Log entries if you query a receipt while the transaction is still in the mempool. Go-ethereum's built-in client raises an error since this is a required field. There is no easy way to ignore the error or pass in a custom struct, so we use this hack to detect it instead.

Types

type Client

type Client interface {
	GethClient

	Dial(ctx context.Context) error
	Close()

	SendRawTx(bytes []byte) (common.Hash, error)
	Call(result interface{}, method string, args ...interface{}) error
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

	HeaderByNumber(ctx context.Context, n *big.Int) (*models.Head, error)
	SubscribeNewHead(ctx context.Context, ch chan<- *models.Head) (ethereum.Subscription, error)
}

Client is the interface used to interact with an ethereum node.

type GethClient

type GethClient interface {
	ChainID(ctx context.Context) (*big.Int, error)
	SendTransaction(ctx context.Context, tx *types.Transaction) error
	PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
	EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
}

GethClient is an interface that represents go-ethereum's own ethclient https://github.com/ethereum/go-ethereum/blob/master/ethclient/ethclient.go

type Impl

type Impl struct {
	GethClient
	RPCClient

	SecondaryGethClients []GethClient
	SecondaryRPCClients  []RPCClient
	// contains filtered or unexported fields
}

Impl implements the ethereum Client interface using a CallerSubscriber instance.

func NewImpl

func NewImpl(config *esTypes.Config) (*Impl, error)

NewImpl creates a new client implementation

func (*Impl) BalanceAt

func (client *Impl) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)

func (*Impl) BlockByNumber

func (client *Impl) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)

func (*Impl) Call

func (client *Impl) Call(result interface{}, method string, args ...interface{}) error

func (*Impl) CallContext

func (client *Impl) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

func (*Impl) ChainID

func (client *Impl) ChainID(ctx context.Context) (*big.Int, error)

func (*Impl) Dial

func (client *Impl) Dial(ctx context.Context) error

func (*Impl) EstimateGas

func (client *Impl) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)

func (*Impl) FilterLogs

func (client *Impl) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)

func (*Impl) HeaderByNumber

func (client *Impl) HeaderByNumber(ctx context.Context, number *big.Int) (*models.Head, error)

func (*Impl) PendingCodeAt

func (client *Impl) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

func (*Impl) PendingNonceAt

func (client *Impl) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*Impl) SendRawTx

func (client *Impl) SendRawTx(bytes []byte) (common.Hash, error)

SendRawTx sends a signed transaction to the transaction pool.

func (*Impl) SendTransaction

func (client *Impl) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction also uses the secondary HTTP RPC URL if set

func (*Impl) SubscribeFilterLogs

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

func (*Impl) SubscribeNewHead

func (client *Impl) SubscribeNewHead(ctx context.Context, ch chan<- *models.Head) (ethereum.Subscription, error)

func (*Impl) SuggestGasPrice

func (client *Impl) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*Impl) TransactionReceipt

func (client *Impl) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

TransactionReceipt wraps the GethClient's `TransactionReceipt` method so that we can ignore the error that arises when we're talking to a Parity node that has no receipt yet.

type KeyStore

type KeyStore struct {
	*keystore.KeyStore
	// contains filtered or unexported fields
}

KeyStore manages a key storage directory on disk.

func NewInsecureKeyStore

func NewInsecureKeyStore(keyDir string) *KeyStore

NewInsecureKeyStore creates an *INSECURE* keystore for the given directory. NOTE: Should only be used for testing!

func NewKeyStore

func NewKeyStore(keyDir string, scryptParams ScryptParams) *KeyStore

NewKeyStore creates a keystore for the given directory.

func (*KeyStore) Delete

func (ks *KeyStore) Delete(address common.Address) error

func (*KeyStore) Export

func (ks *KeyStore) Export(address common.Address, newPassword string) ([]byte, error)

func (*KeyStore) GetAccountByAddress

func (ks *KeyStore) GetAccountByAddress(address common.Address) (accounts.Account, error)

GetAccountByAddress returns the account matching the address provided, or an error if it is missing

func (*KeyStore) GetAccounts

func (ks *KeyStore) GetAccounts() []accounts.Account

GetAccounts returns all accounts

func (*KeyStore) HasAccountWithAddress

func (ks *KeyStore) HasAccountWithAddress(address common.Address) bool

func (*KeyStore) HasAccounts

func (ks *KeyStore) HasAccounts() bool

HasAccounts returns true if there are accounts located at the keystore directory.

func (*KeyStore) Import

func (ks *KeyStore) Import(keyJSON []byte, oldPassword string) (accounts.Account, error)

func (*KeyStore) NewAccount

func (ks *KeyStore) NewAccount() (accounts.Account, error)

NewAccount adds an account to the keystore

func (*KeyStore) SignTx

func (ks *KeyStore) SignTx(account accounts.Account, tx *ethTypes.Transaction, chainID *big.Int) (*ethTypes.Transaction, error)

SignTx uses the unlocked account to sign the given transaction.

func (*KeyStore) Unlock

func (ks *KeyStore) Unlock(password string) error

Unlock uses the given password to try to unlock accounts located in the keystore directory.

type KeyStoreInterface

type KeyStoreInterface interface {
	Unlock(password string) error
	Accounts() []accounts.Account
	Wallets() []accounts.Wallet
	HasAccounts() bool
	HasAccountWithAddress(common.Address) bool
	NewAccount() (accounts.Account, error)
	Import(keyJSON []byte, oldPassword string) (accounts.Account, error)
	Export(address common.Address, newPassword string) ([]byte, error)
	Delete(address common.Address) error
	GetAccounts() []accounts.Account
	GetAccountByAddress(common.Address) (accounts.Account, error)

	SignTx(account accounts.Account, tx *ethTypes.Transaction, chainID *big.Int) (*ethTypes.Transaction, error)
}

type RPCClient

type RPCClient interface {
	Call(result interface{}, method string, args ...interface{}) error
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
	BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
	EthSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (ethereum.Subscription, error)
	Close()
}

RPCClient is an interface that represents go-ethereum's own rpc.Client. https://github.com/ethereum/go-ethereum/blob/master/rpc/client.go

type ScryptConfigReader

type ScryptConfigReader interface {
	InsecureFastScrypt() bool
}

type ScryptParams

type ScryptParams struct{ N, P int }

func GetScryptParams

func GetScryptParams(config ScryptConfigReader) ScryptParams

type SendError

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

fatal means this transaction can never be accepted even with a different nonce or higher gas price

func NewFatalSendError

func NewFatalSendError(e error) *SendError

func NewFatalSendErrorS

func NewFatalSendErrorS(s string) *SendError

func NewSendError

func NewSendError(e error) *SendError

func NewSendErrorS

func NewSendErrorS(s string) *SendError

func (*SendError) Error

func (s *SendError) Error() string

func (*SendError) Fatal

func (s *SendError) Fatal() bool

Fatal indicates whether the error should be considered fatal or not Fatal errors mean that no matter how many times the send is retried, no node will ever accept it

func (*SendError) IsInsufficientEth

func (s *SendError) IsInsufficientEth() bool

func (*SendError) IsNonceTooLowError

func (s *SendError) IsNonceTooLowError() bool

func (*SendError) IsReplacementUnderpriced

func (s *SendError) IsReplacementUnderpriced() bool

IsReplacementUnderpriced indicates that a transaction already exists in the mempool with this nonce but a different gas price or payload

func (*SendError) IsTemporarilyUnderpriced

func (s *SendError) IsTemporarilyUnderpriced() bool

func (*SendError) IsTerminallyUnderpriced

func (s *SendError) IsTerminallyUnderpriced() bool

IsTerminallyUnderpriced indicates that this transaction is so far underpriced the node won't even accept it in the first place

func (*SendError) IsTransactionAlreadyInMempool

func (s *SendError) IsTransactionAlreadyInMempool() bool

Geth/parity returns this error if the transaction is already in the node's mempool

func (*SendError) StrPtr

func (s *SendError) StrPtr() *string

type Subscription

type Subscription interface {
	Err() <-chan error
	Unsubscribe()
}

Subscription is an interface for mock generation. It is identical to `ethereum.Subscription`.

Jump to

Keyboard shortcuts

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