Skip to content

Commit

Permalink
rpcdaemon: read_rlp_transaction() on RemoteChainStorage class (#2624)
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 authored Dec 26, 2024
1 parent 7923eb4 commit 0b7b3b9
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions silkworm/db/chain/remote_chain_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,41 @@ Task<bool> RemoteChainStorage::read_rlp_transactions(BlockNum block_num, const e
}
rlp_txs.reserve(block.transactions.size());
for (const auto& transaction : block.transactions) {
rlp::encode(rlp_txs.emplace_back(), transaction);
rlp::encode(rlp_txs.emplace_back(), transaction, /*wrap_eip2718_into_string=*/false);
}
co_return true;
}

Task<bool> RemoteChainStorage::read_rlp_transaction(const evmc::bytes32& /*txn_hash*/, Bytes& /*rlp_tx*/) const {
throw std::logic_error{"RemoteChainStorage::read_rlp_transaction not implemented"};
Task<bool> RemoteChainStorage::read_rlp_transaction(const evmc::bytes32& txn_hash, Bytes& rlp_tx) const {
auto block_num = co_await providers_.block_num_from_txn_hash(txn_hash.bytes);
if (!block_num) {
co_return false;
}

const auto block_hash = co_await providers_.canonical_block_hash_from_number(*block_num);
if (!block_hash) {
co_return false;
}

std::vector<Bytes> rlp_txs;
if (!co_await read_rlp_transactions(*block_num, *block_hash, rlp_txs)) {
co_return false;
}

Block block;
const bool success = co_await providers_.block(*block_num, block_hash->bytes, /*.read_senders=*/false, block);
if (!success) {
co_return false;
}
for (const auto& transaction : block.transactions) {
Bytes rlp;
if (transaction.hash() == txn_hash) {
rlp::encode(rlp, transaction, /*wrap_eip2718_into_string=*/false);
rlp_tx = rlp;
co_return true;
}
}
co_return false;
}

Task<std::optional<intx::uint256>> RemoteChainStorage::read_total_difficulty(const Hash& hash, BlockNum block_num) const {
Expand Down

0 comments on commit 0b7b3b9

Please sign in to comment.