fetcher

package
v0.0.0-...-e1f3134 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockByNumber

func BlockByNumber(number *big.Int) w3types.CallerFactory[RPCBlock]

BlockByNumber requests the block with the given number with full transactions. If number is nil, the latest block is requested.

func BlockNumberArg

func BlockNumberArg(blockNumber *big.Int) string

func GetCallTraceCaller

func GetCallTraceCaller(msg *w3types.Message, blockNumber *big.Int, config *CallTracerConfig, stateOverrides StateOverride) w3types.CallerFactory[CallTrace]

func GetPrestateTraceCaller

func GetPrestateTraceCaller(msg *w3types.Message, blockNumber *big.Int, config *PrestateTracerConfig, stateOverrides StateOverride) w3types.CallerFactory[PrestateTrace]

func NewRPCFetcher

func NewRPCFetcher(client *w3.Client, blockNumber *big.Int) *rpcFetcher

NewRPCFetcher returns a new Fetcher that fetches account state from the given RPC client for the given block number.

Note, that the returned state for a given block number is the state after the execution of that block.

func NewStreamingFetcher

func NewStreamingFetcher(client *w3.Client) w3vm.Fetcher

func TraceCaller

func TraceCaller[TC, TT any](method string, msg *w3types.Message, blockNumber *big.Int, tracerConfig *TraceConfig[TC]) w3types.CallerFactory[TT]

CallTraceCall requests the call trace of the given message.

Types

type Account

type Account struct {
	Balance *hexutil.Big                `json:"balance,omitempty"`
	Code    *hexutil.Bytes              `json:"code,omitempty"`
	Nonce   *uint64                     `json:"nonce,omitempty"`
	Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
}

func (*Account) CodeHash

func (a *Account) CodeHash() common.Hash

type ArgsWrapperFunc

type ArgsWrapperFunc func([]any) ([]any, error)

type CallTrace

type CallTrace struct {
	From    common.Address `json:"from"`
	To      common.Address `json:"to"`
	Type    string         `json:"type"`
	Gas     hexutil.Uint64 `json:"gas"`
	GasUsed hexutil.Uint64 `json:"gasUsed"`
	Value   *hexutil.Big   `json:"value"`
	Input   hexutil.Bytes  `json:"input"`
	Output  hexutil.Bytes  `json:"output"`
	Error   string         `json:"error"`
	Calls   []*CallTrace   `json:"calls"`
}

type CallTracerConfig

type CallTracerConfig struct {
	OnlyTopCall bool `json:"onlyTopCall"`
	WithLog     bool `json:"withLog"`
}

type Factory

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

func GetPrestateTraceBlockCaller

func GetPrestateTraceBlockCaller(blockNumber *types.NumberOrBlockTag, config *PrestateTracerConfig, stateOverrides StateOverride) *Factory[TraceBlock[PrestateTrace]]

func NewFactory

func NewFactory[T any](method string, args []any, opts ...Option[T]) *Factory[T]

func TraceBlockCaller

func TraceBlockCaller[TC, TT any](method string, blockNumber *types.NumberOrBlockTag, tracerConfig *TraceConfig[TC]) *Factory[TT]

func (Factory[T]) CreateRequest

func (f Factory[T]) CreateRequest() (rpc.BatchElem, error)

func (Factory[T]) HandleResponse

func (f Factory[T]) HandleResponse(elem rpc.BatchElem) error

func (Factory[T]) Returns

func (f Factory[T]) Returns(ret *T) w3types.Caller

type Fetcher

type Fetcher interface {

	// Nonce fetches the nonce of the given address.
	Nonce(common.Address) (uint64, error)

	// Balance fetches the balance of the given address.
	Balance(common.Address) (*big.Int, error)

	// Code fetches the code of the given address.
	Code(common.Address) ([]byte, error)

	// StorageAt fetches the state of the given address and storage slot.
	StorageAt(common.Address, common.Hash) (common.Hash, error)

	// HeaderHash fetches the hash of the header with the given number.
	HeaderHash(*big.Int) (common.Hash, error)
}

Fetcher is the interface to access account state of a blockchain.

type Option

type Option[T any] func(*Factory[T])

the following is borrowed from w3

func WithArgsWrapper

func WithArgsWrapper[T any](fn ArgsWrapperFunc) Option[T]

func WithRetWrapper

func WithRetWrapper[T any](fn RetWrapperFunc[T]) Option[T]

type OverrideAccount

type OverrideAccount struct {
	Nonce     *hexutil.Uint64             `json:"nonce,omitempty"`
	Code      *hexutil.Bytes              `json:"code,omitempty"`
	Balance   *hexutil.Big                `json:"balance,omitempty"`
	State     map[common.Hash]common.Hash `json:"state,omitempty"`
	StateDiff map[common.Hash]common.Hash `json:"stateDiff,omitempty"`
}

OverrideAccount indicates the overriding fields of account during the execution of a message call. Note, state and stateDiff can't be specified at the same time. If state is set, message execution will only use the data in the given state. Otherwise if statDiff is set, all diff will be applied first and then execute the call message.

type PrestateTrace

type PrestateTrace struct {
	Post State `json:"post,omitempty"`
	Pre  State `json:"pre"`
}

type PrestateTracerConfig

type PrestateTracerConfig struct {
	DiffMode bool `json:"diffMode"` // If true, this tracer will return state modifications
}

type RPCBlock

type RPCBlock struct {
	ParentHash      common.Hash         `json:"parentHash"`
	UncleHash       common.Hash         `json:"sha3Uncles"`
	Coinbase        common.Address      `json:"miner"`
	Root            common.Hash         `json:"stateRoot"`
	TxHash          common.Hash         `json:"transactionsRoot"`
	ReceiptHash     common.Hash         `json:"receiptsRoot"`
	Bloom           ethTypes.Bloom      `json:"logsBloom"`
	Difficulty      *hexutil.Big        `json:"difficulty"`
	Number          *hexutil.Big        `json:"number"`
	GasLimit        hexutil.Uint64      `json:"gasLimit"`
	GasUsed         hexutil.Uint64      `json:"gasUsed"`
	Time            hexutil.Uint64      `json:"timestamp"`
	Extra           hexutil.Bytes       `json:"extraData"`
	MixDigest       common.Hash         `json:"mixHash"`
	Nonce           ethTypes.BlockNonce `json:"nonce"`
	Transactions    []*RPCTransaction   `json:"transactions"`                             // added
	ChainID         *hexutil.Big        `json:"chainId,omitempty"`                        // non standard
	BaseFee         *hexutil.Big        `json:"baseFeePerGas,omitempty" rlp:"optional"`   // BaseFee was added by EIP-1559 and is ignored in legacy headers.
	WithdrawalsHash *common.Hash        `json:"withdrawalsRoot,omitempty" rlp:"optional"` // WithdrawalsHash was added by EIP-4895 and is ignored in legacy headers.
	ExcessDataGas   *hexutil.Big        `json:"excessDataGas,omitempty" rlp:"optional"`   // ExcessDataGas was added by EIP-4844 and is ignored in legacy headers.
}

type RPCTransaction

type RPCTransaction struct {
	Type hexutil.Uint64 `json:"type"`

	ChainID              *hexutil.Big         `json:"chainId,omitempty"`
	Nonce                hexutil.Uint64       `json:"nonce"`
	To                   *common.Address      `json:"to"`
	Gas                  hexutil.Uint64       `json:"gas"`
	GasPrice             *hexutil.Big         `json:"gasPrice"`
	MaxPriorityFeePerGas *hexutil.Big         `json:"maxPriorityFeePerGas"`
	MaxFeePerGas         *hexutil.Big         `json:"maxFeePerGas"`
	MaxFeePerBlobGas     *hexutil.Big         `json:"maxFeePerBlobGas,omitempty"`
	Value                *hexutil.Big         `json:"value"`
	Input                *hexutil.Bytes       `json:"input"`
	AccessList           *ethTypes.AccessList `json:"accessList,omitempty"`
	BlobVersionedHashes  []common.Hash        `json:"blobVersionedHashes,omitempty"`
	V                    *hexutil.Big         `json:"v"`
	R                    *hexutil.Big         `json:"r"`
	S                    *hexutil.Big         `json:"s"`
	YParity              *hexutil.Uint64      `json:"yParity,omitempty"`

	// Arbitrum fields:
	From                *common.Address `json:"from,omitempty"`                // Contract SubmitRetryable Unsigned Retry
	RequestId           *common.Hash    `json:"requestId,omitempty"`           // Contract SubmitRetryable Deposit
	TicketId            *common.Hash    `json:"ticketId,omitempty"`            // Retry
	MaxRefund           *hexutil.Big    `json:"maxRefund,omitempty"`           // Retry
	SubmissionFeeRefund *hexutil.Big    `json:"submissionFeeRefund,omitempty"` // Retry
	RefundTo            *common.Address `json:"refundTo,omitempty"`            // SubmitRetryable Retry
	L1BaseFee           *hexutil.Big    `json:"l1BaseFee,omitempty"`           // SubmitRetryable
	DepositValue        *hexutil.Big    `json:"depositValue,omitempty"`        // SubmitRetryable
	RetryTo             *common.Address `json:"retryTo,omitempty"`             // SubmitRetryable
	RetryValue          *hexutil.Big    `json:"retryValue,omitempty"`          // SubmitRetryable
	RetryData           *hexutil.Bytes  `json:"retryData,omitempty"`           // SubmitRetryable
	Beneficiary         *common.Address `json:"beneficiary,omitempty"`         // SubmitRetryable
	MaxSubmissionFee    *hexutil.Big    `json:"maxSubmissionFee,omitempty"`    // SubmitRetryable
	EffectiveGasPrice   *hexutil.Uint64 `json:"effectiveGasPrice,omitempty"`   // ArbLegacy
	L1BlockNumber       *hexutil.Uint64 `json:"l1BlockNumber,omitempty"`       // ArbLegacy

	// Only used for encoding:
	Hash common.Hash `json:"hash"`
}

func (*RPCTransaction) ToW3Message

func (tx *RPCTransaction) ToW3Message() *w3types.Message

type RetWrapperFunc

type RetWrapperFunc[T any] func(*T) any

type State

type State = map[common.Address]*Account

type StateOverride

type StateOverride map[common.Address]OverrideAccount

StateOverride is the collection of overridden accounts.

type StateUpdate

type StateUpdate struct {
	TraceBlock TraceBlock[PrestateTrace]
	Block      *ethTypes.Block
}

type StreamingFetcher

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

func (*StreamingFetcher) Balance

func (*StreamingFetcher) Balance(common.Address) (*big.Int, error)

Balance implements w3vm.Fetcher.

func (*StreamingFetcher) Code

Code implements w3vm.Fetcher.

func (*StreamingFetcher) HeaderHash

func (*StreamingFetcher) HeaderHash(*big.Int) (common.Hash, error)

HeaderHash implements w3vm.Fetcher.

func (*StreamingFetcher) Nonce

Nonce implements w3vm.Fetcher.

func (*StreamingFetcher) StorageAt

StorageAt implements w3vm.Fetcher.

type TraceBlock

type TraceBlock[TC any] []*txTraceResult[TC]

type TraceConfig

type TraceConfig[TC any] struct {
	Tracer         string        `json:"tracer"`
	TracerConfig   *TC           `json:"tracerConfig,omitempty"`
	StateOverrides StateOverride `json:"stateOverrides,omitempty"`
}

Jump to

Keyboard shortcuts

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