From 7c96d95d906b5b1d617933fcc081a3015cdd9c4b Mon Sep 17 00:00:00 2001 From: tgmichel Date: Tue, 6 Sep 2022 06:04:27 +0200 Subject: [PATCH] Remove unwraps in RPC `pending_runtime_api` (#842) * Remove unwraps in RPC `pending_runtime_api` * clippy --- client/rpc/src/eth/mod.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/client/rpc/src/eth/mod.rs b/client/rpc/src/eth/mod.rs index d5a8e3f2f..110785f67 100644 --- a/client/rpc/src/eth/mod.rs +++ b/client/rpc/src/eth/mod.rs @@ -482,13 +482,19 @@ where .map(|in_pool_tx| in_pool_tx.data().clone()) .collect::::Extrinsic>>(); // Manually initialize the overlay. - let header = client.header(best).unwrap().unwrap(); - let parent_hash = BlockId::Hash(*header.parent_hash()); - api.initialize_block(&parent_hash, &header) - .map_err(|e| internal_err(format!("Runtime api access error: {:?}", e)))?; - // Apply the ready queue to the best block's state. - for xt in xts { - let _ = api.apply_extrinsic(&best, xt); - } - Ok(api) + if let Ok(Some(header)) = client.header(best) { + let parent_hash = BlockId::Hash(*header.parent_hash()); + api.initialize_block(&parent_hash, &header) + .map_err(|e| internal_err(format!("Runtime api access error: {:?}", e)))?; + // Apply the ready queue to the best block's state. + for xt in xts { + let _ = api.apply_extrinsic(&best, xt); + } + Ok(api) + } else { + Err(internal_err(format!( + "Cannot get header for block {:?}", + best + ))) + } }