2023-12-13 13:49:10 +00:00
|
|
|
# Fluffy
|
2024-01-24 15:28:03 +00:00
|
|
|
# Copyright (c) 2021-2024 Status Research & Development GmbH
|
2021-06-18 17:20:48 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2023-01-31 12:38:08 +00:00
|
|
|
{.push raises: [].}
|
2021-06-18 17:20:48 +00:00
|
|
|
|
|
|
|
import
|
2023-10-09 15:49:15 +00:00
|
|
|
std/[times, sequtils, strutils, typetraits],
|
2024-01-24 15:28:03 +00:00
|
|
|
json_rpc/[rpcproxy, rpcserver],
|
2023-12-27 00:48:53 +00:00
|
|
|
web3/[conversions], # sigh, for FixedBytes marshalling
|
2022-02-22 10:52:44 +00:00
|
|
|
eth/[common/eth_types, rlp],
|
2023-10-09 15:49:15 +00:00
|
|
|
beacon_chain/spec/forks,
|
2023-12-08 09:35:50 +00:00
|
|
|
../../nimbus/rpc/[rpc_types, filters],
|
2022-12-02 04:39:12 +00:00
|
|
|
../../nimbus/transaction,
|
2022-12-27 14:57:10 +00:00
|
|
|
# TODO: this is a bit weird but having this import makes beacon_light_client
|
|
|
|
# to fail compilation due throwing undeclared `CatchableError` in
|
|
|
|
# `vendor/nimbus-eth2/beacon_chain/spec/keystore.nim`. This is most probably
|
|
|
|
# caused by `readValue` clashing ?
|
|
|
|
# ../../nimbus/common/chain_config
|
2023-10-09 15:49:15 +00:00
|
|
|
../network/history/[history_network, history_content],
|
2023-10-20 10:06:25 +00:00
|
|
|
../network/beacon/beacon_light_client
|
2021-06-18 17:20:48 +00:00
|
|
|
|
|
|
|
# Subset of Eth JSON-RPC API: https://eth.wiki/json-rpc/API
|
|
|
|
# Supported subset will eventually be found here:
|
|
|
|
# https://github.com/ethereum/stateless-ethereum-specs/blob/master/portal-network.md#json-rpc-api
|
|
|
|
#
|
|
|
|
# In order to already support these calls before every part of the Portal
|
|
|
|
# Network is up, one plan is to get the data directly from an external client
|
|
|
|
# through RPC calls. Practically just playing a proxy to that client.
|
|
|
|
# Can be done by just forwarding the rpc call, or by adding a call here, but
|
|
|
|
# that would introduce a unnecessary serializing/deserializing step.
|
|
|
|
|
2022-05-22 20:44:15 +00:00
|
|
|
# Some similar code as from nimbus `rpc_utils`, but avoiding that import as it
|
|
|
|
# brings in a lot more. Should restructure `rpc_utils` a bit before using that.
|
2023-12-08 09:35:50 +00:00
|
|
|
func toHash*(value: rpc_types.Hash256): eth_types.Hash256 =
|
|
|
|
result.data = value.bytes
|
2022-05-22 20:44:15 +00:00
|
|
|
|
|
|
|
func init*(
|
|
|
|
T: type TransactionObject,
|
2023-12-08 09:35:50 +00:00
|
|
|
tx: eth_types.Transaction, header: eth_types.BlockHeader, txIndex: int):
|
2023-01-31 12:38:08 +00:00
|
|
|
T {.raises: [ValidationError].} =
|
2022-05-22 20:44:15 +00:00
|
|
|
TransactionObject(
|
2023-12-08 09:35:50 +00:00
|
|
|
blockHash: some(w3Hash header.blockHash),
|
|
|
|
blockNumber: some(Quantity(header.blockNumber.truncate(uint64))),
|
|
|
|
`from`: w3Addr tx.getSender(),
|
|
|
|
gas: Quantity(tx.gasLimit),
|
|
|
|
gasPrice: Quantity(tx.gasPrice),
|
|
|
|
hash: w3Hash tx.rlpHash,
|
2022-05-22 20:44:15 +00:00
|
|
|
input: tx.payload,
|
2023-12-08 09:35:50 +00:00
|
|
|
nonce: Quantity(tx.nonce),
|
|
|
|
to: some(w3Addr tx.destination),
|
|
|
|
transactionIndex: some(Quantity(txIndex)),
|
|
|
|
value: tx.value,
|
|
|
|
v: Quantity(tx.V),
|
|
|
|
r: tx.R,
|
|
|
|
s: tx.S,
|
|
|
|
`type`: some(Quantity(tx.txType)),
|
|
|
|
maxFeePerGas: some(Quantity(tx.maxFee)),
|
|
|
|
maxPriorityFeePerGas: some(Quantity(tx.maxPriorityFee)),
|
2022-05-22 20:44:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Note: Similar as `populateBlockObject` from rpc_utils, but lacking the
|
|
|
|
# total difficulty
|
|
|
|
func init*(
|
|
|
|
T: type BlockObject,
|
2023-12-08 09:35:50 +00:00
|
|
|
header: eth_types.BlockHeader, body: BlockBody,
|
2022-02-22 10:52:44 +00:00
|
|
|
fullTx = true, isUncle = false):
|
2023-01-31 12:38:08 +00:00
|
|
|
T {.raises: [ValidationError].} =
|
2022-02-11 13:43:10 +00:00
|
|
|
let blockHash = header.blockHash
|
|
|
|
|
2022-05-22 20:44:15 +00:00
|
|
|
var blockObject = BlockObject(
|
2023-12-08 09:35:50 +00:00
|
|
|
number: Quantity(header.blockNumber.truncate(uint64)),
|
|
|
|
hash: w3Hash blockHash,
|
|
|
|
parentHash: w3Hash header.parentHash,
|
|
|
|
nonce: some(FixedBytes[8](header.nonce)),
|
|
|
|
sha3Uncles: w3Hash header.ommersHash,
|
2022-05-22 20:44:15 +00:00
|
|
|
logsBloom: FixedBytes[256] header.bloom,
|
2023-12-08 09:35:50 +00:00
|
|
|
transactionsRoot: w3Hash header.txRoot,
|
|
|
|
stateRoot: w3Hash header.stateRoot,
|
|
|
|
receiptsRoot: w3Hash header.receiptRoot,
|
|
|
|
miner: w3Addr header.coinbase,
|
|
|
|
difficulty: header.difficulty,
|
|
|
|
extraData: HistoricExtraData header.extraData,
|
2022-05-22 20:44:15 +00:00
|
|
|
# TODO: This is optional according to
|
|
|
|
# https://playground.open-rpc.org/?schemaUrl=https://raw.githubusercontent.com/ethereum/eth1.0-apis/assembled-spec/openrpc.json
|
|
|
|
# So we should probably change `BlockObject`.
|
2023-12-08 09:35:50 +00:00
|
|
|
totalDifficulty: UInt256.low(),
|
|
|
|
gasLimit: Quantity(header.gasLimit.uint64),
|
|
|
|
gasUsed: Quantity(header.gasUsed.uint64),
|
|
|
|
timestamp: Quantity(header.timestamp.uint64)
|
2022-05-22 20:44:15 +00:00
|
|
|
)
|
2022-02-11 13:43:10 +00:00
|
|
|
|
|
|
|
let size = sizeof(BlockHeader) - sizeof(Blob) + header.extraData.len
|
2023-12-08 09:35:50 +00:00
|
|
|
blockObject.size = Quantity(size.uint)
|
2022-02-11 13:43:10 +00:00
|
|
|
|
2022-02-22 10:52:44 +00:00
|
|
|
if not isUncle:
|
2022-05-22 20:44:15 +00:00
|
|
|
blockObject.uncles =
|
2023-12-08 09:35:50 +00:00
|
|
|
body.uncles.map(proc(h: BlockHeader): rpc_types.Hash256 = w3Hash h.blockHash)
|
2022-02-22 10:52:44 +00:00
|
|
|
|
|
|
|
if fullTx:
|
|
|
|
var i = 0
|
|
|
|
for tx in body.transactions:
|
2022-05-22 20:44:15 +00:00
|
|
|
# ValidationError from tx.getSender in TransactionObject.init
|
2023-12-08 09:35:50 +00:00
|
|
|
blockObject.transactions.add txOrHash(TransactionObject.init(tx, header, i))
|
2022-02-22 10:52:44 +00:00
|
|
|
inc i
|
|
|
|
else:
|
|
|
|
for tx in body.transactions:
|
2023-12-08 09:35:50 +00:00
|
|
|
blockObject.transactions.add txOrHash(w3Hash keccakHash(rlp.encode(tx)))
|
2022-05-22 20:44:15 +00:00
|
|
|
|
|
|
|
blockObject
|
2022-02-22 10:52:44 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
proc installEthApiHandlers*(
|
|
|
|
# Currently only HistoryNetwork needed, later we might want a master object
|
|
|
|
# holding all the networks.
|
2023-10-09 15:49:15 +00:00
|
|
|
rpcServerWithProxy: var RpcProxy, historyNetwork: HistoryNetwork,
|
2024-01-25 10:04:09 +00:00
|
|
|
beaconLightClient: Opt[LightClient]) =
|
2021-06-18 17:20:48 +00:00
|
|
|
|
|
|
|
# Supported API
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_blockNumber")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_call")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-09-10 13:05:32 +00:00
|
|
|
# rpcServerWithProxy.registerProxyMethod("eth_chainId")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_estimateGas")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_feeHistory")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getBalance")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
# rpcServerWithProxy.registerProxyMethod("eth_getBlockByHash")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-08-04 06:34:53 +00:00
|
|
|
# rpcServerWithProxy.registerProxyMethod("eth_getBlockByNumber")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-22 10:52:44 +00:00
|
|
|
# rpcServerWithProxy.registerProxyMethod("eth_getBlockTransactionCountByHash")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getBlockTransactionCountByNumber")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getCode")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getRawTransactionByHash")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getRawTransactionByBlockHashAndIndex")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getRawTransactionByBlockNumberAndIndex")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getStorageAt")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getTransactionByBlockHashAndIndex")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getTransactionByBlockNumberAndIndex")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getTransactionByHash")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getTransactionCount")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getTransactionReceipt")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getUncleByBlockHashAndIndex")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getUncleByBlockNumberAndIndex")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getUncleCountByBlockHash")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getUncleCountByBlockNumber")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getProof")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_sendRawTransaction")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
|
|
|
# Optional API
|
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_gasPrice")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getFilterChanges")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_getFilterLogs")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-06-29 15:44:08 +00:00
|
|
|
# rpcServerWithProxy.registerProxyMethod("eth_getLogs")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_newBlockFilter")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_newFilter")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_newPendingTransactionFilter")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_pendingTransactions")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_syncing")
|
2021-06-18 17:20:48 +00:00
|
|
|
|
2021-08-05 06:14:25 +00:00
|
|
|
rpcServerWithProxy.registerProxyMethod("eth_uninstallFilter")
|
2022-02-11 13:43:10 +00:00
|
|
|
|
|
|
|
# Supported API through the Portal Network
|
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
rpcServerWithProxy.rpc("eth_chainId") do() -> Quantity:
|
2022-12-27 14:57:10 +00:00
|
|
|
# The Portal Network can only support MainNet at the moment, so always return
|
|
|
|
# 1
|
2023-12-08 09:35:50 +00:00
|
|
|
return Quantity(uint64(1))
|
2022-09-10 13:05:32 +00:00
|
|
|
|
2022-02-11 13:43:10 +00:00
|
|
|
rpcServerWithProxy.rpc("eth_getBlockByHash") do(
|
2023-12-08 09:35:50 +00:00
|
|
|
data: rpc_types.Hash256, fullTransactions: bool) -> Option[BlockObject]:
|
2022-02-11 13:43:10 +00:00
|
|
|
## Returns information about a block by hash.
|
|
|
|
##
|
|
|
|
## data: Hash of a block.
|
|
|
|
## fullTransactions: If true it returns the full transaction objects, if
|
|
|
|
## false only the hashes of the transactions.
|
|
|
|
##
|
|
|
|
## Returns BlockObject or nil when no block was found.
|
2022-02-22 10:52:44 +00:00
|
|
|
let
|
|
|
|
blockHash = data.toHash()
|
2022-12-09 16:59:36 +00:00
|
|
|
(header, body) = (await historyNetwork.getBlock(blockHash)).valueOr:
|
|
|
|
return none(BlockObject)
|
2022-02-22 10:52:44 +00:00
|
|
|
|
2023-12-13 13:49:10 +00:00
|
|
|
return some(BlockObject.init(header, body, fullTransactions))
|
2022-03-02 14:29:12 +00:00
|
|
|
|
2022-09-10 13:05:32 +00:00
|
|
|
rpcServerWithProxy.rpc("eth_getBlockByNumber") do(
|
2023-12-27 00:48:53 +00:00
|
|
|
quantityTag: BlockTag, fullTransactions: bool) -> Option[BlockObject]:
|
|
|
|
|
|
|
|
if quantityTag.kind == bidAlias:
|
|
|
|
let tag = quantityTag.alias.toLowerAscii
|
|
|
|
case tag
|
|
|
|
of "latest":
|
|
|
|
# TODO:
|
|
|
|
# I assume this would refer to the content in the latest optimistic update
|
|
|
|
# in case the majority treshold is not met. And if it is met it is the
|
|
|
|
# same as the safe version?
|
|
|
|
raise newException(ValueError, "Latest tag not yet implemented")
|
|
|
|
of "earliest":
|
|
|
|
raise newException(ValueError, "Earliest tag not yet implemented")
|
|
|
|
of "safe":
|
|
|
|
if beaconLightClient.isNone():
|
|
|
|
raise newException(ValueError, "Safe tag not yet implemented")
|
|
|
|
|
|
|
|
withForkyStore(beaconLightClient.value().store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.Altair:
|
|
|
|
let
|
|
|
|
blockHash = forkyStore.optimistic_header.execution.block_hash
|
|
|
|
(header, body) = (await historyNetwork.getBlock(blockHash)).valueOr:
|
|
|
|
return none(BlockObject)
|
|
|
|
|
|
|
|
return some(BlockObject.init(header, body, fullTransactions))
|
|
|
|
else:
|
|
|
|
raise newException(
|
|
|
|
ValueError, "Not available before Capella - not synced?")
|
|
|
|
of "finalized":
|
|
|
|
if beaconLightClient.isNone():
|
|
|
|
raise newException(ValueError, "Finalized tag not yet implemented")
|
|
|
|
|
|
|
|
withForkyStore(beaconLightClient.value().store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.Altair:
|
|
|
|
let
|
|
|
|
blockHash = forkyStore.finalized_header.execution.block_hash
|
|
|
|
(header, body) = (await historyNetwork.getBlock(blockHash)).valueOr:
|
|
|
|
return none(BlockObject)
|
|
|
|
|
|
|
|
return some(BlockObject.init(header, body, fullTransactions))
|
|
|
|
else:
|
|
|
|
raise newException(
|
|
|
|
ValueError, "Not available before Capella - not synced?")
|
|
|
|
of "pending":
|
|
|
|
raise newException(ValueError, "Pending tag not yet implemented")
|
|
|
|
else:
|
|
|
|
raise newException(ValueError, "Unsupported block tag " & tag)
|
2023-10-09 15:49:15 +00:00
|
|
|
else:
|
|
|
|
let
|
2023-12-27 00:48:53 +00:00
|
|
|
blockNumber = quantityTag.number.toBlockNumber
|
2023-10-09 15:49:15 +00:00
|
|
|
maybeBlock = (await historyNetwork.getBlock(blockNumber)).valueOr:
|
|
|
|
raise newException(ValueError, error)
|
2022-08-04 06:34:53 +00:00
|
|
|
|
2023-10-09 15:49:15 +00:00
|
|
|
if maybeBlock.isNone():
|
|
|
|
return none(BlockObject)
|
|
|
|
else:
|
|
|
|
let (header, body) = maybeBlock.get()
|
2023-12-13 13:49:10 +00:00
|
|
|
return some(BlockObject.init(header, body, fullTransactions))
|
2022-08-04 06:34:53 +00:00
|
|
|
|
2022-02-22 10:52:44 +00:00
|
|
|
rpcServerWithProxy.rpc("eth_getBlockTransactionCountByHash") do(
|
2023-12-08 09:35:50 +00:00
|
|
|
data: rpc_types.Hash256) -> Quantity:
|
2022-02-22 10:52:44 +00:00
|
|
|
## Returns the number of transactions in a block from a block matching the
|
|
|
|
## given block hash.
|
|
|
|
##
|
|
|
|
## data: hash of a block
|
|
|
|
## Returns integer of the number of transactions in this block.
|
|
|
|
let
|
|
|
|
blockHash = data.toHash()
|
2022-12-09 16:59:36 +00:00
|
|
|
(_, body) = (await historyNetwork.getBlock(blockHash)).valueOr:
|
|
|
|
raise newException(ValueError, "Could not find block with requested hash")
|
2022-02-22 10:52:44 +00:00
|
|
|
|
2022-12-09 16:59:36 +00:00
|
|
|
var txCount: uint = 0
|
|
|
|
for tx in body.transactions:
|
|
|
|
txCount.inc()
|
2022-02-22 10:52:44 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
return Quantity(txCount)
|
2022-02-22 10:52:44 +00:00
|
|
|
|
|
|
|
# Note: can't implement this yet as the fluffy node doesn't know the relation
|
|
|
|
# of tx hash -> block number -> block hash, in order to get the receipt
|
|
|
|
# from from the block with that block hash. The Canonical Indices Network
|
|
|
|
# would need to be implemented to get this information.
|
|
|
|
# rpcServerWithProxy.rpc("eth_getTransactionReceipt") do(
|
|
|
|
# data: EthHashStr) -> Option[ReceiptObject]:
|
2022-06-29 15:44:08 +00:00
|
|
|
|
2022-07-05 12:42:55 +00:00
|
|
|
rpcServerWithProxy.rpc("eth_getLogs") do(
|
|
|
|
filterOptions: FilterOptions) -> seq[FilterLog]:
|
2022-09-10 19:00:27 +00:00
|
|
|
if filterOptions.blockHash.isNone():
|
2022-07-05 12:42:55 +00:00
|
|
|
# Currently only queries by blockhash are supported.
|
|
|
|
# To support range queries the Indicies network is required.
|
|
|
|
raise newException(ValueError,
|
2022-09-10 19:00:27 +00:00
|
|
|
"Unsupported query: Only `blockHash` queries are currently supported")
|
2022-12-09 16:59:36 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
let hash = ethHash filterOptions.blockHash.unsafeGet()
|
2022-12-09 16:59:36 +00:00
|
|
|
|
|
|
|
let header = (await historyNetwork.getVerifiedBlockHeader(hash)).valueOr:
|
|
|
|
raise newException(ValueError,
|
|
|
|
"Could not find header with requested hash")
|
|
|
|
|
|
|
|
if headerBloomFilter(header, filterOptions.address, filterOptions.topics):
|
|
|
|
# TODO: These queries could be done concurrently, investigate if there
|
|
|
|
# are no assumptions about usage of concurrent queries on portal
|
|
|
|
# wire protocol level
|
|
|
|
let
|
|
|
|
body = (await historyNetwork.getBlockBody(hash, header)).valueOr:
|
|
|
|
raise newException(ValueError,
|
|
|
|
"Could not find block body for requested hash")
|
|
|
|
receipts = (await historyNetwork.getReceipts(hash, header)).valueOr:
|
|
|
|
raise newException(ValueError,
|
|
|
|
"Could not find receipts for requested hash")
|
|
|
|
|
|
|
|
logs = deriveLogs(header, body.transactions, receipts)
|
|
|
|
filteredLogs = filterLogs(
|
|
|
|
logs, filterOptions.address, filterOptions.topics)
|
|
|
|
|
|
|
|
return filteredLogs
|
2022-06-29 15:44:08 +00:00
|
|
|
else:
|
2022-12-09 16:59:36 +00:00
|
|
|
# bloomfilter returned false, there are no logs matching the criteria
|
|
|
|
return @[]
|