Skip to content

Add subscription stream function for transaction receipts #19055

@mattsse

Description

@mattsse

Describe the feature

prep for alloy-rs/alloy#2974

we can already implement a function for this, similar to:

/// Returns a stream that yields all new RPC blocks.
pub fn new_headers_stream(&self) -> impl Stream<Item = Header<N::BlockHeader>> {
self.inner.new_headers_stream()
}

we need to leverage the conversion trait for the tx to receipt conversion

RpcConvert: RpcConvert<
Primitives: NodePrimitives<SignedTx = PoolConsensusTx<Eth::Pool>>,
>,

/// Converts a set of primitive receipts to RPC representations. It is guaranteed that all
/// receipts are from the same block.
///
/// Also accepts the corresponding block in case the receipt requires additional metadata.
fn convert_receipts_with_block(
&self,
receipts: Vec<ConvertReceiptInput<'_, Self::Primitives>>,
block: &SealedBlock<BlockTy<Self::Primitives>>,
) -> Result<Vec<RpcReceipt<Self::Network>>, Self::Error>;

basically just like

let inputs = block
.transactions_recovered()
.zip(Arc::unwrap_or_clone(receipts))
.enumerate()
.map(|(idx, (tx, receipt))| {
let meta = TransactionMeta {
tx_hash: *tx.tx_hash(),
index: idx as u64,
block_hash,
block_number,
base_fee,
excess_blob_gas,
timestamp,
};
let cumulative_gas_used = receipt.cumulative_gas_used();
let logs_len = receipt.logs().len();
let input = ConvertReceiptInput {
tx,
gas_used: cumulative_gas_used - gas_used,
next_log_index,
meta,
receipt,
};
gas_used = cumulative_gas_used;
next_log_index += logs_len;
input
})
.collect::<Vec<_>>();
return self
.tx_resp_builder()
.convert_receipts_with_block(inputs, block.sealed_block())
.map(Some)

which we could actually convert to a helper fn in rpconvert first maybe so that this can be reused

maybe @futreall

Additional context

No response

Metadata

Metadata

Assignees

Labels

A-rpcRelated to the RPC implementationC-enhancementNew feature or request

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions