Skip to content

Commit

Permalink
Run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Jun 17, 2024
1 parent 4473f98 commit 7346a10
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions cmd/soroban-rpc/lib/preflight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use soroban_simulation::simulation::{
};
use soroban_simulation::{AutoRestoringSnapshotSource, NetworkConfig, SnapshotSourceWithArchive};
use std::cell::RefCell;
use std::convert::TryFrom;
use std::ffi::{CStr, CString};
use std::panic;
use std::ptr::null_mut;
use std::rc::Rc;
use std::{mem, slice};
use std::convert::TryFrom;

#[repr(C)]
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -168,10 +168,7 @@ impl CPreflightResult {
let mut result = Self {
error: string_to_c(error),
auth: xdr_vec_to_c(invoke_hf_result.auth),
result: option_xdr_to_c(
invoke_hf_result
.invoke_result.ok(),
),
result: option_xdr_to_c(invoke_hf_result.invoke_result.ok()),
min_fee: invoke_hf_result
.transaction_data
.as_ref()
Expand Down Expand Up @@ -321,25 +318,25 @@ fn preflight_footprint_ttl_op_or_maybe_panic(
let network_config =
NetworkConfig::load_from_snapshot(go_storage.as_ref(), c_ledger_info.bucket_list_size)?;
let ledger_info = fill_ledger_info(c_ledger_info, &network_config);
// TODO: It would make for a better UX if the user passed only the neccesary fields for every operation.
// TODO: It would make for a better UX if the user passed only the necessary fields for every operation.
// That would remove a possibility of providing bad operation body, or a possibility of filling wrong footprint
// field.
match op_body {
OperationBody::ExtendFootprintTtl(extend_op) => {
preflight_extend_ttl_op(extend_op, footprint.read_only.as_slice(), go_storage, &network_config, &ledger_info)
preflight_extend_ttl_op(&extend_op, footprint.read_only.as_slice(), &go_storage, &network_config, &ledger_info)
}
OperationBody::RestoreFootprint(_) => {
Ok(preflight_restore_op(footprint.read_write.as_slice(), go_storage, &network_config, &ledger_info))
Ok(preflight_restore_op(footprint.read_write.as_slice(), &go_storage, &network_config, &ledger_info))
}
_ => Err(anyhow!("encountered unsupported operation type: '{:?}', instead of 'ExtendFootprintTtl' or 'RestoreFootprint' operations.",
op_body.discriminant()))
}
}

fn preflight_extend_ttl_op(
extend_op: ExtendFootprintTtlOp,
extend_op: &ExtendFootprintTtlOp,
keys_to_extend: &[LedgerKey],
go_storage: Rc<GoLedgerStorage>,
go_storage: &Rc<GoLedgerStorage>,
network_config: &NetworkConfig,
ledger_info: &LedgerInfo,
) -> Result<CPreflightResult> {
Expand Down Expand Up @@ -374,7 +371,7 @@ fn preflight_extend_ttl_op(

fn preflight_restore_op(
keys_to_restore: &[LedgerKey],
go_storage: Rc<GoLedgerStorage>,
go_storage: &Rc<GoLedgerStorage>,
network_config: &NetworkConfig,
ledger_info: &LedgerInfo,
) -> CPreflightResult {
Expand Down Expand Up @@ -424,7 +421,7 @@ fn catch_preflight_panic(op: Box<dyn Fn() -> Result<CPreflightResult>>) -> *mut
// TODO: We could use something like https://github.com/sonos/ffi-convert-rs
// to replace all the free_* , *_to_c and from_c_* functions by implementations of CDrop,
// CReprOf and AsRust

#[allow(clippy::needless_pass_by_value)]
fn xdr_to_c(v: impl WriteXdr) -> CXDR {
let (xdr, len) = vec_to_c_array(v.to_xdr(DEFAULT_XDR_RW_LIMITS).unwrap());
CXDR { xdr, len }
Expand Down Expand Up @@ -660,11 +657,14 @@ fn extract_error_string<T>(simulation_result: &Result<T>, go_storage: &GoLedgerS
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.
if let Some(e) = go_storage.internal_error.borrow().as_ref()
{ format!("{e:?}") }
else
{ format!("{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 {
format!("{e:?}")
}
}
}
}

0 comments on commit 7346a10

Please sign in to comment.