rpc

package
v0.0.0-...-aac2901 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: GPL-3.0 Imports: 23 Imported by: 13

Documentation

Overview

Package rpc provides access to the RPC client

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAContract = errors.New("not a contract")

Functions

func IsSame

func IsSame(a string, b string) bool

IsSame returns true if the two strings are the same, ignoring case. If not equal, it also tried to interpret the strings as addresses using ENS.

Types

type Connection

type Connection struct {
	Chain                string
	Store                *cache.Store // Cache Store to use for read/write. Write can be disabled by setting Store to read-only mode
	LatestBlockTimestamp base.Timestamp
	EnabledMap           map[walk.CacheType]bool
}

Connection carries additional context to rpc calls

func NewConnection

func NewConnection(chain string, cacheEnabled bool, caches map[walk.CacheType]bool) *Connection

func NewReadOnlyConnection

func NewReadOnlyConnection(chain string) *Connection

func TempConnection

func TempConnection(chain string) *Connection

func (*Connection) GetBalanceAt

func (conn *Connection) GetBalanceAt(addr base.Address, bn base.Blknum) (*base.Wei, error)

GetBalanceAt returns a balance for an address at a block

func (*Connection) GetBalanceAtToken

func (conn *Connection) GetBalanceAtToken(token, holder base.Address, hexBlockNo string) (*base.Wei, error)

GetBalanceAtToken returns token balance for given block. `hexBlockNo` can be "latest" or "" for the latest block or decimal number or hex number with 0x prefix.

func (*Connection) GetBlockBodyByNumber

func (conn *Connection) GetBlockBodyByNumber(bn base.Blknum) (types.Block, error)

GetBlockBodyByNumber fetches the block with transactions from the RPC.

func (*Connection) GetBlockHashByHash

func (conn *Connection) GetBlockHashByHash(hash string) (base.Hash, error)

GetBlockHashByHash returns a block's hash if it's a valid block

func (*Connection) GetBlockHashByNumber

func (conn *Connection) GetBlockHashByNumber(bn base.Blknum) (base.Hash, error)

GetBlockHashByNumber returns a block's hash if it's a valid block

func (*Connection) GetBlockHeaderByNumber

func (conn *Connection) GetBlockHeaderByNumber(bn base.Blknum) (types.LightBlock, error)

GetBlockHeaderByNumber fetches the block with only transactions' hashes from the RPC

func (*Connection) GetBlockNumberByHash

func (conn *Connection) GetBlockNumberByHash(hash string) (base.Blknum, error)

GetBlockNumberByHash returns a block's hash if it's a valid block

func (*Connection) GetBlockTimestamp

func (conn *Connection) GetBlockTimestamp(bn base.Blknum) base.Timestamp

GetBlockTimestamp returns the timestamp associated with a given block

func (*Connection) GetClientIDs

func (conn *Connection) GetClientIDs() (uint64, uint64, error)

GetClientIDs returns both chainId and networkId from the node

func (*Connection) GetClientVersion

func (conn *Connection) GetClientVersion() (version string, err error)

GetClientVersion returns the version of the client

func (*Connection) GetContractCodeAt

func (conn *Connection) GetContractCodeAt(addr base.Address, bn base.Blknum) ([]byte, error)

GetContractCodeAt returns a code (if any) for an address at a block

func (*Connection) GetContractDeployBlock

func (conn *Connection) GetContractDeployBlock(address base.Address) (block base.Blknum, err error)

func (*Connection) GetContractProxyAt

func (conn *Connection) GetContractProxyAt(address base.Address, blockNumber base.Blknum) (base.Address, error)

GetContractProxyAt returns the proxy address for a contract if any

func (*Connection) GetEnsAddress

func (conn *Connection) GetEnsAddress(addrOrEns string) (string, bool)

GetEnsAddress converts a single string, if it contains .eth, into an address. Note, we take chain parameter, but ignore it choosing to look at mainnet ENS only

func (*Connection) GetEnsAddresses

func (conn *Connection) GetEnsAddresses(addrs []string) (out []string, found bool)

GetEnsAddresses converts an array of strings, if they contains .eth, into addresses. Note, we take chain parameter, but ignore it choosing to look at mainnet ENS only

func (*Connection) GetEnsName

func (conn *Connection) GetEnsName(addr string) (string, bool)

GetEnsName converts an address into an ens name if registered, returns the address otherwise.

func (*Connection) GetLatestBlockNumber

func (conn *Connection) GetLatestBlockNumber() base.Blknum

GetLatestBlockNumber returns the block number at the front of the chain (i.e. latest)

func (*Connection) GetLogsByNumber

func (conn *Connection) GetLogsByNumber(bn base.Blknum, ts base.Timestamp) ([]types.Log, error)

GetLogsByNumber returns the logs of a block

func (*Connection) GetLogsCountInBlock

func (conn *Connection) GetLogsCountInBlock(bn base.Blknum, ts base.Timestamp) (uint64, error)

GetLogsCountInBlock returns the number of logs in a block

func (*Connection) GetMetaData

func (conn *Connection) GetMetaData(testmode bool) (*types.MetaData, error)

func (*Connection) GetMinerAndWithdrawals

func (conn *Connection) GetMinerAndWithdrawals(bn base.Blknum) ([]types.Withdrawal, base.Address, error)

GetMinerAndWithdrawals returns the miner and withdrawals for a block

func (*Connection) GetReceipt

func (conn *Connection) GetReceipt(bn base.Blknum, txid base.Txnum, suggested base.Timestamp) (receipt types.Receipt, err error)

GetReceipt retrieves a single receipt by block number and transaction id. If suggested is provided, it will be used for the timestamp of the logs.

func (*Connection) GetReceiptNoTimestamp

func (conn *Connection) GetReceiptNoTimestamp(bn base.Blknum, txid base.Txnum) (receipt types.Receipt, err error)

GetReceiptNoTimestamp fetches receipt from the RPC. If txGasPrice is provided, it will be used for receipts in blocks before London

func (*Connection) GetReceiptsByNumber

func (conn *Connection) GetReceiptsByNumber(bn base.Blknum, ts base.Timestamp) ([]types.Receipt, map[base.Txnum]*types.Receipt, error)

GetReceiptsByNumber returns all receipts in a blocks along with their logs

func (*Connection) GetState

func (conn *Connection) GetState(fieldBits types.StatePart, address base.Address, blockNumber base.Blknum, filters StateFilters) (*types.State, error)

GetState returns account state (search: FromRpc)

func (*Connection) GetTokenState

func (conn *Connection) GetTokenState(tokenAddress base.Address, hexBlockNo string) (token *types.Token, err error)

GetTokenState returns token state for given block. `hexBlockNo` can be "latest" or "" for the latest block or decimal number or hex number with 0x prefix. (search: FromRpc)

func (*Connection) GetTracesByBlockNumber

func (conn *Connection) GetTracesByBlockNumber(bn base.Blknum) ([]types.Trace, error)

GetTracesByBlockNumber returns a slice of traces in the given block

func (*Connection) GetTracesByTransactionHash

func (conn *Connection) GetTracesByTransactionHash(txHash string, transaction *types.Transaction) ([]types.Trace, error)

GetTracesByTransactionHash returns a slice of traces in a given transaction's hash

func (*Connection) GetTracesByTransactionId

func (conn *Connection) GetTracesByTransactionId(bn base.Blknum, txid base.Txnum) ([]types.Trace, error)

GetTracesByTransactionId returns a slice of traces in a given transaction

func (*Connection) GetTracesCountInBlock

func (conn *Connection) GetTracesCountInBlock(bn base.Blknum) (uint64, error)

GetTracesCountInBlock returns the number of traces in a block

func (*Connection) GetTransactionAppByHash

func (conn *Connection) GetTransactionAppByHash(hash string) (types.Appearance, error)

GetTransactionAppByHash returns a transaction's appearance if it's a valid transaction

func (*Connection) GetTransactionByAppearance

func (conn *Connection) GetTransactionByAppearance(app *types.Appearance, fetchTraces bool) (*types.Transaction, error)

func (*Connection) GetTransactionByNumberAndId

func (conn *Connection) GetTransactionByNumberAndId(bn base.Blknum, txid base.Txnum) (*types.Transaction, error)

func (*Connection) GetTransactionCountInBlock

func (conn *Connection) GetTransactionCountInBlock(bn base.Blknum) (uint64, error)

GetTransactionCountInBlock returns the number of transactions in a block

func (*Connection) GetTransactionHashByHash

func (conn *Connection) GetTransactionHashByHash(hash string) (string, error)

GetTransactionHashByHash returns a transaction's hash if it's a valid transaction, an empty string otherwise

func (*Connection) GetTransactionHashByHashAndID

func (conn *Connection) GetTransactionHashByHashAndID(hash string, txId base.Txnum) (string, error)

GetTransactionHashByHashAndID returns a transaction's hash if it's a valid transaction

func (*Connection) GetTransactionHashByNumberAndID

func (conn *Connection) GetTransactionHashByNumberAndID(bn base.Blknum, txId base.Txnum) (base.Hash, error)

GetTransactionHashByNumberAndID returns a transaction's hash if it's a valid transaction

func (*Connection) GetTransactionPrefundByApp

func (conn *Connection) GetTransactionPrefundByApp(theApp *types.Appearance) (tx *types.Transaction, err error)

func (*Connection) GetTransactionRewardByTypeAndApp

func (conn *Connection) GetTransactionRewardByTypeAndApp(rt base.Txnum, theApp *types.Appearance) (*types.Transaction, error)

func (*Connection) GetUncleBodiesByNumber

func (conn *Connection) GetUncleBodiesByNumber(bn base.Blknum) ([]types.Block, error)

GetUncleBodiesByNumber returns the number of uncles in a block. (search: FromRpc)

func (*Connection) GetUnclesCountInBlock

func (conn *Connection) GetUnclesCountInBlock(bn base.Blknum) (uint64, error)

GetUnclesCountInBlock returns the number of uncles in a block. (search: FromRpc)

func (*Connection) GetWithdrawalsByNumber

func (conn *Connection) GetWithdrawalsByNumber(bn base.Blknum) ([]types.Withdrawal, error)

GetWithdrawalsByNumber returns all withdrawals in a block

func (*Connection) IsContractAt

func (conn *Connection) IsContractAt(address base.Address, bn base.Blknum) error

IsContractAt checks if an account is a contract

func (*Connection) IsContractAtLatest

func (conn *Connection) IsContractAtLatest(address base.Address) error

IsContractAtLatest checks if an account is a contract at the latest block

func (*Connection) IsNodeArchive

func (conn *Connection) IsNodeArchive() bool

IsNodeArchive tries to return true if the node is an archive node with the following caveteat: we assume that the node has been initialized with a pre-allocation. This is a reasonable assumption for most chains, but not all. For example, if a chain does not have a pre-allocation, this function will return false, when in fact the node may be an archive node.

func (*Connection) IsNodeTracing

func (conn *Connection) IsNodeTracing() (error, bool)

IsNodeTracing returns true if the node exposes the `block_trace` RPC endpoint. It queries block 1 or a user supplied block (which we presume exists). The function returns false if block_trace returns an error or doesn't exist.

func (*Connection) StoreReadable

func (conn *Connection) StoreReadable() bool

StoreReadable is a shorthand to check if Store is initialized. It will return false for nil pointer to Connection

func (*Connection) StoreWritable

func (conn *Connection) StoreWritable() bool

func (*Connection) TestLog

func (conn *Connection) TestLog(caches map[walk.CacheType]bool)

TestLog prints the enabledMap to the log. Note this routine gets called prior to full initialization, thus it takes the enabledMap

type LogFilter

type LogFilter struct {
	BlockHash base.Hash      `json:"blockHash"`
	Emitters  []base.Address `json:"emitters"`
	FromBlock base.Blknum    `json:"fromBlock"`
	ToBlock   base.Blknum    `json:"toBlock"`
	Topics    []base.Hash    `json:"topics"`
}

func NewLogFilter

func NewLogFilter(emitters []string, topics []string) *LogFilter

func (*LogFilter) PassesFilter

func (filter *LogFilter) PassesFilter(log *types.Log) bool

type StateFilters

type StateFilters struct {
	BalanceCheck func(address base.Address, balance *base.Wei) bool
}

Directories

Path Synopsis
Package query provides access to the RPC server
Package query provides access to the RPC server

Jump to

Keyboard shortcuts

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