From 3fb3f1f54ef18fa96bc0cf4796c9118bc6594286 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 27 Sep 2016 12:17:02 +0200 Subject: [PATCH] Reorder transaction_by_hash to favour canon search (#2332) * Reorder transaction_by_hash to favour canon search * Fix build. * Slightly cleaner function. * Fix test. --- ethcore/src/client/test_client.rs | 4 ++-- rpc/src/v1/impls/eth.rs | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index c0d7e35ba..0abc50bfb 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -383,11 +383,11 @@ impl BlockChainClient for TestBlockChainClient { } fn transaction(&self, _id: TransactionID) -> Option { - unimplemented!(); + None // Simple default. } fn uncle(&self, _id: UncleID) -> Option { - unimplemented!(); + None // Simple default. } fn transaction_receipt(&self, id: TransactionID) -> Option { diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 755539ebd..b174e406e 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -424,13 +424,9 @@ impl Eth for EthClient where fn transaction_by_hash(&self, hash: RpcH256) -> Result, Error> { try!(self.active()); - - let miner = take_weak!(self.miner); let hash: H256 = hash.into(); - match miner.transaction(&hash) { - Some(pending_tx) => Ok(Some(pending_tx.into())), - None => self.transaction(TransactionID::Hash(hash)) - } + let miner = take_weak!(self.miner); + Ok(try!(self.transaction(TransactionID::Hash(hash))).or_else(|| miner.transaction(&hash).map(Into::into))) } fn transaction_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> Result, Error> {