From 2d549a71ff4400a8fcf1de172d9d78b9a1e1e8f2 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 18 Jun 2024 15:57:36 -0400 Subject: [PATCH] fix: clippy --- cmd/soroban-rpc/lib/preflight/src/lib.rs | 27 +++++++++++------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/cmd/soroban-rpc/lib/preflight/src/lib.rs b/cmd/soroban-rpc/lib/preflight/src/lib.rs index e84bb5cf..79fec314 100644 --- a/cmd/soroban-rpc/lib/preflight/src/lib.rs +++ b/cmd/soroban-rpc/lib/preflight/src/lib.rs @@ -189,14 +189,14 @@ impl CPreflightResult { } fn new_from_transaction_data( - transaction_data: &Option, - restore_preamble: &Option, + transaction_data: Option<&SorobanTransactionData>, + restore_preamble: Option<&RestoreOpSimulationResult>, error: String, ) -> Self { - let min_fee = transaction_data.as_ref().map_or(0, |d| d.resource_fee); + let min_fee = transaction_data.map_or(0, |d| d.resource_fee); let mut result = Self { error: string_to_c(error), - transaction_data: option_xdr_to_c(transaction_data.as_ref()), + transaction_data: option_xdr_to_c(transaction_data), min_fee, ..Default::default() }; @@ -361,10 +361,10 @@ fn preflight_extend_ttl_op( Err(e) => (None, Err(e)), }; - let error_str = extract_error_string(&maybe_restore_result, go_storage.as_ref()); + let error_str = extract_error_string(&maybe_restore_result, go_storage); Ok(CPreflightResult::new_from_transaction_data( - &maybe_transaction_data, - &maybe_restore_result.unwrap_or(None), + maybe_transaction_data.as_ref(), + maybe_restore_result.ok().flatten().as_ref(), error_str, )) } @@ -384,10 +384,8 @@ fn preflight_restore_op( ); let error_str = extract_error_string(&simulation_result, go_storage.as_ref()); CPreflightResult::new_from_transaction_data( - &simulation_result - .map(|r| Some(r.transaction_data)) - .unwrap_or(None), - &None, + simulation_result.ok().map(|r| r.transaction_data).as_ref(), + None, error_str, ) } @@ -655,10 +653,9 @@ impl SnapshotSourceWithArchive for GoLedgerStorage { fn extract_error_string(simulation_result: &Result, go_storage: &GoLedgerStorage) -> String { match simulation_result { Ok(_) => String::new(), - Err(e) => - // Override any simulation result with a storage error (if any). Simulation does not propagate the storage - // errors, but these provide more exact information on the root cause. - { + Err(e) => { + // Override any simulation result with a storage error (if any). Simulation does not propagate the storage + // errors, but these provide more exact information on the root cause. if let Some(e) = go_storage.internal_error.borrow().as_ref() { format!("{e:?}") } else {