Reorder transaction_by_hash to favour canon search (#2331)

* Reorder transaction_by_hash to favour canon search

* Fix test.
This commit is contained in:
Gav Wood 2016-09-27 12:16:42 +02:00 committed by GitHub
parent 16f3119547
commit 6f772a28e2
2 changed files with 9 additions and 6 deletions

View File

@ -348,11 +348,11 @@ impl BlockChainClient for TestBlockChainClient {
}
fn transaction(&self, _id: TransactionID) -> Option<LocalizedTransaction> {
unimplemented!();
None
}
fn uncle(&self, _id: UncleID) -> Option<Bytes> {
unimplemented!();
None
}
fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt> {

View File

@ -433,11 +433,14 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
try!(self.active());
from_params::<(RpcH256,)>(params)
.and_then(|(hash,)| {
let miner = take_weak!(self.miner);
let hash: H256 = hash.into();
match miner.transaction(&hash) {
Some(pending_tx) => to_value(&Transaction::from(pending_tx)),
None => self.transaction(TransactionID::Hash(hash))
let miner = take_weak!(self.miner);
let client = take_weak!(self.client);
let maybe_tx = client.transaction(TransactionID::Hash(hash)).map(Transaction::from)
.or_else(|| miner.transaction(&hash).map(Transaction::from));
match maybe_tx {
Some(t) => to_value(&t),
None => Ok(Value::Null),
}
})
}