rpc

package
v0.0.0-...-3f8eaf4 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 28 Imported by: 19

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")
View Source
var ErrTraceBlockMissing = "trace_block is missing"

ErrTraceBlockMissing is returned when the node does not support the trace_block endpoint.

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[string]bool
}

Connection carries additional context to rpc calls

func NewConnection

func NewConnection(chain string, cacheEnabled bool, enabledMap map[string]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 uint64) (*big.Int, error)

GetBalanceAt returns a balance for an address at a block

func (*Connection) GetBalanceAtToken

func (conn *Connection) GetBalanceAtToken(token, holder base.Address, hexBlockNo string) (balance *big.Int, err 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 uint64) (types.SimpleBlock[types.SimpleTransaction], 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 uint64) (base.Hash, error)

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

func (*Connection) GetBlockHeaderByNumber

func (conn *Connection) GetBlockHeaderByNumber(bn uint64) (block types.SimpleBlock[string], err 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 uint64) ([]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) GetFieldsFromParts

func (conn *Connection) GetFieldsFromParts(parts []string, asEther bool) (stateFields StatePart, outputFields []string, none bool)

GetFieldsFromParts converts a string array of part names to a bit mask of parts and returns the corresponding output field names or none if no valid parts are present

func (*Connection) GetLatestBlockNumber

func (conn *Connection) GetLatestBlockNumber() uint64

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

func (*Connection) GetLogsByFilter

func (conn *Connection) GetLogsByFilter(filter types.SimpleLogFilter) ([]types.SimpleLog, error)

GetLogsByFilter returns the logs given a filter

func (*Connection) GetLogsByNumber

func (conn *Connection) GetLogsByNumber(bn base.Blknum, ts base.Timestamp) ([]types.SimpleLog, 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) (*MetaData, error)

func (*Connection) GetMinerAndWithdrawals

func (conn *Connection) GetMinerAndWithdrawals(bn base.Blknum) ([]types.SimpleWithdrawal, 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.SimpleReceipt, 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.SimpleReceipt, 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.SimpleReceipt, map[base.Txnum]*types.SimpleReceipt, error)

GetReceiptsByNumber returns all receipts in a blocks along with their logs

func (*Connection) GetState

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

GetState returns account state

func (*Connection) GetTokenState

func (conn *Connection) GetTokenState(tokenAddress base.Address, hexBlockNo string) (token *types.SimpleToken, 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.

func (*Connection) GetTracesByBlockNumber

func (conn *Connection) GetTracesByBlockNumber(bn uint64) ([]types.SimpleTrace, error)

GetTracesByBlockNumber returns a slice of traces in the given block

func (*Connection) GetTracesByFilter

func (conn *Connection) GetTracesByFilter(filter string) ([]types.SimpleTrace, error)

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

func (*Connection) GetTracesByTransactionHash

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

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

func (*Connection) GetTracesByTransactionId

func (conn *Connection) GetTracesByTransactionId(bn, txid uint64) ([]types.SimpleTrace, error)

GetTracesByTransactionId returns a slice of traces in a given transaction

func (*Connection) GetTracesCountInBlock

func (conn *Connection) GetTracesCountInBlock(bn uint64) (uint64, error)

GetTracesCountInBlock returns the number of traces in a block

func (*Connection) GetTransactionAppByHash

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

func (*Connection) GetTransactionByAppearance

func (conn *Connection) GetTransactionByAppearance(app *types.SimpleAppearance, fetchTraces bool) (tx *types.SimpleTransaction, err error)

func (*Connection) GetTransactionByNumberAndId

func (conn *Connection) GetTransactionByNumberAndId(bn base.Blknum, txid uint64) (tx *types.SimpleTransaction, err error)

func (*Connection) GetTransactionCountInBlock

func (conn *Connection) GetTransactionCountInBlock(bn uint64) (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 uint64) (string, error)

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

func (*Connection) GetTransactionHashByNumberAndID

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

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

func (*Connection) GetTransactionPrefundByApp

func (conn *Connection) GetTransactionPrefundByApp(raw *types.RawAppearance) (tx *types.SimpleTransaction, err error)

func (*Connection) GetTransactionRewardByTypeAndApp

func (conn *Connection) GetTransactionRewardByTypeAndApp(rt base.Txnum, raw *types.RawAppearance) (*types.SimpleTransaction, error)

func (*Connection) GetUncleBodiesByNumber

func (conn *Connection) GetUncleBodiesByNumber(bn uint64) ([]types.SimpleBlock[types.SimpleTransaction], error)

GetUncleBodiesByNumber returns the number of uncles in a block.

func (*Connection) GetUnclesCountInBlock

func (conn *Connection) GetUnclesCountInBlock(bn uint64) (uint64, error)

GetUnclesCountInBlock returns the number of uncles in a block.

func (*Connection) GetUnclesHashesByNumber

func (conn *Connection) GetUnclesHashesByNumber(bn uint64) ([]base.Hash, error)

GetUnclesHashesByNumber returns the uncle hashes in a block.

func (*Connection) GetWithdrawalsByNumber

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

GetWithdrawalsByNumber returns all withdrawals in a block

func (*Connection) IsContractAt

func (conn *Connection) IsContractAt(address base.Address, block *types.SimpleNamedBlock) error

IsContractAt checks if an account is a contract

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() bool

IsNodeTracing returns true if the node exposes the `block_trace` RPC endpoing. It queries block 1 (which we presume exists). The function returns false if block_trace an error.

func (*Connection) SlurpTxCountByAddress

func (conn *Connection) SlurpTxCountByAddress(chain, source, addr, requestType string, paginator *Paginator) (int, error)

func (*Connection) SlurpTxsByAddress

func (conn *Connection) SlurpTxsByAddress(chain, source, addr, requestType string, paginator *Paginator) ([]types.SimpleSlurp, int, error)

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(enabledMap map[string]bool)

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

type MetaData

type MetaData struct {
	Latest    uint64 `json:"client"`
	Finalized uint64 `json:"finalized"`
	Staging   uint64 `json:"staging"`
	Ripe      uint64 `json:"ripe"`
	Unripe    uint64 `json:"unripe"`
	ChainId   uint64 `json:"chainId,omitempty"`
	NetworkId uint64 `json:"networkId,omitempty"`
	Chain     string `json:"chain,omitempty"`
}

func (*MetaData) ChainHeight

func (m *MetaData) ChainHeight() base.Blknum

ChainHeight returns the block after the height of the index.

func (*MetaData) IndexHeight

func (m *MetaData) IndexHeight() base.Blknum

Highest returns the height of the index (i.e., max between the finalized, staging, and ripe indexes).

func (*MetaData) NextIndexHeight

func (m *MetaData) NextIndexHeight() base.Blknum

NextIndexHeight returns the block after the height of the index.

func (*MetaData) StageHeight

func (m *MetaData) StageHeight() base.Blknum

StageHieght returns the highest block that's been staged

func (*MetaData) String

func (m *MetaData) String() string

type Paginator

type Paginator struct {
	Page    int
	PerPage int
}

type StateFilters

type StateFilters struct {
	Balance func(address base.Address, balance *big.Int) bool
}

type StatePart

type StatePart int

StatePart is a bit mask for querying various parts an address's state

const (
	// The balance of the address
	Balance StatePart = 1 << iota
	// The nonce of the address
	Nonce
	// The code of the address if the address is a smart contract
	Code
	// The block number when the smart contract was deployed
	Deployed
	// If an address is proxied, the address of the proxy (note that the proxy may in some cases not be visible and therefore this value will be empty)
	Proxy
	// Either EOA or Contract
	Type
)

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