types

package
v0.0.5-RC3 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: AGPL-3.0, AGPL-3.0-or-later Imports: 15 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// PendingBlockNumber represents the pending block number
	PendingBlockNumber = BlockNumber(-3)
	// LatestBlockNumber represents the latest block number
	LatestBlockNumber = BlockNumber(-2)
	// EarliestBlockNumber represents the earliest block number
	EarliestBlockNumber = BlockNumber(-1)

	// LatestBatchNumber represents the latest batch number
	LatestBatchNumber = BatchNumber(-2)
	// EarliestBatchNumber represents the earliest batch number
	EarliestBatchNumber = BatchNumber(-1)

	// Earliest contains the string to represent the earliest block known.
	Earliest = "earliest"
	// Latest contains the string to represent the latest block known.
	Latest = "latest"
	// Pending contains the string to represent pending blocks.
	Pending = "pending"

	// BlockNumberKey is the key for the block number for EIP-1898
	BlockNumberKey = "blockNumber"
	// BlockHashKey is the key for the block hash for EIP-1898
	BlockHashKey = "blockHash"
	// RequireCanonicalKey is the key for the require canonical for EIP-1898
	RequireCanonicalKey = "requireCanonical"
)
View Source
const (
	// DefaultErrorCode rpc default error code
	DefaultErrorCode = -32000
	// RevertedErrorCode error code for reverted txs
	RevertedErrorCode = 3
	// InvalidRequestErrorCode error code for invalid requests
	InvalidRequestErrorCode = -32600
	// NotFoundErrorCode error code for not found objects
	NotFoundErrorCode = -32601
	// InvalidParamsErrorCode error code for invalid parameters
	InvalidParamsErrorCode = -32602
	// ParserErrorCode error code for parsing errors
	ParserErrorCode = -32700
)

Variables

This section is empty.

Functions

func ToBatchNumArg

func ToBatchNumArg(number *big.Int) string

ToBatchNumArg converts a big.Int into a batch number rpc parameter

Types

type ArgAddress

type ArgAddress common.Address

ArgAddress represents a common.Address that accepts strings shorter than 32 bytes, like 0x00

func (*ArgAddress) Address

func (arg *ArgAddress) Address() common.Address

Address returns an instance of common.Address

func (*ArgAddress) UnmarshalText

func (b *ArgAddress) UnmarshalText(input []byte) error

UnmarshalText unmarshals from text

type ArgBig

type ArgBig big.Int

ArgBig helps to marshal big number values provided in the RPC requests

func (ArgBig) Hex

func (b ArgBig) Hex() string

Hex returns a hexadecimal representation

func (ArgBig) MarshalText

func (a ArgBig) MarshalText() ([]byte, error)

MarshalText marshals an array of bytes into an instance of ArgBig

func (*ArgBig) UnmarshalText

func (a *ArgBig) UnmarshalText(input []byte) error

UnmarshalText unmarshals an instance of ArgBig into an array of bytes

type ArgBytes

type ArgBytes []byte

ArgBytes helps to marshal byte array values provided in the RPC requests

func ArgBytesPtr

func ArgBytesPtr(b []byte) *ArgBytes

ArgBytesPtr helps to marshal byte array values provided in the RPC requests

func (ArgBytes) Hex

func (b ArgBytes) Hex() string

Hex returns a hexadecimal representation

func (ArgBytes) MarshalText

func (b ArgBytes) MarshalText() ([]byte, error)

MarshalText marshals into text

func (*ArgBytes) UnmarshalText

func (b *ArgBytes) UnmarshalText(input []byte) error

UnmarshalText unmarshals from text

type ArgHash

type ArgHash common.Hash

ArgHash represents a common.Hash that accepts strings shorter than 64 bytes, like 0x00

func (*ArgHash) Hash

func (arg *ArgHash) Hash() common.Hash

Hash returns an instance of common.Hash

func (*ArgHash) UnmarshalText

func (arg *ArgHash) UnmarshalText(input []byte) error

UnmarshalText unmarshals from text

type ArgUint64

type ArgUint64 uint64

ArgUint64 helps to marshal uint64 values provided in the RPC requests

func ArgUint64Ptr

func ArgUint64Ptr(a ArgUint64) *ArgUint64

ArgUint64Ptr returns the pointer of the provided ArgUint64

func (ArgUint64) Hex

func (b ArgUint64) Hex() string

Hex returns a hexadecimal representation

func (ArgUint64) MarshalText

func (b ArgUint64) MarshalText() ([]byte, error)

MarshalText marshals into text

func (*ArgUint64) UnmarshalText

func (b *ArgUint64) UnmarshalText(input []byte) error

UnmarshalText unmarshals from text

type Batch

type Batch struct {
	Number              ArgUint64           `json:"number"`
	Coinbase            common.Address      `json:"coinbase"`
	StateRoot           common.Hash         `json:"stateRoot"`
	GlobalExitRoot      common.Hash         `json:"globalExitRoot"`
	MainnetExitRoot     common.Hash         `json:"mainnetExitRoot"`
	RollupExitRoot      common.Hash         `json:"rollupExitRoot"`
	LocalExitRoot       common.Hash         `json:"localExitRoot"`
	AccInputHash        common.Hash         `json:"accInputHash"`
	Timestamp           ArgUint64           `json:"timestamp"`
	SendSequencesTxHash *common.Hash        `json:"sendSequencesTxHash"`
	VerifyBatchTxHash   *common.Hash        `json:"verifyBatchTxHash"`
	Transactions        []TransactionOrHash `json:"transactions"`
}

Batch structure

func NewBatch

func NewBatch(batch *state.Batch, virtualBatch *state.VirtualBatch, verifiedBatch *state.VerifiedBatch, receipts []types.Receipt, fullTx bool, ger *state.GlobalExitRoot) *Batch

NewBatch creates a Batch instance

type BatchNumber

type BatchNumber int64

BatchNumber is the number of a ethereum block

func (*BatchNumber) GetNumericBatchNumber

func (b *BatchNumber) GetNumericBatchNumber(ctx context.Context, s StateInterface, dbTx pgx.Tx) (uint64, Error)

GetNumericBatchNumber returns a numeric batch number based on the BatchNumber instance

func (*BatchNumber) UnmarshalJSON

func (b *BatchNumber) UnmarshalJSON(buffer []byte) error

UnmarshalJSON automatically decodes the user input for the block number, when a JSON RPC method is called

type Block

type Block struct {
	ParentHash      common.Hash         `json:"parentHash"`
	Sha3Uncles      common.Hash         `json:"sha3Uncles"`
	Miner           common.Address      `json:"miner"`
	StateRoot       common.Hash         `json:"stateRoot"`
	TxRoot          common.Hash         `json:"transactionsRoot"`
	ReceiptsRoot    common.Hash         `json:"receiptsRoot"`
	LogsBloom       types.Bloom         `json:"logsBloom"`
	Difficulty      ArgUint64           `json:"difficulty"`
	TotalDifficulty ArgUint64           `json:"totalDifficulty"`
	Size            ArgUint64           `json:"size"`
	Number          ArgUint64           `json:"number"`
	GasLimit        ArgUint64           `json:"gasLimit"`
	GasUsed         ArgUint64           `json:"gasUsed"`
	Timestamp       ArgUint64           `json:"timestamp"`
	ExtraData       ArgBytes            `json:"extraData"`
	MixHash         common.Hash         `json:"mixHash"`
	Nonce           ArgBytes            `json:"nonce"`
	Hash            common.Hash         `json:"hash"`
	Transactions    []TransactionOrHash `json:"transactions"`
	Uncles          []common.Hash       `json:"uncles"`
}

Block structure

func NewBlock

func NewBlock(b *types.Block, fullTx bool) *Block

NewBlock creates a Block instance

type BlockNumber

type BlockNumber int64

BlockNumber is the number of a ethereum block

func StringToBlockNumber

func StringToBlockNumber(str string) (BlockNumber, error)

StringToBlockNumber converts a string like "latest" or "0x1" to a BlockNumber instance

func (*BlockNumber) GetNumericBlockNumber

func (b *BlockNumber) GetNumericBlockNumber(ctx context.Context, s StateInterface, dbTx pgx.Tx) (uint64, Error)

GetNumericBlockNumber returns a numeric block number based on the BlockNumber instance

func (*BlockNumber) StringOrHex

func (b *BlockNumber) StringOrHex() string

StringOrHex returns the block number as a string or hex n == -3 = pending n == -2 = latest n == -1 = earliest n >= 0 = hex(n)

func (*BlockNumber) UnmarshalJSON

func (b *BlockNumber) UnmarshalJSON(buffer []byte) error

UnmarshalJSON automatically decodes the user input for the block number, when a JSON RPC method is called

type BlockNumberOrHash

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

BlockNumberOrHash allows a string value to be parsed into a block number or a hash, it's used by methods like eth_call that allows the block to be specified either by the block number or the block hash

func (*BlockNumberOrHash) Hash

func (b *BlockNumberOrHash) Hash() *ArgHash

Hash returns the hash

func (*BlockNumberOrHash) IsHash

func (b *BlockNumberOrHash) IsHash() bool

IsHash checks if the hash has value

func (*BlockNumberOrHash) IsNumber

func (b *BlockNumberOrHash) IsNumber() bool

IsNumber checks if the number has value

func (*BlockNumberOrHash) Number

func (b *BlockNumberOrHash) Number() *BlockNumber

Number returns the number

func (*BlockNumberOrHash) SetHash

func (b *BlockNumberOrHash) SetHash(hash ArgHash, requireCanonical bool)

SetHash sets the hash and nullify the number

func (*BlockNumberOrHash) SetNumber

func (b *BlockNumberOrHash) SetNumber(number BlockNumber)

SetNumber sets the number and nullify the hash

func (*BlockNumberOrHash) UnmarshalJSON

func (b *BlockNumberOrHash) UnmarshalJSON(buffer []byte) error

UnmarshalJSON automatically decodes the user input for the block number, when a JSON RPC method is called

type Error

type Error interface {
	Error() string
	ErrorCode() int
	ErrorData() *[]byte
}

Error interface

type ErrorObject

type ErrorObject struct {
	Code    int       `json:"code"`
	Message string    `json:"message"`
	Data    *ArgBytes `json:"data,omitempty"`
}

ErrorObject is a jsonrpc error

type Index

type Index int64

Index of a item

func (*Index) UnmarshalJSON

func (i *Index) UnmarshalJSON(buffer []byte) error

UnmarshalJSON automatically decodes the user input for the block number, when a JSON RPC method is called

type Log

type Log struct {
	Address     common.Address `json:"address"`
	Topics      []common.Hash  `json:"topics"`
	Data        ArgBytes       `json:"data"`
	BlockNumber ArgUint64      `json:"blockNumber"`
	TxHash      common.Hash    `json:"transactionHash"`
	TxIndex     ArgUint64      `json:"transactionIndex"`
	BlockHash   common.Hash    `json:"blockHash"`
	LogIndex    ArgUint64      `json:"logIndex"`
	Removed     bool           `json:"removed"`
}

Log structure

func NewLog

func NewLog(l types.Log) Log

NewLog creates a new instance of Log

type LogFilterRequest

type LogFilterRequest struct {
	BlockHash *common.Hash  `json:"blockHash,omitempty"`
	FromBlock *string       `json:"fromBlock,omitempty"`
	ToBlock   *string       `json:"toBlock,omitempty"`
	Address   interface{}   `json:"address,omitempty"`
	Topics    []interface{} `json:"topics,omitempty"`
}

LogFilterRequest represents a log filter request.

type PoolInterface

type PoolInterface interface {
	AddTx(ctx context.Context, tx types.Transaction, ip string) error
	GetGasPrice(ctx context.Context) (uint64, error)
	GetNonce(ctx context.Context, address common.Address) (uint64, error)
	GetPendingTxHashesSince(ctx context.Context, since time.Time) ([]common.Hash, error)
	GetPendingTxs(ctx context.Context, isClaims bool, limit uint64) ([]pool.Transaction, error)
	CountPendingTransactions(ctx context.Context) (uint64, error)
	GetTxByHash(ctx context.Context, hash common.Hash) (*pool.Transaction, error)
}

PoolInterface contains the methods required to interact with the tx pool.

type RPCError

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

RPCError represents an error returned by a JSON RPC endpoint.

func NewRPCError

func NewRPCError(code int, err string, args ...interface{}) *RPCError

NewRPCError creates a new error instance to be returned by the RPC endpoints

func NewRPCErrorWithData

func NewRPCErrorWithData(code int, err string, data *[]byte, args ...interface{}) *RPCError

NewRPCErrorWithData creates a new error instance with data to be returned by the RPC endpoints

func (*RPCError) Error

func (e *RPCError) Error() string

Error returns the error message.

func (*RPCError) ErrorCode

func (e *RPCError) ErrorCode() int

ErrorCode returns the error code.

func (*RPCError) ErrorData

func (e *RPCError) ErrorData() *[]byte

ErrorData returns the error data.

type Receipt

type Receipt struct {
	Root              common.Hash     `json:"root"`
	CumulativeGasUsed ArgUint64       `json:"cumulativeGasUsed"`
	LogsBloom         types.Bloom     `json:"logsBloom"`
	Logs              []*types.Log    `json:"logs"`
	Status            ArgUint64       `json:"status"`
	TxHash            common.Hash     `json:"transactionHash"`
	TxIndex           ArgUint64       `json:"transactionIndex"`
	BlockHash         common.Hash     `json:"blockHash"`
	BlockNumber       ArgUint64       `json:"blockNumber"`
	GasUsed           ArgUint64       `json:"gasUsed"`
	FromAddr          common.Address  `json:"from"`
	ToAddr            *common.Address `json:"to"`
	ContractAddress   *common.Address `json:"contractAddress"`
	Type              ArgUint64       `json:"type"`
}

Receipt structure

func NewReceipt

func NewReceipt(tx types.Transaction, r *types.Receipt) (Receipt, error)

NewReceipt creates a new Receipt instance

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request is a jsonrpc request

type Response

type Response struct {
	JSONRPC string
	ID      interface{}
	Result  json.RawMessage
	Error   *ErrorObject
}

Response is a jsonrpc success response

func NewResponse

func NewResponse(req Request, reply []byte, err Error) Response

NewResponse returns Success/Error response object

func (Response) Bytes

func (s Response) Bytes() ([]byte, error)

Bytes return the serialized response

func (Response) MarshalJSON

func (r Response) MarshalJSON() ([]byte, error)

MarshalJSON customizes the JSON representation of the response.

type StateInterface

type StateInterface interface {
	PrepareWebSocket()
	BeginStateTransaction(ctx context.Context) (pgx.Tx, error)
	DebugTransaction(ctx context.Context, transactionHash common.Hash, traceConfig state.TraceConfig, dbTx pgx.Tx) (*runtime.ExecutionResult, error)
	EstimateGas(transaction *types.Transaction, senderAddress common.Address, l2BlockNumber *uint64, dbTx pgx.Tx) (uint64, error)
	GetBalance(ctx context.Context, address common.Address, root common.Hash) (*big.Int, error)
	GetCode(ctx context.Context, address common.Address, root common.Hash) ([]byte, error)
	GetL2BlockByHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (*types.Block, error)
	GetL2BlockByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*types.Block, error)
	BatchNumberByL2BlockNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (uint64, error)
	GetL2BlockHashesSince(ctx context.Context, since time.Time, dbTx pgx.Tx) ([]common.Hash, error)
	GetL2BlockHeaderByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*types.Header, error)
	GetL2BlockTransactionCountByHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (uint64, error)
	GetL2BlockTransactionCountByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (uint64, error)
	GetLastConsolidatedL2BlockNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
	GetLastL2Block(ctx context.Context, dbTx pgx.Tx) (*types.Block, error)
	GetLastL2BlockNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
	GetLogs(ctx context.Context, fromBlock uint64, toBlock uint64, addresses []common.Address, topics [][]common.Hash, blockHash *common.Hash, since *time.Time, dbTx pgx.Tx) ([]*types.Log, error)
	GetNonce(ctx context.Context, address common.Address, root common.Hash) (uint64, error)
	GetStorageAt(ctx context.Context, address common.Address, position *big.Int, root common.Hash) (*big.Int, error)
	GetSyncingInfo(ctx context.Context, dbTx pgx.Tx) (state.SyncingInfo, error)
	GetTransactionByHash(ctx context.Context, transactionHash common.Hash, dbTx pgx.Tx) (*types.Transaction, error)
	GetTransactionByL2BlockHashAndIndex(ctx context.Context, blockHash common.Hash, index uint64, dbTx pgx.Tx) (*types.Transaction, error)
	GetTransactionByL2BlockNumberAndIndex(ctx context.Context, blockNumber uint64, index uint64, dbTx pgx.Tx) (*types.Transaction, error)
	GetTransactionReceipt(ctx context.Context, transactionHash common.Hash, dbTx pgx.Tx) (*types.Receipt, error)
	IsL2BlockConsolidated(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (bool, error)
	IsL2BlockVirtualized(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (bool, error)
	ProcessUnsignedTransaction(ctx context.Context, tx *types.Transaction, senderAddress common.Address, l2BlockNumber *uint64, noZKEVMCounters bool, dbTx pgx.Tx) (*runtime.ExecutionResult, error)
	RegisterNewL2BlockEventHandler(h state.NewL2BlockEventHandler)
	GetLastVirtualBatchNum(ctx context.Context, dbTx pgx.Tx) (uint64, error)
	GetLastVerifiedBatch(ctx context.Context, dbTx pgx.Tx) (*state.VerifiedBatch, error)
	GetLastBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
	GetBatchByNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.Batch, error)
	GetTransactionsByBatchNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (txs []types.Transaction, err error)
	GetVirtualBatch(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.VirtualBatch, error)
	GetVerifiedBatch(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.VerifiedBatch, error)
	GetExitRootByGlobalExitRoot(ctx context.Context, ger common.Hash, dbTx pgx.Tx) (*state.GlobalExitRoot, error)
}

StateInterface gathers the methods required to interact with the state.

type SubscriptionResponse

type SubscriptionResponse struct {
	JSONRPC string                     `json:"jsonrpc"`
	Method  string                     `json:"method"`
	Params  SubscriptionResponseParams `json:"params"`
}

SubscriptionResponse used to push response for filters that have an active web socket connection

func (SubscriptionResponse) Bytes

func (s SubscriptionResponse) Bytes() ([]byte, error)

Bytes return the serialized response

type SubscriptionResponseParams

type SubscriptionResponseParams struct {
	Subscription string          `json:"subscription"`
	Result       json.RawMessage `json:"result"`
}

SubscriptionResponseParams parameters for subscription responses

type Transaction

type Transaction struct {
	Nonce       ArgUint64       `json:"nonce"`
	GasPrice    ArgBig          `json:"gasPrice"`
	Gas         ArgUint64       `json:"gas"`
	To          *common.Address `json:"to"`
	Value       ArgBig          `json:"value"`
	Input       ArgBytes        `json:"input"`
	V           ArgBig          `json:"v"`
	R           ArgBig          `json:"r"`
	S           ArgBig          `json:"s"`
	Hash        common.Hash     `json:"hash"`
	From        common.Address  `json:"from"`
	BlockHash   *common.Hash    `json:"blockHash"`
	BlockNumber *ArgUint64      `json:"blockNumber"`
	TxIndex     *ArgUint64      `json:"transactionIndex"`
	ChainID     ArgBig          `json:"chainId"`
	Type        ArgUint64       `json:"type"`
}

Transaction structure

func NewTransaction

func NewTransaction(
	t types.Transaction,
	blockNumber *big.Int,
	blockHash *common.Hash,
	txIndex *uint64,
) *Transaction

NewTransaction creates a transaction instance

func (Transaction) CoreTx

func (t Transaction) CoreTx() *types.Transaction

CoreTx returns a geth core type Transaction

type TransactionOrHash

type TransactionOrHash struct {
	Hash *common.Hash
	Tx   *Transaction
}

TransactionOrHash for union type of transaction and types.Hash

func (TransactionOrHash) MarshalJSON

func (b TransactionOrHash) MarshalJSON() ([]byte, error)

MarshalJSON marshals into json

func (*TransactionOrHash) UnmarshalJSON

func (b *TransactionOrHash) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from json

type TxArgs

type TxArgs struct {
	From     *common.Address
	To       *common.Address
	Gas      *ArgUint64
	GasPrice *ArgBytes
	Value    *ArgBytes
	Data     *ArgBytes
	Input    *ArgBytes
	Nonce    *ArgUint64
}

TxArgs is the transaction argument for the rpc endpoints

func (*TxArgs) ToTransaction

func (args *TxArgs) ToTransaction(ctx context.Context, st StateInterface, maxCumulativeGasUsed uint64, root common.Hash, defaultSenderAddress common.Address, dbTx pgx.Tx) (common.Address, *types.Transaction, error)

ToTransaction transforms txnArgs into a Transaction

Jump to

Keyboard shortcuts

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