mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: raw_tx_by_hash (#6827)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -102,6 +102,14 @@ pub trait EthApi {
|
||||
#[method(name = "getTransactionByHash")]
|
||||
async fn transaction_by_hash(&self, hash: B256) -> RpcResult<Option<Transaction>>;
|
||||
|
||||
/// Returns information about a raw transaction by block hash and transaction index position.
|
||||
#[method(name = "getRawTransactionByBlockHashAndIndex")]
|
||||
async fn raw_transaction_by_block_hash_and_index(
|
||||
&self,
|
||||
hash: B256,
|
||||
index: Index,
|
||||
) -> RpcResult<Option<Bytes>>;
|
||||
|
||||
/// Returns information about a transaction by block hash and transaction index position.
|
||||
#[method(name = "getTransactionByBlockHashAndIndex")]
|
||||
async fn transaction_by_block_hash_and_index(
|
||||
@ -110,6 +118,15 @@ pub trait EthApi {
|
||||
index: Index,
|
||||
) -> RpcResult<Option<Transaction>>;
|
||||
|
||||
/// Returns information about a raw transaction by block number and transaction index
|
||||
/// position.
|
||||
#[method(name = "getRawTransactionByBlockNumberAndIndex")]
|
||||
async fn raw_transaction_by_block_number_and_index(
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
index: Index,
|
||||
) -> RpcResult<Option<Bytes>>;
|
||||
|
||||
/// Returns information about a transaction by block number and transaction index position.
|
||||
#[method(name = "getTransactionByBlockNumberAndIndex")]
|
||||
async fn transaction_by_block_number_and_index(
|
||||
|
||||
@ -165,6 +165,16 @@ where
|
||||
Ok(EthTransactions::transaction_by_hash(self, hash).await?.map(Into::into))
|
||||
}
|
||||
|
||||
/// Handler for: `eth_getRawTransactionByBlockHashAndIndex`
|
||||
async fn raw_transaction_by_block_hash_and_index(
|
||||
&self,
|
||||
hash: B256,
|
||||
index: Index,
|
||||
) -> Result<Option<Bytes>> {
|
||||
trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getRawTransactionByBlockHashAndIndex");
|
||||
Ok(EthApi::raw_transaction_by_block_and_tx_index(self, hash, index).await?)
|
||||
}
|
||||
|
||||
/// Handler for: `eth_getTransactionByBlockHashAndIndex`
|
||||
async fn transaction_by_block_hash_and_index(
|
||||
&self,
|
||||
@ -175,6 +185,16 @@ where
|
||||
Ok(EthApi::transaction_by_block_and_tx_index(self, hash, index).await?)
|
||||
}
|
||||
|
||||
/// Handler for: `eth_getRawTransactionByBlockNumberAndIndex`
|
||||
async fn raw_transaction_by_block_number_and_index(
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
index: Index,
|
||||
) -> Result<Option<Bytes>> {
|
||||
trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getRawTransactionByBlockNumberAndIndex");
|
||||
Ok(EthApi::raw_transaction_by_block_and_tx_index(self, number, index).await?)
|
||||
}
|
||||
|
||||
/// Handler for: `eth_getTransactionByBlockNumberAndIndex`
|
||||
async fn transaction_by_block_number_and_index(
|
||||
&self,
|
||||
|
||||
@ -1288,6 +1288,20 @@ where
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub(crate) async fn raw_transaction_by_block_and_tx_index(
|
||||
&self,
|
||||
block_id: impl Into<BlockId>,
|
||||
index: Index,
|
||||
) -> EthResult<Option<Bytes>> {
|
||||
if let Some(block) = self.block_with_senders(block_id.into()).await? {
|
||||
if let Some(tx) = block.transactions().nth(index.into()) {
|
||||
return Ok(Some(tx.envelope_encoded()))
|
||||
}
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
/// Represents from where a transaction was fetched.
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
|
||||
Reference in New Issue
Block a user