From 78817c1c6edd35edd1b101be170cad23e7b2499f Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 5 Sep 2022 09:43:04 +0200 Subject: [PATCH 1/2] Remove unwraps in RPC `pending_runtime_api` --- 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 d5a8e3f2fd..1e96a9c6fb 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); + } + return Ok(api); + } else { + return Err(internal_err(format!( + "Cannot get header for block {:?}", + best + ))); + } } From 3e9f8f75e78be2bd7796376a638a6d36def9b000 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 5 Sep 2022 10:40:29 +0200 Subject: [PATCH 2/2] clippy --- client/rpc/src/eth/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/rpc/src/eth/mod.rs b/client/rpc/src/eth/mod.rs index 1e96a9c6fb..110785f675 100644 --- a/client/rpc/src/eth/mod.rs +++ b/client/rpc/src/eth/mod.rs @@ -490,11 +490,11 @@ where for xt in xts { let _ = api.apply_extrinsic(&best, xt); } - return Ok(api); + Ok(api) } else { - return Err(internal_err(format!( + Err(internal_err(format!( "Cannot get header for block {:?}", best - ))); + ))) } }