mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add debug_getrawTransactions (#5682)
This commit is contained in:
@ -24,6 +24,10 @@ pub trait DebugApi {
|
||||
#[method(name = "getRawTransaction")]
|
||||
async fn raw_transaction(&self, hash: B256) -> RpcResult<Bytes>;
|
||||
|
||||
/// Returns an array of EIP-2718 binary-encoded transactions for the given [BlockId].
|
||||
#[method(name = "getRawTransactions")]
|
||||
async fn raw_transactions(&self, block_id: BlockId) -> RpcResult<Vec<Bytes>>;
|
||||
|
||||
/// Returns an array of EIP-2718 binary-encoded receipts.
|
||||
#[method(name = "getRawReceipts")]
|
||||
async fn raw_receipts(&self, block_id: BlockId) -> RpcResult<Vec<Bytes>>;
|
||||
|
||||
@ -21,7 +21,7 @@ use reth_primitives::{
|
||||
},
|
||||
Address, Block, BlockId, BlockNumberOrTag, Bytes, TransactionSigned, B256,
|
||||
};
|
||||
use reth_provider::{BlockReaderIdExt, HeaderProvider, StateProviderBox};
|
||||
use reth_provider::{BlockReaderIdExt, HeaderProvider, StateProviderBox, TransactionVariant};
|
||||
use reth_revm::{
|
||||
database::{StateProviderDatabase, SubState},
|
||||
tracing::{
|
||||
@ -895,6 +895,18 @@ where
|
||||
.unwrap_or_default())
|
||||
}
|
||||
|
||||
/// Handler for `debug_getRawTransactions`
|
||||
/// Returns the bytes of the transaction for the given hash.
|
||||
async fn raw_transactions(&self, block_id: BlockId) -> RpcResult<Vec<Bytes>> {
|
||||
let block = self
|
||||
.inner
|
||||
.provider
|
||||
.block_with_senders_by_id(block_id, TransactionVariant::NoHash)
|
||||
.to_rpc_result()?
|
||||
.unwrap_or_default();
|
||||
Ok(block.into_transactions_ecrecovered().map(|tx| tx.envelope_encoded()).collect())
|
||||
}
|
||||
|
||||
/// Handler for `debug_getRawReceipts`
|
||||
async fn raw_receipts(&self, block_id: BlockId) -> RpcResult<Vec<Bytes>> {
|
||||
let receipts =
|
||||
|
||||
@ -187,11 +187,32 @@ pub trait BlockReaderIdExt: BlockReader + BlockIdReader + ReceiptProviderIdExt {
|
||||
self.sealed_header_by_id(BlockNumberOrTag::Finalized.into())
|
||||
}
|
||||
|
||||
/// Returns the block with the matching `BlockId` from the database.
|
||||
/// Returns the block with the matching [BlockId] from the database.
|
||||
///
|
||||
/// Returns `None` if block is not found.
|
||||
fn block_by_id(&self, id: BlockId) -> ProviderResult<Option<Block>>;
|
||||
|
||||
/// Returns the block with senders with matching [BlockId].
|
||||
///
|
||||
/// Returns the block's transactions in the requested variant.
|
||||
///
|
||||
/// Returns `None` if block is not found.
|
||||
fn block_with_senders_by_id(
|
||||
&self,
|
||||
id: BlockId,
|
||||
transaction_kind: TransactionVariant,
|
||||
) -> ProviderResult<Option<BlockWithSenders>> {
|
||||
match id {
|
||||
BlockId::Hash(hash) => {
|
||||
self.block_with_senders(hash.block_hash.into(), transaction_kind)
|
||||
}
|
||||
BlockId::Number(num) => self.convert_block_number(num)?.map_or_else(
|
||||
|| Ok(None),
|
||||
|num| self.block_with_senders(num.into(), transaction_kind),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the header with matching tag from the database
|
||||
///
|
||||
/// Returns `None` if header is not found.
|
||||
|
||||
Reference in New Issue
Block a user