Documentation
¶
Overview ¶
Package rpctypes provides pretty JSON marshaling functionality for blockchain data types.
The pretty marshaling functions convert hex-encoded values to their native types for better human readability. For example:
- Timestamps: "0x55ba467c" -> 1438271100 (uint64)
- Gas values: "0x5208" -> 21000 (uint64)
- Addresses: "0x1234..." -> common.Address type
- Hashes: "0xabcd..." -> common.Hash type
Usage example:
block := NewPolyBlock(rawBlockResponse)
prettyJSON, err := PolyBlockToPrettyJSON(block)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(prettyJSON))
Index ¶
- Variables
- func ConvHexToBigInt(raw any) (bi *big.Int, err error)
- func ConvHexToUint64(raw any) (uint64, error)
- func MustConvHexToUint64(raw any) uint64
- func PolyBlockToPrettyJSON(block PolyBlock) ([]byte, error)
- func PolyReceiptToPrettyJSON(receipt PolyReceipt) ([]byte, error)
- func PolyTransactionToPrettyJSON(tx PolyTransaction) ([]byte, error)
- type HexBytes
- type PolyBlock
- type PolyReceipt
- type PolyReceipts
- type PolyTransaction
- type PolyTransactions
- type PrettyBlock
- type PrettyMarshaler
- type PrettyReceipt
- type PrettyTransaction
- type PrettyTxLogs
- type RawBlockResponse
- type RawData20Response
- type RawData256Response
- type RawData32Response
- type RawData8Response
- type RawDataResponse
- type RawQuantityResponse
- type RawTransactionResponse
- type RawTxLogs
- type RawTxReceipt
- type SortableBlocks
Constants ¶
This section is empty.
Variables ¶
var RPCSchemaAccountList string
var RPCSchemaBadBlocks string
var RPCSchemaDebugTrace string
var RPCSchemaDebugTraceBlock string
var RPCSchemaEthAccessList string
var RPCSchemaEthBlock string
var RPCSchemaEthFeeHistory string
var RPCSchemaEthFilter string
var RPCSchemaEthProof string
var RPCSchemaEthReceipt string
var RPCSchemaEthSyncing string
var RPCSchemaEthTransaction string
var RPCSchemaHexArray string
var RPCSchemaSignTxResponse string
Functions ¶
func ConvHexToBigInt ¶
ConvHexToBigInt assumes that it's input is a hex encoded string and will try to convert it to a big int
func ConvHexToUint64 ¶
ConvHexToUint64 assumes that its input is a hex encoded string and it will attempt to convert this into a uint64
func MustConvHexToUint64 ¶
func PolyBlockToPrettyJSON ¶ added in v0.1.83
Helper functions to convert poly types to their pretty JSON representations
func PolyReceiptToPrettyJSON ¶ added in v0.1.83
func PolyReceiptToPrettyJSON(receipt PolyReceipt) ([]byte, error)
func PolyTransactionToPrettyJSON ¶ added in v0.1.83
func PolyTransactionToPrettyJSON(tx PolyTransaction) ([]byte, error)
Types ¶
type HexBytes ¶ added in v0.1.83
type HexBytes []byte
HexBytes represents byte data that should be JSON-marshaled as hex strings
func (HexBytes) MarshalJSON ¶ added in v0.1.83
MarshalJSON implements the json.Marshaler interface for HexBytes
func (*HexBytes) UnmarshalJSON ¶ added in v0.1.83
UnmarshalJSON implements the json.Unmarshaler interface for HexBytes
type PolyBlock ¶
type PolyBlock interface {
Number() *big.Int
Time() uint64
Transactions() PolyTransactions
Uncles() []RawData32Response
Size() uint64
GasUsed() uint64
Miner() ethcommon.Address
Hash() ethcommon.Hash
Difficulty() *big.Int
GasLimit() uint64
BaseFee() *big.Int
Extra() []byte
ParentHash() ethcommon.Hash
UncleHash() ethcommon.Hash
Root() ethcommon.Hash
TxRoot() ethcommon.Hash
Nonce() uint64
String() string
MarshalJSON() ([]byte, error)
ReceiptsRoot() ethcommon.Hash
LogsBloom() []byte
Coinbase() ethcommon.Address
MixHash() ethcommon.Hash
}
func NewPolyBlock ¶
func NewPolyBlock(r *RawBlockResponse) PolyBlock
type PolyReceipt ¶
type PolyReceipt interface {
TransactionHash() ethcommon.Hash
TransactionIndex() uint64
BlockHash() ethcommon.Hash
BlockNumber() *big.Int
From() ethcommon.Address
To() ethcommon.Address
CumulativeGasUsed() *big.Int
EffectiveGasPrice() *big.Int
GasUsed() *big.Int
ContractAddress() ethcommon.Address
Logs() []RawTxLogs
LogsBloom() []byte
Root() ethcommon.Hash
Status() uint64
BlobGasPrice() *big.Int
BlobGasUsed() *big.Int
MarshalJSON() ([]byte, error)
}
func NewPolyReceipt ¶
func NewPolyReceipt(r *RawTxReceipt) PolyReceipt
type PolyReceipts ¶
type PolyReceipts []PolyReceipt
type PolyTransaction ¶
type PolyTransaction interface {
GasPrice() *big.Int
Hash() ethcommon.Hash
To() ethcommon.Address
From() ethcommon.Address
Data() []byte
DataStr() string // Raw hex string of transaction data
Value() *big.Int
Gas() uint64
Nonce() uint64
String() string
MarshalJSON() ([]byte, error)
Type() uint64
MaxPriorityFeePerGas() uint64
MaxFeePerGas() uint64
ChainID() uint64
BlockNumber() *big.Int
V() *big.Int
R() *big.Int
S() *big.Int
}
func NewPolyTransaction ¶
func NewPolyTransaction(r *RawTransactionResponse) PolyTransaction
type PolyTransactions ¶
type PolyTransactions []PolyTransaction
type PrettyBlock ¶ added in v0.1.83
type PrettyBlock struct {
Number *big.Int `json:"number"`
Hash ethcommon.Hash `json:"hash"`
ParentHash ethcommon.Hash `json:"parentHash"`
Nonce uint64 `json:"nonce"`
SHA3Uncles ethcommon.Hash `json:"sha3Uncles"`
LogsBloom HexBytes `json:"logsBloom"`
TransactionsRoot ethcommon.Hash `json:"transactionsRoot"`
StateRoot ethcommon.Hash `json:"stateRoot"`
ReceiptsRoot ethcommon.Hash `json:"receiptsRoot"`
Miner ethcommon.Address `json:"miner"`
Difficulty *big.Int `json:"difficulty"`
TotalDifficulty *big.Int `json:"totalDifficulty,omitempty"`
ExtraData HexBytes `json:"extraData"`
Size uint64 `json:"size"`
GasLimit uint64 `json:"gasLimit"`
GasUsed uint64 `json:"gasUsed"`
Timestamp uint64 `json:"timestamp"`
Transactions []PrettyTransaction `json:"transactions"`
Uncles []ethcommon.Hash `json:"uncles"`
BaseFeePerGas *big.Int `json:"baseFeePerGas"`
MixHash ethcommon.Hash `json:"mixHash"`
}
PrettyBlock represents a human-readable block structure
type PrettyMarshaler ¶ added in v0.1.83
Interface extensions for pretty marshaling
type PrettyReceipt ¶ added in v0.1.83
type PrettyReceipt struct {
TransactionHash ethcommon.Hash `json:"transactionHash"`
TransactionIndex uint64 `json:"transactionIndex"`
BlockHash ethcommon.Hash `json:"blockHash"`
BlockNumber *big.Int `json:"blockNumber"`
From ethcommon.Address `json:"from"`
To ethcommon.Address `json:"to"`
CumulativeGasUsed *big.Int `json:"cumulativeGasUsed"`
EffectiveGasPrice *big.Int `json:"effectiveGasPrice"`
GasUsed *big.Int `json:"gasUsed"`
ContractAddress ethcommon.Address `json:"contractAddress"`
Logs []PrettyTxLogs `json:"logs"`
LogsBloom HexBytes `json:"logsBloom"`
Root ethcommon.Hash `json:"root"`
Status uint64 `json:"status"`
BlobGasPrice *big.Int `json:"blobGasPrice"`
BlobGasUsed *big.Int `json:"blobGasUsed"`
}
PrettyReceipt represents a human-readable receipt structure
type PrettyTransaction ¶ added in v0.1.83
type PrettyTransaction struct {
BlockHash ethcommon.Hash `json:"blockHash"`
BlockNumber *big.Int `json:"blockNumber"`
From ethcommon.Address `json:"from"`
Gas uint64 `json:"gas"`
GasPrice *big.Int `json:"gasPrice"`
MaxPriorityFeePerGas uint64 `json:"maxPriorityFeePerGas"`
MaxFeePerGas uint64 `json:"maxFeePerGas"`
Hash ethcommon.Hash `json:"hash"`
Input HexBytes `json:"input"`
Nonce uint64 `json:"nonce"`
To ethcommon.Address `json:"to"`
TransactionIndex uint64 `json:"transactionIndex"`
Value *big.Int `json:"value"`
V *big.Int `json:"v"`
R *big.Int `json:"r"`
S *big.Int `json:"s"`
Type uint64 `json:"type"`
ChainID uint64 `json:"chainId"`
AccessList []any `json:"accessList"`
}
PrettyTransaction represents a human-readable transaction structure
type PrettyTxLogs ¶ added in v0.1.83
type PrettyTxLogs struct {
BlockHash ethcommon.Hash `json:"blockHash"`
BlockNumber uint64 `json:"blockNumber"`
TransactionIndex uint64 `json:"transactionIndex"`
Address ethcommon.Address `json:"address"`
LogIndex uint64 `json:"logIndex"`
Data HexBytes `json:"data"`
Removed bool `json:"removed"`
Topics []ethcommon.Hash `json:"topics"`
TransactionHash ethcommon.Hash `json:"transactionHash"`
}
PrettyTxLogs represents a human-readable log structure
type RawBlockResponse ¶
type RawBlockResponse struct {
// number: QUANTITY - the block number. null when its pending block.
Number RawQuantityResponse `json:"number"`
// hash: DATA, 32 Bytes - hash of the block. null when its pending block.
Hash RawData32Response `json:"hash"`
// parentHash: DATA, 32 Bytes - hash of the parent block.
ParentHash RawData32Response `json:"parentHash"`
// nonce: DATA, 8 Bytes - hash of the generated proof-of-work. null when its pending block.
Nonce RawData8Response `json:"nonce"`
// sha3Uncles: DATA, 32 Bytes - SHA3 of the uncles data in the block.
SHA3Uncles RawData32Response `json:"sha3Uncles"`
// logsBloom: DATA, 256 Bytes - the bloom filter for the logs of the block. null when its pending block.
LogsBloom RawData256Response `json:"logsBloom"`
// transactionsRoot: DATA, 32 Bytes - the root of the transaction trie of the block.
TransactionsRoot RawData32Response `json:"transactionsRoot"`
// stateRoot: DATA, 32 Bytes - the root of the final state trie of the block.
StateRoot RawData32Response `json:"stateRoot"`
// receiptsRoot: DATA, 32 Bytes - the root of the receipts trie of the block.
ReceiptsRoot RawData32Response `json:"receiptsRoot"`
// miner: DATA, 20 Bytes - the address of the beneficiary to whom the mining rewards were given.
Miner RawData20Response `json:"miner"`
// difficulty: QUANTITY - integer of the difficulty for this block.
Difficulty RawQuantityResponse `json:"difficulty"`
// totalDifficulty: QUANTITY - integer of the total difficulty of the chain until this block.
TotalDifficulty RawQuantityResponse `json:"totalDifficulty"`
// extraData: DATA - the "extra data" field of this block.
ExtraData RawDataResponse `json:"extraData"`
// size: QUANTITY - integer the size of this block in bytes.
Size RawQuantityResponse `json:"size"`
// gasLimit: QUANTITY - the maximum gas allowed in this block.
GasLimit RawQuantityResponse `json:"gasLimit"`
// gasUsed: QUANTITY - the total used gas by all transactions in this block.
GasUsed RawQuantityResponse `json:"gasUsed"`
// timestamp: QUANTITY - the unix timestamp for when the block was collated.
Timestamp RawQuantityResponse `json:"timestamp"`
// transactions: Array - Array of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.
Transactions []RawTransactionResponse `json:"transactions"`
// uncles: Array - Array of uncle hashes.
Uncles []RawData32Response `json:"uncles"`
// baseFeePerGas: QUANTITY - fixed per block fee
BaseFeePerGas RawQuantityResponse `json:"baseFeePerGas"`
// receiptsRoot: DATA, 32 Bytes - a 256-bit hash encoded as a hexadecimal
MixHash RawData32Response `json:"mixHash"`
}
func NewRawBlockResponseFromAny ¶
func NewRawBlockResponseFromAny(raw any) (*RawBlockResponse, error)
func (*RawBlockResponse) ToBlock ¶ added in v0.1.97
func (r *RawBlockResponse) ToBlock() *types.Block
ToBlock converts a RawBlockResponse to a types.Block with header only. The block will not contain transactions, uncles, or withdrawals.
type RawData20Response ¶
type RawData20Response string
func (*RawData20Response) ToAddress ¶
func (r *RawData20Response) ToAddress() ethcommon.Address
type RawData256Response ¶
type RawData256Response string
func (*RawData256Response) ToBytes ¶
func (r *RawData256Response) ToBytes() []byte
type RawData32Response ¶
type RawData32Response string
func (*RawData32Response) ToHash ¶
func (r *RawData32Response) ToHash() ethcommon.Hash
type RawData8Response ¶
type RawData8Response string
func (RawData8Response) ToUint64 ¶
func (r RawData8Response) ToUint64() uint64
type RawDataResponse ¶
type RawDataResponse string
func (*RawDataResponse) ToBytes ¶
func (r *RawDataResponse) ToBytes() []byte
type RawQuantityResponse ¶
type RawQuantityResponse string
func (*RawQuantityResponse) String ¶
func (r *RawQuantityResponse) String() string
func (*RawQuantityResponse) ToBigInt ¶
func (r *RawQuantityResponse) ToBigInt() *big.Int
func (RawQuantityResponse) ToFloat64 ¶
func (r RawQuantityResponse) ToFloat64() float64
func (RawQuantityResponse) ToInt64 ¶
func (r RawQuantityResponse) ToInt64() int64
func (RawQuantityResponse) ToUint64 ¶
func (r RawQuantityResponse) ToUint64() uint64
type RawTransactionResponse ¶
type RawTransactionResponse struct {
// blockHash: DATA, 32 Bytes - hash of the block where this transaction was in. null when its pending.
BlockHash RawData32Response `json:"blockHash"`
// blockNumber: QUANTITY - block number where this transaction was in. null when its pending.
BlockNumber RawQuantityResponse `json:"blockNumber"`
// from: DATA, 20 Bytes - address of the sender.
From RawData20Response `json:"from"`
// gas: QUANTITY - gas provided by the sender.
Gas RawQuantityResponse `json:"gas"`
// gasPrice: QUANTITY - gas price provided by the sender in Wei.
GasPrice RawQuantityResponse `json:"gasPrice"`
// gas: QUANTITY - gas provided by the sender.
MaxPriorityFeePerGas RawQuantityResponse `json:"maxPriorityFeePerGas"`
// gas: QUANTITY - gas provided by the sender.
MaxFeePerGas RawQuantityResponse `json:"maxFeePerGas"`
// hash: DATA, 32 Bytes - hash of the transaction.
Hash RawData32Response `json:"hash"`
// input: DATA - the data send along with the transaction.
Input RawDataResponse `json:"input"`
// nonce: QUANTITY - the number of transactions made by the sender prior to this one.
Nonce RawQuantityResponse `json:"nonce"`
// to: DATA, 20 Bytes - address of the receiver. null when its a contract creation transaction.
To RawData20Response `json:"to"`
// transactionIndex: QUANTITY - integer of the transactions index position in the block. null when its pending.
TransactionIndex RawQuantityResponse `json:"transactionIndex"`
// value: QUANTITY - value transferred in Wei.
Value RawQuantityResponse `json:"value"`
// v: QUANTITY - ECDSA recovery id
V RawQuantityResponse `json:"v"`
// r: QUANTITY - ECDSA signature r
R RawQuantityResponse `json:"r"`
// s: QUANTITY - ECDSA signature s
S RawQuantityResponse `json:"s"`
// EIP 2718 Type field?
Type RawQuantityResponse `json:"type"`
ChainID RawQuantityResponse `json:"chainId"`
AccessList []any `json:"accessList"`
}
type RawTxLogs ¶
type RawTxLogs struct {
// blockHash: DATA, 32 Bytes - hash of the block where this transaction was in.
BlockHash RawData32Response `json:"blockHash"`
// blockNumber: QUANTITY - block number where this transaction was in.
BlockNumber RawQuantityResponse `json:"blockNumber"`
// transactionIndex: QUANTITY - integer of the transactions index position in the block.
TransactionIndex RawQuantityResponse `json:"transactionIndex"`
// address: DATA, 20 Bytes - address from which this log originated.
Address RawData20Response `json:"address"`
// logIndex: QUANTITY - integer of the log index position in the block. null when its pending log.
LogIndex RawQuantityResponse `json:"logIndex"`
// data: DATA - contains one or more 32 Bytes non-indexed arguments of the log.
Data RawDataResponse `json:"data"`
// removed: boolean - true when the log was removed, due to a chain reorganization. false if its a valid log.
Removed bool `json:"removed"`
// topics: Array, 32 Bytes - array of zero to four 32 Bytes DATA of indexed log arguments. In solidity: The first topic is the hash of the signature of the event (e.g. Deposit(address,bytes32,uint256)), except you declare the event with the anonymous specifier.
Topics []RawData32Response `json:"topics"`
// transactionHash: DATA, 32 Bytes - hash of the transaction.
TransactionHash RawData32Response `json:"transactionHash"`
}
type RawTxReceipt ¶
type RawTxReceipt struct {
// transactionHash: DATA, 32 Bytes - hash of the transaction.
TransactionHash RawData32Response `json:"transactionHash"`
// transactionIndex: QUANTITY - integer of the transactions index position in the block.
TransactionIndex RawQuantityResponse `json:"transactionIndex"`
// blockHash: DATA, 32 Bytes - hash of the block where this transaction was in.
BlockHash RawData32Response `json:"blockHash"`
// blockNumber: QUANTITY - block number where this transaction was in.
BlockNumber RawQuantityResponse `json:"blockNumber"`
// from: DATA, 20 Bytes - address of the sender.
From RawData20Response `json:"from"`
// to: DATA, 20 Bytes - address of the receiver. null when its a contract creation transaction.
To RawData20Response `json:"to"`
// cumulativeGasUsed : QUANTITY - The total amount of gas used when this transaction was executed in the block.
CumulativeGasUsed RawQuantityResponse `json:"cumulativeGasUsed"`
// effectiveGasPrice : QUANTITY - The total base charge plus tip paid for each unit of gas.
EffectiveGasPrice RawQuantityResponse `json:"effectiveGasPrice"`
// gasUsed : QUANTITY - The amount of gas used by this specific transaction alone.
GasUsed RawQuantityResponse `json:"gasUsed"`
// contractAddress : DATA, 20 Bytes - The contract address created, if the transaction was a contract creation, otherwise null.
ContractAddress RawData20Response `json:"contractAddress"`
// logs: Array - Array of log objects, which this transaction generated.
Logs []RawTxLogs `json:"logs"`
// logsBloom: DATA, 256 Bytes - Bloom filter for light clients to quickly retrieve related logs. It also returns either :
LogsBloom RawData256Response `json:"logsBloom"`
// root : DATA 32 bytes of post-transaction stateroot (pre Byzantium)
Root RawData32Response `json:"root"`
// status: QUANTITY either 1 (success) or 0 (failure)
Status RawQuantityResponse `json:"status"`
// blobGasPrice: QUANTITY - blob gas price provided by the sender in Wei.
BlobGasPrice RawQuantityResponse `json:"blobGasPrice"`
// blobGasUsed: QUANTITY - blob gas used by this specific transaction alone.
BlobGasUsed RawQuantityResponse `json:"blobGasUsed"`
}
type SortableBlocks ¶
type SortableBlocks []PolyBlock
func (SortableBlocks) Len ¶
func (a SortableBlocks) Len() int
func (SortableBlocks) Less ¶
func (a SortableBlocks) Less(i, j int) bool
func (SortableBlocks) Swap ¶
func (a SortableBlocks) Swap(i, j int)