From 6fa26343d836360851818385c7ea90e80157e630 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Wed, 7 Oct 2020 17:52:19 +0200 Subject: [PATCH] Pubsub fixes (#156) * Fix bug transaction index * Missing past events flag when no options * Move transaction hash calculation to upper scope --- rpc/src/eth.rs | 2 ++ rpc/src/eth_pubsub.rs | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/rpc/src/eth.rs b/rpc/src/eth.rs index 64fa5306e..a7ab4c314 100644 --- a/rpc/src/eth.rs +++ b/rpc/src/eth.rs @@ -799,6 +799,8 @@ impl EthApiT for EthApi where if log.topics.starts_with(&topics) { add = true; } + } else { + add = true; } if add { ret.push(Log { diff --git a/rpc/src/eth_pubsub.rs b/rpc/src/eth_pubsub.rs index 2eb69fa3c..337b00867 100644 --- a/rpc/src/eth_pubsub.rs +++ b/rpc/src/eth_pubsub.rs @@ -305,8 +305,15 @@ impl SubscriptionResult { )); let mut logs: Vec = vec![]; let mut log_index: u32 = 0; - for receipt in receipts { + for (receipt_index, receipt) in receipts.into_iter().enumerate() { let mut transaction_log_index: u32 = 0; + let transaction_hash: Option = if receipt.logs.len() > 0 { + Some(H256::from_slice( + Keccak256::digest(&rlp::encode( + &block.transactions[receipt_index as usize] + )).as_slice() + )) + } else { None }; for log in receipt.logs { if self.add_log( block_hash.unwrap(), @@ -320,11 +327,7 @@ impl SubscriptionResult { data: Bytes(log.data), block_hash: block_hash, block_number: Some(block.header.number), - transaction_hash: Some(H256::from_slice( - Keccak256::digest(&rlp::encode( - &block.transactions[log_index as usize] - )).as_slice() - )), + transaction_hash: transaction_hash, transaction_index: Some(U256::from(log_index)), log_index: Some(U256::from(log_index)), transaction_log_index: Some(U256::from(