Documentation ¶
Index ¶
- Constants
- Variables
- func LoadDeployedContracts(filename string) (map[string]string, error)
- func NewAddress() (string, string, error)
- func NewEphemeralKeys(addrs int64) ([]string, error)
- func ReturnFunds(c *Client, toAddr string) error
- func SaveDeployedContract(filename, contractName, address string) error
- func UpdateAndSplitFunds(c *Client, opts *FundKeyFileCmdOpts) error
- func UpdateKeyFileBalances(c *Client) error
- type ABIFinder
- type ABIFinderResult
- type ABIStore
- type Call
- type CallOpt
- type Client
- func (m *Client) AnySyncedKey() int
- func (m *Client) CalculateSubKeyFunding(addrs int64) (*FundingDetails, error)
- func (m *Client) CallMsgFromTx(tx *types.Transaction) ethereum.CallMsg
- func (m *Client) CreateOrUnmarshalKeyFile(opts *FundKeyFileCmdOpts) (*KeyFile, error)
- func (m *Client) Decode(tx *types.Transaction, txErr error) (*DecodedTransaction, error)
- func (m *Client) DecodeCustomABIErr(txErr error) (string, error)
- func (m *Client) DeployContract(auth *bind.TransactOpts, name string, abi abi.ABI, bytecode []byte, ...) (DeploymentData, error)
- func (m *Client) DeployContractFromContractStore(auth *bind.TransactOpts, name string, params ...interface{}) (DeploymentData, error)
- func (m *Client) DeployDebugContract(subDbgAddr common.Address) (*network_debug_contract.NetworkDebugContract, common.Address, error)
- func (m *Client) DeployDebugSubContract() (*network_sub_debug_contract.NetworkDebugSubContract, common.Address, error)
- func (m *Client) NewCallKeyOpts(keyNum int, o ...CallOpt) *bind.CallOpts
- func (m *Client) NewCallOpts(o ...CallOpt) *bind.CallOpts
- func (m *Client) NewTXKeyOpts(keyNum int, o ...TransactOpt) *bind.TransactOpts
- func (m *Client) NewTXOpts(o ...TransactOpt) *bind.TransactOpts
- func (m *Client) RetryTxAndDecode(f func() (*types.Transaction, error)) (*DecodedTransaction, error)
- func (m *Client) SaveDecodedCallsAsJson(dirname string) error
- func (m *Client) TransferETHFromKey(ctx context.Context, fromKeyNum int, to string, value *big.Int) error
- func (m *Client) WaitMined(ctx context.Context, l zerolog.Logger, b bind.DeployBackend, ...) (*types.Receipt, error)
- type ClientOpt
- type CommonData
- type Config
- type ContractMap
- type ContractStore
- type DecodableLog
- type DecodedCall
- type DecodedCommonLog
- type DecodedTransaction
- type DecodedTransactionLog
- type DeploymentData
- type Duration
- func (d Duration) Before(t time.Time) time.Time
- func (d Duration) Duration() time.Duration
- func (d Duration) IsInstant() bool
- func (d Duration) MarshalJSON() ([]byte, error)
- func (d Duration) MarshalText() ([]byte, error)
- func (d *Duration) Scan(v interface{}) (err error)
- func (d Duration) Shorter(od Duration) bool
- func (d Duration) String() string
- func (d *Duration) UnmarshalJSON(input []byte) error
- func (d *Duration) UnmarshalText(input []byte) error
- func (d Duration) Value() (driver.Value, error)
- type FundKeyFileCmdOpts
- type FundingDetails
- type GasEstimator
- type GasPercentiles
- type GasSuggestions
- type KeyData
- type KeyFile
- type KeyNonce
- type LogWithEventData
- type Network
- type NonceManager
- type NonceManagerCfg
- type TXCallTraceOutput
- type TXFourByteMetadataOutput
- type Trace
- type TraceLog
- type Tracer
- type TransactOpt
- func WithGasFeeCap(gasFeeCap *big.Int) TransactOpt
- func WithGasLimit(gasLimit uint64) TransactOpt
- func WithGasPrice(gasPrice *big.Int) TransactOpt
- func WithGasTipCap(gasTipCap *big.Int) TransactOpt
- func WithNoSend(noSend bool) TransactOpt
- func WithNonce(nonce *big.Int) TransactOpt
- func WithValue(value *big.Int) TransactOpt
- type TransactionLog
Constants ¶
const ( ErrEmptyConfigPath = "toml config path is empty, set SETH_CONFIG_PATH" ErrCreateABIStore = "failed to create ABI store" ErrReadingKeys = "failed to read keys" ErrCreateNonceManager = "failed to create nonce manager" ErrCreateTracer = "failed to create tracer" ErrReadContractMap = "failed to read deployed contract map" ErrNoKeyLoaded = "failed to load private key" ContractMapFilePattern = "deployed_contracts_%s_%s.toml" )
const ( ErrReadSethConfig = "failed to read TOML config for seth" ErrReadKeyFileConfig = "failed to read TOML keyfile config" ErrUnmarshalSethConfig = "failed to unmarshal TOML config for seth" ErrUnmarshalKeyFileConfig = "failed to unmarshal TOML keyfile config for seth" ErrEmptyNetwork = "no network was selected, set NETWORK=..., check TOML config for available networks and set the env var" ErrEmptyRootPrivateKey = "no private keys were set, set ROOT_PRIVATE_KEY=..." GETH = "Geth" ANVIL = "Anvil" )
const ( ErrOpenABIFile = "failed to open ABI file" ErrParseABI = "failed to parse ABI file" ErrOpenBINFile = "failed to open BIN file" )
const ( ErrDecodeInput = "failed to decode transaction input" ErrDecodeOutput = "failed to decode transaction output" ErrDecodeLog = "failed to decode log" ErrDecodedLogNonIndexed = "failed to decode non-indexed log data" ErrDecodeILogIndexed = "failed to decode indexed log data" ErrNoTxData = "no tx data or it's less than 4 bytes" ErrRPCJSONCastError = "failed to cast CallMsg error as rpc.DataError" WarnNoContractStore = "ContractStore is nil, use seth.NewContractStore(...) to decode transactions" )
const ( ErrKeySyncTimeout = "key sync timeout, consider increasing key_sync_timeout in seth.toml, or increasing the number of keys" ErrKeySync = "failed to sync the key" ErrNonce = "failed to get nonce" )
const ( ErrNoTrace = "no trace found" ErrNoABIMethod = "no ABI method found" ErrNoAbiFound = "no ABI found in Contract Store" ErrNoFourByteFound = "no method signatures found in tracing data" ErrInvalidMethodSignature = "no method signature found or it's not 4 bytes long" ErrSignatureNotFoundIn4Bytes = "signature not found in 4 bytes trace" WrnMissingCallTrace = "" /* 135-byte string literal not displayed */ FAILED_TO_DECODE = "failed to decode" UNKNOWN = "unknown" NO_DATA = "no data" CommentMissingABI = "Call not decoded due to missing ABI instance" )
const ( ErrEmptyKeyFile = "keyfile is empty" ErrInsufficientRootKeyBalance = "insufficient root key balance: %s" )
const (
ErrRPCConnectionRefused = "connection refused"
)
const (
ErrRetryTimeout = "retry timeout"
)
const (
LogLevelEnvVar = "SETH_LOG_LEVEL"
)
Variables ¶
var ( // DefaultEphemeralAddresses is amount of addresses created in ephemeral client mode DefaultEphemeralAddresses int64 = 60 )
var (
L zerolog.Logger
)
Functions ¶
func NewEphemeralKeys ¶
NewEphemeralKeys creates a new ephemeral keyfile, can be used for simulated networks
func ReturnFunds ¶
ReturnFunds returns funds to the root key from all the test keys in some "keyfile.toml"
func SaveDeployedContract ¶
func UpdateAndSplitFunds ¶
func UpdateAndSplitFunds(c *Client, opts *FundKeyFileCmdOpts) error
UpdateAndSplitFunds splits funds from the root key into equal parts
func UpdateKeyFileBalances ¶
UpdateKeyFileBalances updates file balances
Types ¶
type ABIFinder ¶
type ABIFinder struct { ContractMap ContractMap ContractStore *ContractStore }
func NewABIFinder ¶
func NewABIFinder(contractMap ContractMap, contractStore *ContractStore) ABIFinder
func (*ABIFinder) FindABIByMethod ¶
func (a *ABIFinder) FindABIByMethod(address string, signature []byte) (ABIFinderResult, error)
FindABIByMethod finds the ABI method and instance for the given contract address and signature If the contract address is known, it will use the ABI instance that is known to be at the address. If the contract address is not known, it will iterate over all known ABIs and check if any of them has a method with the given signature. If there are duplicates we will use the first ABI that matched.
type ABIFinderResult ¶
type ABIFinderResult struct { ABI abi.ABI Method *abi.Method DuplicateCount int // contains filtered or unexported fields }
func (*ABIFinderResult) ContractName ¶
func (a *ABIFinderResult) ContractName() string
type CallOpt ¶
CallOpt is a functional option for bind.CallOpts
func WithBlockNumber ¶
WithBlockNumber sets blockNumber option for bind.CallOpts
func WithPending ¶
WithPending sets pending option for bind.CallOpts
type Client ¶
type Client struct { Cfg *Config Client *ethclient.Client Addresses []common.Address PrivateKeys []*ecdsa.PrivateKey ChainID int64 URL string Context context.Context CancelFunc context.CancelFunc Errors []error ContractStore *ContractStore NonceManager *NonceManager Tracer *Tracer TraceReverted bool ContractAddressToNameMap ContractMap ABIFinder *ABIFinder }
Client is a vanilla go-ethereum client with enhanced debug logging
func NewClientRaw ¶
func NewClientRaw( cfg *Config, addrs []common.Address, pkeys []*ecdsa.PrivateKey, opts ...ClientOpt, ) (*Client, error)
NewClientRaw creates a new raw seth client without dependencies
func NewClientWithConfig ¶
NewClientWithConfig creates a new seth client with all deps setup from config
func (*Client) AnySyncedKey ¶
AnySyncedKey returns the first synced key
func (*Client) CalculateSubKeyFunding ¶
func (m *Client) CalculateSubKeyFunding(addrs int64) (*FundingDetails, error)
CalculateSubKeyFunding calculates all required params to split funds from the root key to N test keys
func (*Client) CallMsgFromTx ¶
func (m *Client) CallMsgFromTx(tx *types.Transaction) ethereum.CallMsg
CallMsgFromTx creates ethereum.CallMsg from tx, used in simulated calls
func (*Client) CreateOrUnmarshalKeyFile ¶
func (m *Client) CreateOrUnmarshalKeyFile(opts *FundKeyFileCmdOpts) (*KeyFile, error)
func (*Client) Decode ¶
func (m *Client) Decode(tx *types.Transaction, txErr error) (*DecodedTransaction, error)
Decode waits for transaction to be minted and decodes basic info of the first method that was called by the transaction (such as: method name, inputs and any logs/events emitted by the transaction. Additionally if `tracing_enabled` flag is set in Client config it will trace all other calls that were made during the transaction execution and print them to console using logger. If transaction was reverted, then tracing won't take place, but the error return will contain revert reason (if we were able to get it from the receipt).
func (*Client) DecodeCustomABIErr ¶
DecodeCustomABIErr decodes typed Solidity errors
func (*Client) DeployContract ¶
func (m *Client) DeployContract(auth *bind.TransactOpts, name string, abi abi.ABI, bytecode []byte, params ...interface{}) (DeploymentData, error)
DeployContract deploys contract using ABI and bytecode passed to it, waits for transaction to be minted and contract really available at the address, so that when the method returns it's safe to interact with it. It also saves the contract address and ABI name to the contract map, so that we can use that, when tracing transactions. It is suggested to use name identical to the name of the contract Solidity file.
func (*Client) DeployContractFromContractStore ¶
func (m *Client) DeployContractFromContractStore(auth *bind.TransactOpts, name string, params ...interface{}) (DeploymentData, error)
DeployContractFromContractStore deploys contract from Seth's Contract Store, waits for transaction to be minted and contract really available at the address, so that when the method returns it's safe to interact with it. It also saves the contract address and ABI name to the contract map, so that we can use that, when tracing transactions. Name by which you refer the contract should be the same as the name of ABI file (you can omit the .abi suffix).
func (*Client) DeployDebugContract ¶
func (m *Client) DeployDebugContract(subDbgAddr common.Address) (*network_debug_contract.NetworkDebugContract, common.Address, error)
func (*Client) DeployDebugSubContract ¶
func (m *Client) DeployDebugSubContract() (*network_sub_debug_contract.NetworkDebugSubContract, common.Address, error)
func (*Client) NewCallKeyOpts ¶
NewCallKeyOpts returns a new sequential call options wrapper from the key N
func (*Client) NewCallOpts ¶
NewCallOpts returns a new sequential call options wrapper
func (*Client) NewTXKeyOpts ¶
func (m *Client) NewTXKeyOpts(keyNum int, o ...TransactOpt) *bind.TransactOpts
NewTXKeyOpts returns a new transaction options wrapper, sets opts.GasPrice and opts.GasLimit from seth.toml or override with options
func (*Client) NewTXOpts ¶
func (m *Client) NewTXOpts(o ...TransactOpt) *bind.TransactOpts
NewTXOpts returns a new transaction options wrapper, sets opts.GasPrice and opts.GasLimit from seth.toml or override with options
func (*Client) RetryTxAndDecode ¶
func (m *Client) RetryTxAndDecode(f func() (*types.Transaction, error)) (*DecodedTransaction, error)
RetryTxAndDecode executes transaction several times, retries if connection is lost and decodes all the data
func (*Client) SaveDecodedCallsAsJson ¶
func (*Client) TransferETHFromKey ¶
type ClientOpt ¶
type ClientOpt func(c *Client)
ClientOpt is a client functional option
func WithABIFinder ¶
WithABIFinder ABIFinder functional option
func WithContractMap ¶
WithContractMap contractAddressToNameMap functional option
func WithContractStore ¶
func WithContractStore(as *ContractStore) ClientOpt
WithContractStore ContractStore functional option
func WithNonceManager ¶
func WithNonceManager(nm *NonceManager) ClientOpt
WithNonceManager NonceManager functional option
type CommonData ¶
type Config ¶
type Config struct { EphemeralAddrs *int64 `toml:"ephemeral_addresses_number"` ABIDir string `toml:"abi_dir"` BINDir string `toml:"bin_dir"` ContractMapFile string `toml:"contract_map_file"` KeyFilePath string Network *Network `toml:"network"` Networks []*Network `toml:"networks"` NonceManager *NonceManagerCfg `toml:"nonce_manager"` TracingEnabled bool `toml:"tracing_enabled"` TraceToJson bool `toml:"trace_to_json"` // internal fields ConfigDir string `toml:"abs_path"` // contains filtered or unexported fields }
func ReadConfig ¶
func (*Config) GenerateContractMapFileName ¶
func (*Config) IsSimulatedNetwork ¶
type ContractMap ¶
func (ContractMap) AddContract ¶
func (c ContractMap) AddContract(addr, name string)
func (ContractMap) GetContractAddress ¶
func (c ContractMap) GetContractAddress(addr string) string
func (ContractMap) GetContractName ¶
func (c ContractMap) GetContractName(addr string) string
func (ContractMap) IsKnownAddress ¶
func (c ContractMap) IsKnownAddress(addr string) bool
type ContractStore ¶
ContractStore contains all ABIs that are used in decoding. It might also contain contract bytecode for deployment
func NewContractStore ¶
func NewContractStore(abiPath, binPath string) (*ContractStore, error)
NewContractStore creates a new Contract store
func (*ContractStore) AddBIN ¶
func (c *ContractStore) AddBIN(name string, bin []byte)
type DecodableLog ¶
type DecodedCall ¶
type DecodedCall struct { CommonData FromAddress string `json:"from_address,omitempty"` ToAddress string `json:"to_address,omitempty"` From string `json:"from,omitempty"` To string `json:"to,omitempty"` Events []DecodedCommonLog `json:"events,omitempty"` Comment string `json:"comment,omitempty"` Value int64 `json:"value,omitempty"` GasLimit uint64 `json:"gas_limit,omitempty"` GasUsed uint64 `json:"gas_used,omitempty"` }
DecodedCall decoded call
type DecodedCommonLog ¶
type DecodedCommonLog struct { Signature string `json:"signature"` Address common.Address `json:"address"` EventData map[string]interface{} `json:"event_data"` Topics []string `json:"topics,omitempty"` }
func (*DecodedCommonLog) MergeEventData ¶
func (d *DecodedCommonLog) MergeEventData(newEventData map[string]interface{})
type DecodedTransaction ¶
type DecodedTransaction struct { CommonData Index uint `json:"index"` Hash string `json:"hash,omitempty"` Protected bool `json:"protected,omitempty"` Transaction *types.Transaction `json:"transaction,omitempty"` Receipt *types.Receipt `json:"receipt,omitempty"` Events []DecodedTransactionLog `json:"events,omitempty"` }
DecodedTransaction decoded transaction
type DecodedTransactionLog ¶
type DecodedTransactionLog struct { DecodedCommonLog BlockNumber uint64 `json:"block_number"` Index uint `json:"index"` TXHash string `json:"hash"` TXIndex uint `json:"tx_index"` Removed bool `json:"removed"` FileTag string `json:"file_tag,omitempty"` }
DecodedTransactionLog decoded Solidity log(event)
func (*DecodedTransactionLog) MergeEventData ¶
func (d *DecodedTransactionLog) MergeEventData(newEventData map[string]interface{})
type DeploymentData ¶
type DeploymentData struct { Address common.Address Transaction *types.Transaction BoundContract *bind.BoundContract }
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration is a non-negative time duration.
func MustMakeDuration ¶
func ParseDuration ¶
func (Duration) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Duration) MarshalText ¶
MarshalText implements the text.Marshaler interface.
func (Duration) String ¶
String returns a string representing the duration in the form "72h3m0.5s". Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. The zero duration formats as 0s.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Duration) UnmarshalText ¶
UnmarshalText implements the text.Unmarshaler interface.
type FundKeyFileCmdOpts ¶
type FundKeyFileCmdOpts struct {
Addrs int64
}
FundKeyFileCmdOpts funding params for CLI
type FundingDetails ¶
type FundingDetails struct { RootBalance *big.Int TotalFee *big.Int FreeBalance *big.Int AddrFunding *big.Int NetworkTransferFee int64 }
FundingDetails funding details about shares we put into test keys
type GasEstimator ¶
GasEstimator estimates gas prices
func NewGasEstimator ¶
func NewGasEstimator(c *Client) *GasEstimator
NewGasEstimator creates a new gas estimator
func (*GasEstimator) Stats ¶
func (m *GasEstimator) Stats(fromNumber uint64, priorityPerc float64) (GasSuggestions, error)
Stats prints gas stats
type GasPercentiles ¶
type GasPercentiles struct { Max float64 Perc99 float64 Perc75 float64 Perc50 float64 Perc25 float64 }
GasPercentiles contains gas percentiles
type GasSuggestions ¶
type GasSuggestions struct { GasPrice *GasPercentiles TipCap *GasPercentiles }
type KeyData ¶
type KeyData struct { PrivateKey string `toml:"private_key"` Address string `toml:"address"` Funds string `toml:"funds"` }
KeyData data for test keys
type KeyFile ¶
type KeyFile struct {
Keys []*KeyData `toml:"keys"`
}
KeyFile is a struct that holds all test keys data
func NewKeyFile ¶
func NewKeyFile() *KeyFile
type LogWithEventData ¶
type LogWithEventData interface {
MergeEventData(map[string]interface{})
}
type Network ¶
type Network struct { Name string `toml:"name"` ChainID string `toml:"chain_id"` URLs []string `toml:"urls_secret"` EIP1559DynamicFees bool `toml:"eip_1559_dynamic_fees"` GasPrice int64 `toml:"gas_price"` GasFeeCap int64 `toml:"gas_fee_cap"` GasTipCap int64 `toml:"gas_tip_cap"` GasLimit uint64 `toml:"gas_limit"` TxnTimeout *Duration `toml:"transaction_timeout"` TransferGasFee int64 `toml:"transfer_gas_fee"` PrivateKeys []string `toml:"private_keys_secret"` }
type NonceManager ¶
type NonceManager struct { *sync.Mutex Client *Client SyncTimeout time.Duration SyncedKeys chan *KeyNonce Addresses []common.Address PrivateKeys []*ecdsa.PrivateKey Nonces map[common.Address]int64 // contains filtered or unexported fields }
NonceManager tracks nonce for each address
func NewNonceManager ¶
func NewNonceManager(cfg *Config, addrs []common.Address, privKeys []*ecdsa.PrivateKey) (*NonceManager, error)
NewNonceManager creates a new nonce manager that tracks nonce for each address
func (*NonceManager) NextNonce ¶
func (m *NonceManager) NextNonce(addr common.Address) *big.Int
NextNonce returns new nonce for addr this method is external for module testing, but you should not use it since handling nonces on the client is unpredictable
func (*NonceManager) UpdateNonces ¶
func (m *NonceManager) UpdateNonces() error
UpdateNonces syncs nonces for addresses
type NonceManagerCfg ¶
type TXCallTraceOutput ¶
func (*TXCallTraceOutput) AsCall ¶
func (t *TXCallTraceOutput) AsCall() Call
type Trace ¶
type Trace struct { TxHash string FourByte map[string]*TXFourByteMetadataOutput CallTrace *TXCallTraceOutput OpCodesTrace map[string]interface{} }
type TraceLog ¶
type Tracer ¶
type Tracer struct { Cfg *Config Addresses []common.Address ContractStore *ContractStore ContractAddressToNameMap ContractMap DecodedCalls map[string][]*DecodedCall ABIFinder *ABIFinder // contains filtered or unexported fields }
func (*Tracer) DecodeTrace ¶
DecodeTrace decodes the trace of a transaction including all subcalls. It returns a list of decoded calls. Depending on the config it also saves the decoded calls as JSON files.
func (*Tracer) PrintTXTrace ¶
func (*Tracer) SaveDecodedCallsAsJson ¶
func (*Tracer) TraceGethTX ¶
type TransactOpt ¶
type TransactOpt func(o *bind.TransactOpts)
TransactOpt is a wrapper for bind.TransactOpts
func WithGasFeeCap ¶
func WithGasFeeCap(gasFeeCap *big.Int) TransactOpt
WithGasFeeCap sets gasFeeCap option for bind.TransactOpts
func WithGasLimit ¶
func WithGasLimit(gasLimit uint64) TransactOpt
WithGasLimit sets gasLimit option for bind.TransactOpts
func WithGasPrice ¶
func WithGasPrice(gasPrice *big.Int) TransactOpt
WithGasPrice sets gasPrice option for bind.TransactOpts
func WithGasTipCap ¶
func WithGasTipCap(gasTipCap *big.Int) TransactOpt
WithGasTipCap sets gasTipCap option for bind.TransactOpts
func WithNoSend ¶
func WithNoSend(noSend bool) TransactOpt
WithNoSend sets noSend option for bind.TransactOpts
func WithNonce ¶
func WithNonce(nonce *big.Int) TransactOpt
WithNonce sets nonce option for bind.TransactOpts
func WithValue ¶
func WithValue(value *big.Int) TransactOpt
WithValue sets value option for bind.TransactOpts
type TransactionLog ¶
func (TransactionLog) GetData ¶
func (t TransactionLog) GetData() []byte
func (TransactionLog) GetTopics ¶
func (t TransactionLog) GetTopics() []common.Hash