zondapi

package
v0.0.0-...-5d05a64 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoCall

func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, timeout time.Duration, globalGasCap uint64) (*core.ExecutionResult, error)

func DoEstimateGas

func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (hexutil.Uint64, error)

func GetAPIs

func GetAPIs(apiBackend Backend) []rpc.API

func RPCMarshalBlock

func RPCMarshalBlock(block *protos.Block, inclTx bool, fullTx bool, config *params.ChainConfig) (map[string]interface{}, error)

RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain transaction hashes.

func RPCMarshalHeader

func RPCMarshalHeader(head *protos.BlockHeader) map[string]interface{}

RPCMarshalHeader converts the given header to the RPC output .

Types

type AccountResult

type AccountResult struct {
	Address      common.Address  `json:"address"`
	AccountProof []string        `json:"accountProof"`
	Balance      *hexutil.Big    `json:"balance"`
	CodeHash     common.Hash     `json:"codeHash"`
	Nonce        hexutil.Uint64  `json:"nonce"`
	StorageHash  common.Hash     `json:"storageHash"`
	StorageProof []StorageResult `json:"storageProof"`
}

Result structs for GetProof

type AddrLocker

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

func (*AddrLocker) LockAddr

func (l *AddrLocker) LockAddr(address common.Address)

LockAddr locks an account's mutex. This is used to prevent another tx getting the same nonce until the lock is released. The mutex prevents the (an identical nonce) from being read again during the time that the first transaction is being signed.

func (*AddrLocker) UnlockAddr

func (l *AddrLocker) UnlockAddr(address common.Address)

UnlockAddr unlocks the mutex of the given account.

type Backend

type Backend interface {

	//SuggestGasTipCap(ctx context.Context) (*big.Int, error)
	//FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error)
	//ChainDb() ethdb.Database
	//AccountManager() *accounts.Manager
	//ExtRPCEnabled() bool
	RPCGasCap() uint64            // global gas cap for eth_call over rpc: DoS protection
	RPCEVMTimeout() time.Duration // global timeout for eth_call over rpc: DoS protection

	// Blockchain API
	//SetHead(number uint64)
	GetValidators(ctx context.Context) (*metadata.EpochMetaData, error)
	HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*protos.BlockHeader, error)
	HeaderByHash(ctx context.Context, hash common.Hash) (*protos.BlockHeader, error)
	//HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error)
	//CurrentHeader() *types.Header
	//CurrentBlock() *types.Block
	BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*protos.Block, error)
	BlockByHash(ctx context.Context, hash common.Hash) (*protos.Block, error)
	BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*protos.Block, error)
	//StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
	StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *protos.BlockHeader, error)
	//PendingBlockAndReceipts() (*types.Block, types.Receipts)
	GetReceipts(ctx context.Context, hash common.Hash, isProtocolTransaction bool) (types.Receipts, error)
	//GetTd(ctx context.Context, hash common.Hash) *big.Int
	GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *protos.BlockHeader, vmConfig *vm.Config) (*vm.EVM, func() error, error)

	// Transaction pool API
	SendTx(ctx context.Context, signedTx transactions.TransactionInterface) error
	GetTransaction(ctx context.Context, txHash common.Hash) (*protos.Transaction, common.Hash, uint64, uint64, error)
	//GetPoolTransactions() (types.Transactions, error)
	//GetPoolTransaction(txHash common.Hash) *types.Transaction
	GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)

	// Filter API
	//BloomStatus() (uint64, uint64)
	GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error)

	ChainConfig() *params.ChainConfig
}

Backend interface provides the common API services (that are provided by both full and light clients) with access to necessary functions.

type BlockChainAPI

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

BlockChainAPI provides an API to access Ethereum blockchain data.

func NewBlockChainAPI

func NewBlockChainAPI(b Backend) *BlockChainAPI

NewBlockChainAPI creates a new Ethereum blockchain API.

func (*BlockChainAPI) BlockNumber

func (s *BlockChainAPI) BlockNumber() hexutil.Uint64

BlockNumber returns the block number of the chain head.

func (*BlockChainAPI) Call

func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Bytes, error)

Call executes the given transaction on the state for the given block number.

Additionally, the caller can specify a batch of contract for fields overriding.

Note, this function doesn't make and changes in the state/blockchain and is useful to execute and retrieve values.

func (*BlockChainAPI) ChainId

func (s *BlockChainAPI) ChainId() *hexutil.Big

func (*BlockChainAPI) EstimateGas

func (s *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error)

EstimateGas returns an estimate of the amount of gas needed to execute the given transaction against the current pending block.

func (*BlockChainAPI) GetBalance

func (s *BlockChainAPI) GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error)

GetBalance returns the amount of wei for the given address in the state of the given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta block numbers are also allowed.

func (*BlockChainAPI) GetBlockByHash

func (s *BlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, error)

GetBlockByHash returns the requested block. When fullTx is true all transactions in the block are returned in full detail, otherwise only the transaction hash is returned.

func (*BlockChainAPI) GetBlockByNumber

func (s *BlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error)

GetBlockByNumber returns the requested canonical block.

  • When blockNr is -1 the chain head is returned.
  • When blockNr is -2 the pending chain head is returned.
  • When fullTx is true all transactions in the block are returned, otherwise only the transaction hash is returned.

func (*BlockChainAPI) GetCode

func (s *BlockChainAPI) GetCode(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)

GetCode returns the code stored at the given address in the state for the given block number.

func (*BlockChainAPI) GetHeaderByHash

func (s *BlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.Hash) map[string]interface{}

GetHeaderByHash returns the requested header by hash.

func (*BlockChainAPI) GetHeaderByNumber

func (s *BlockChainAPI) GetHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (map[string]interface{}, error)

GetHeaderByNumber returns the requested canonical block header. * When blockNr is -1 the chain head is returned. * When blockNr is -2 the pending chain head is returned.

func (*BlockChainAPI) GetStakeBalance

func (s *BlockChainAPI) GetStakeBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*StakeBalanceResult, error)

GetStakeBalance returns stake balance and pending stake balance

func (*BlockChainAPI) GetStorageAt

func (s *BlockChainAPI) GetStorageAt(ctx context.Context, address common.Address, key string, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)

GetStorageAt returns the storage from the state at the given address, key and block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta block numbers are also allowed.

func (*BlockChainAPI) GetValidators

func (s *BlockChainAPI) GetValidators(ctx context.Context) (*ValidatorsResult, error)

type BlockOverrides

type BlockOverrides struct {
	Number     *hexutil.Big
	Difficulty *hexutil.Big
	Time       *hexutil.Big
	GasLimit   *hexutil.Uint64
	Coinbase   *common.Address
	Random     *common.Hash
	BaseFee    *hexutil.Big
}

BlockOverrides is a set of header fields to override.

func (*BlockOverrides) Apply

func (diff *BlockOverrides) Apply(blockCtx *vm.BlockContext)

Apply overrides the given header fields into the given block context.

type OverrideAccount

type OverrideAccount struct {
	Nonce               *hexutil.Uint64 `json:"nonce"`
	Code                *hexutil.Bytes  `json:"code"`
	Balance             **hexutil.Big   `json:"balance"`
	StakeBalance        **hexutil.Big   `json:"stakeBalance"`
	PendingStakeBalance **hexutil.Big   `json:"pendingStakeBalance"`
	// TODO (cyyber): require OTSBitfield
	OTSBitfield [][8]*hexutil.Bytes          `json:"otsBitfield"`
	State       *map[common.Hash]common.Hash `json:"state"`
	StateDiff   *map[common.Hash]common.Hash `json:"stateDiff"`
}

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 RPCIncomingTransaction

type RPCIncomingTransaction struct {
	Gas       hexutil.Uint64 `json:"gas,omitempty"`
	GasPrice  *hexutil.Big   `json:"gasPrice,omitempty"`
	Data      hexutil.Bytes  `json:"data,omitempty"`
	Nonce     hexutil.Uint64 `json:"nonce"`
	To        hexutil.Bytes  `json:"to,omitempty"`
	Value     *hexutil.Big   `json:"value,omitempty"`
	Type      hexutil.Uint64 `json:"type"`
	ChainID   *hexutil.Big   `json:"chainId,omitempty"`
	PK        hexutil.Bytes  `json:"pk,omitempty"`
	Signature hexutil.Bytes  `json:"signature,omitempty"`
}

func (*RPCIncomingTransaction) ToTransaction

type RPCTransaction

type RPCTransaction struct {
	BlockHash           *common.Hash      `json:"blockHash"`
	BlockNumber         *hexutil.Big      `json:"blockNumber"`
	From                common.Address    `json:"from"`
	Gas                 hexutil.Uint64    `json:"gas,omitempty"`
	GasPrice            *hexutil.Big      `json:"gasPrice,omitempty"`
	GasFeeCap           *hexutil.Big      `json:"maxFeePerGas,omitempty"`
	GasTipCap           *hexutil.Big      `json:"maxPriorityFeePerGas,omitempty"`
	Hash                common.Hash       `json:"hash"`
	Data                hexutil.Bytes     `json:"data,omitempty"`
	Nonce               hexutil.Uint64    `json:"nonce"`
	To                  *common.Address   `json:"to,omitempty"`
	TransactionIndex    *hexutil.Uint64   `json:"transactionIndex"`
	Value               *hexutil.Big      `json:"value,omitempty"`
	BlockProposerReward *hexutil.Big      `json:"blockProposerReward,omitempty"`
	AttestorReward      *hexutil.Big      `json:"attestorReward,omitempty"`
	FeeReward           *hexutil.Big      `json:"feeReward,omitempty"`
	Type                hexutil.Uint64    `json:"type"`
	Accesses            *types.AccessList `json:"accessList,omitempty"`
	ChainID             *hexutil.Big      `json:"chainId,omitempty"`
	Signature           hexutil.Bytes     `json:"signature"`
	PK                  hexutil.Bytes     `json:"pk"`
}

RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction

type SignTransactionResult

type SignTransactionResult struct {
	Raw hexutil.Bytes      `json:"raw"`
	Tx  *types.Transaction `json:"tx"`
}

SignTransactionResult represents a RLP encoded signed transaction.

type SlotValidators

type SlotValidators struct {
	SlotNumber uint64           `json:"slotNumber"`
	Leader     common.Address   `json:"leader"`
	Attestors  []common.Address `json:"attestors"`
}

type StakeBalanceResult

type StakeBalanceResult struct {
	StakeBalance        *hexutil.Big `json:"stakeBalance"`
	PendingStakeBalance *hexutil.Big `json:"pendingStakeBalance"`
}

type StateOverride

type StateOverride map[common.Address]OverrideAccount

StateOverride is the collection of overridden accounts.

func (*StateOverride) Apply

func (diff *StateOverride) Apply(state *state.StateDB) error

Apply overrides the fields of specified accounts into the given state.

type StorageResult

type StorageResult struct {
	Key   string       `json:"key"`
	Value *hexutil.Big `json:"value"`
	Proof []string     `json:"proof"`
}

type TransactionAPI

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

TransactionAPI exposes methods for reading and creating transaction data.

func NewTransactionAPI

func NewTransactionAPI(b Backend, nonceLock *AddrLocker) *TransactionAPI

NewTransactionAPI creates a new RPC service with methods for interacting with transactions.

func (*TransactionAPI) GetBlockTransactionCountByHash

func (s *TransactionAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint

GetBlockTransactionCountByHash returns the number of transactions in the block with the given hash.

func (*TransactionAPI) GetBlockTransactionCountByNumber

func (s *TransactionAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint

GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.

func (*TransactionAPI) GetTransactionByBlockHashAndIndex

func (s *TransactionAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction

GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index.

func (*TransactionAPI) GetTransactionByBlockNumberAndIndex

func (s *TransactionAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction

GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.

func (*TransactionAPI) GetTransactionCount

func (s *TransactionAPI) GetTransactionCount(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Uint64, error)

GetTransactionCount returns the number of transactions the given address has sent for the given block number

func (*TransactionAPI) GetTransactionReceipt

func (s *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error)

GetTransactionReceipt returns the transaction receipt for the given transaction hash.

func (*TransactionAPI) SendRawTransaction

func (s *TransactionAPI) SendRawTransaction(ctx context.Context, rpcTx RPCIncomingTransaction) (common.Hash, error)

SendRawTransaction will add the signed transaction to the transaction pool. The sender is responsible for signing the transaction and using the correct nonce.

type TransactionArgs

type TransactionArgs struct {
	From                 *common.Address `json:"from"`
	To                   *common.Address `json:"to"`
	Gas                  *hexutil.Uint64 `json:"gas"`
	GasPrice             *hexutil.Big    `json:"gasPrice"`
	MaxFeePerGas         *hexutil.Big    `json:"maxFeePerGas"`
	MaxPriorityFeePerGas *hexutil.Big    `json:"maxPriorityFeePerGas"`
	Value                *hexutil.Big    `json:"value"`
	Nonce                *hexutil.Uint64 `json:"nonce"`

	Data *hexutil.Bytes `json:"data"`

	// Introduced by AccessListTxType transaction.
	AccessList *types.AccessList `json:"accessList,omitempty"`
	ChainID    *hexutil.Big      `json:"chainId,omitempty"`
}

TransactionArgs represents the arguments to construct a new transaction or a message call.

func (*TransactionArgs) ToMessage

func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (types.Message, error)

ToMessage converts the transaction arguments to the Message type used by the core evm. This method is used in calls and traces that do not require a real live transaction.

func (*TransactionArgs) ToTransaction

func (args *TransactionArgs) ToTransaction() *types.Transaction

ToTransaction converts the arguments to a transaction. This assumes that setDefaults has been called.

type ValidatorsResult

type ValidatorsResult struct {
	Epoch                  uint64           `json:"epoch"`
	ValidatorsBySlotNumber []SlotValidators `json:"validatorsBySlotNumber"`
}

Jump to

Keyboard shortcuts

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