From ed80fba7abbcfa27cf232b05b129b63247b61088 Mon Sep 17 00:00:00 2001 From: bear <2630582710@qq.com> Date: Sat, 27 Mar 2021 02:10:30 +0800 Subject: [PATCH] Correct load transactions by hash (#329) * Correct load transactions by hash * Make rustc happy --- client/rpc/src/eth.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/client/rpc/src/eth.rs b/client/rpc/src/eth.rs index 7279b818b..0d49729c2 100644 --- a/client/rpc/src/eth.rs +++ b/client/rpc/src/eth.rs @@ -355,11 +355,25 @@ impl EthApi where let transaction_metadata = self.backend.mapping().transaction_metadata(&transaction_hash) .map_err(|err| internal_err(format!("fetch aux store failed: {:?}", err)))?; - if transaction_metadata.len() == 1 { - Ok(Some((transaction_metadata[0].ethereum_block_hash, transaction_metadata[0].ethereum_index))) - } else { - Ok(None) - } + if transaction_metadata.len() == 1 { + Ok(Some(( + transaction_metadata[0].ethereum_block_hash, + transaction_metadata[0].ethereum_index, + ))) + } else if transaction_metadata.len() > 1 { + transaction_metadata + .iter() + .find(|meta| self.is_canon(meta.block_hash)) + .map_or( + Ok(Some(( + transaction_metadata[0].ethereum_block_hash, + transaction_metadata[0].ethereum_index, + ))), + |meta| Ok(Some((meta.ethereum_block_hash, meta.ethereum_index))), + ) + } else { + Ok(None) + } } }