-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fill transaction hash on ethGetLog of light client. #9938
Changes from 6 commits
49e54b7
f25fefa
564559d
9ce5396
dac8cad
0cbb9a7
3af6385
92c6d05
c386faf
ad26801
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -46,6 +46,7 @@ use ethereum_types::{U256, Address}; | |||||
use hash::H256; | ||||||
use parking_lot::Mutex; | ||||||
use fastmap::H256FastMap; | ||||||
use std::collections::BTreeMap; | ||||||
use transaction::{Action, Transaction as EthTransaction, PendingTransaction, SignedTransaction, LocalizedTransaction}; | ||||||
|
||||||
use v1::helpers::{CallRequest as CallRequestHelper, errors, dispatch}; | ||||||
|
@@ -308,11 +309,11 @@ impl LightFetch { | |||||
Some(OnDemandResponse::Receipts(b)) => b, | ||||||
_ => panic!(WRONG_RESPONSE_AMOUNT_TYPE_PROOF), | ||||||
})) | ||||||
|
||||||
|
||||||
} | ||||||
|
||||||
/// Get transaction logs | ||||||
pub fn logs(&self, filter: EthcoreFilter) -> impl Future<Item = Vec<Log>, Error = Error> + Send { | ||||||
use std::collections::BTreeMap; | ||||||
fn logs_common(&self, filter: EthcoreFilter) -> impl Future<Item = BTreeMap<(u64,usize),Log>, Error = Error> + Send { | ||||||
ordian marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing spaces
Suggested change
|
||||||
use jsonrpc_core::futures::stream::{self, Stream}; | ||||||
|
||||||
const MAX_BLOCK_RANGE: u64 = 1000; | ||||||
|
@@ -321,7 +322,7 @@ impl LightFetch { | |||||
self.headers_range_by_block_id(filter.from_block, filter.to_block, MAX_BLOCK_RANGE) | ||||||
.and_then(move |mut headers| { | ||||||
if headers.is_empty() { | ||||||
return Either::A(future::ok(Vec::new())); | ||||||
return Either::A(future::ok(BTreeMap::new())); | ||||||
} | ||||||
|
||||||
let on_demand = &fetcher.on_demand; | ||||||
|
@@ -343,7 +344,7 @@ impl LightFetch { | |||||
// insert them into a BTreeMap to maintain order by number and block index. | ||||||
stream::futures_unordered(receipts_futures) | ||||||
.fold(BTreeMap::new(), move |mut matches, (num, hash, receipts)| { | ||||||
let mut block_index = 0; | ||||||
let mut block_index: usize = 0; | ||||||
for (transaction_index, receipt) in receipts.into_iter().enumerate() { | ||||||
for (transaction_log_index, log) in receipt.logs.into_iter().enumerate() { | ||||||
if filter.matches(&log) { | ||||||
|
@@ -366,8 +367,7 @@ impl LightFetch { | |||||
} | ||||||
} | ||||||
future::ok::<_,OnDemandError>(matches) | ||||||
}) // and then collect them into a vector. | ||||||
.map(|matches| matches.into_iter().map(|(_, v)| v).collect()) | ||||||
}) | ||||||
.map_err(errors::on_demand_error) | ||||||
}); | ||||||
|
||||||
|
@@ -376,6 +376,52 @@ impl LightFetch { | |||||
None => Either::B(Either::B(future::err(errors::network_disabled()))), | ||||||
} | ||||||
}) | ||||||
|
||||||
} | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra whitespace |
||||||
|
||||||
/// Variant of get transaction logs that does not fetch log transactions hash | ||||||
pub fn logs_light(&self, filter: EthcoreFilter) -> impl Future<Item = Vec<Log>, Error = Error> + Send { | ||||||
self.logs_common(filter) | ||||||
.map(|matches| matches.into_iter().map(|(_, v)| v).collect()) | ||||||
} | ||||||
|
||||||
/// Get transaction logs | ||||||
pub fn logs(&self, filter: EthcoreFilter) -> impl Future<Item = Vec<Log>, Error = Error> + Send { | ||||||
use jsonrpc_core::futures::stream::{self, Stream}; | ||||||
let fetcher_block = self.clone(); | ||||||
self.logs_common(filter) | ||||||
// retrieve transaction hash. | ||||||
.and_then(move |matches| { | ||||||
let mut blocks = BTreeMap::new(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation off |
||||||
let mut result: Vec<Log> = matches.into_iter().map(|(_, v)| { | ||||||
{ | ||||||
let block_hash = v.block_hash.as_ref().expect("Previously initialized with value; qed"); | ||||||
blocks.entry(block_hash.clone()).or_insert_with(|| { | ||||||
fetcher_block.block(BlockId::Hash(block_hash.clone().into())) | ||||||
}); | ||||||
} | ||||||
v | ||||||
}).collect(); | ||||||
// future get blocks (unordered it) | ||||||
stream::futures_unordered(blocks.into_iter().map(|(_,v)|v)).collect().map(move |blocks| { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
let transactions_per_block: BTreeMap<_, _> = blocks.iter() | ||||||
.map(|block| (block.hash(), block.transactions())).collect(); | ||||||
for log in result.iter_mut() { | ||||||
let log_index: U256 = log.transaction_index.expect("Previously initialized with value; qed").into(); | ||||||
if log_index < usize::max_value().into() { | ||||||
let block_hash = log.block_hash.clone().expect("Previously initialized with value; qed").into(); | ||||||
let tx_hash = transactions_per_block.get(&block_hash) | ||||||
.and_then(|txs| txs.get(log_index.as_usize())) | ||||||
.map(|tr| tr.hash().into()); | ||||||
log.transaction_hash = tx_hash; | ||||||
} else { | ||||||
trace!(target: "light_fetch", "A received Receipts indexed other usize length ignored"); | ||||||
ordian marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
} | ||||||
result | ||||||
}) | ||||||
}) | ||||||
} | ||||||
|
||||||
// Get a transaction by hash. also returns the index in the block. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ use v1::types::{ | |
Peers, Transaction, RpcSettings, Histogram, RecoveredAccount, | ||
TransactionStats, LocalTransactionStatus, | ||
BlockNumber, ConsensusCapability, VersionInfo, | ||
OperationsInfo, ChainStatus, | ||
OperationsInfo, ChainStatus, Log, Filter, | ||
AccountInfo, HwAccountInfo, RichHeader, Receipt, | ||
}; | ||
|
||
|
@@ -241,5 +241,11 @@ build_rpc_trait! { | |
/// as well as checks the signature for chain replay protection | ||
#[rpc(name = "parity_verifySignature")] | ||
fn verify_signature(&self, bool, Bytes, H256, H256, U64) -> Result<RecoveredAccount>; | ||
|
||
/// Returns logs matching given filter object. | ||
/// Skip filling transaction hash for faster query. | ||
#[rpc(name = "parity_getLogsLight")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no strong opinions on the naming but Otherwise, I propose |
||
fn logs_light(&self, Filter) -> BoxFuture<Vec<Log>>; | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra whitespace