Skip to content

Commit

Permalink
Pubsub fixes (#156)
Browse files Browse the repository at this point in the history
* Fix bug transaction index

* Missing past events flag when no options

* Move transaction hash calculation to upper scope
  • Loading branch information
tgmichel authored Oct 7, 2020
1 parent 428e2cd commit 6fa2634
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ impl<B, C, P, CT, BE> EthApiT for EthApi<B, C, P, CT, BE> where
if log.topics.starts_with(&topics) {
add = true;
}
} else {
add = true;
}
if add {
ret.push(Log {
Expand Down
15 changes: 9 additions & 6 deletions rpc/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,15 @@ impl SubscriptionResult {
));
let mut logs: Vec<Log> = 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<H256> = 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(),
Expand All @@ -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(
Expand Down

0 comments on commit 6fa2634

Please sign in to comment.