From 8952557c392d574db9dd295832c1db3a942fdd41 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 3 May 2023 21:27:59 -0500 Subject: [PATCH] Run cargo clippy --fix (#790) * Run cargo clippy --fix * Remove braces --------- Co-authored-by: Graydon Hoare --- soroban-env-common/src/compare.rs | 4 +- soroban-env-common/src/env_val.rs | 2 +- soroban-env-common/src/meta.rs | 2 +- soroban-env-common/src/num.rs | 10 +- soroban-env-common/src/object.rs | 8 +- soroban-env-common/src/raw_val.rs | 10 +- soroban-env-common/src/status.rs | 8 +- soroban-env-common/src/string.rs | 6 +- soroban-env-common/src/symbol.rs | 4 +- soroban-env-common/src/unimplemented_env.rs | 4 +- soroban-env-host/src/auth.rs | 29 ++-- soroban-env-host/src/budget.rs | 8 +- soroban-env-host/src/host.rs | 138 ++++++++---------- soroban-env-host/src/host/comparison.rs | 10 +- soroban-env-host/src/host/data_helper.rs | 4 +- soroban-env-host/src/host/err_helper.rs | 2 +- soroban-env-host/src/host/error.rs | 4 +- soroban-env-host/src/host/mem_helper.rs | 2 +- soroban-env-host/src/host/metered_clone.rs | 2 +- soroban-env-host/src/host/metered_map.rs | 2 +- soroban-env-host/src/host/metered_vector.rs | 8 +- soroban-env-host/src/host/metered_xdr.rs | 4 +- soroban-env-host/src/host_object.rs | 2 +- .../src/native_contract/account_contract.rs | 2 +- .../src/native_contract/base_types.rs | 34 ++--- .../src/native_contract/token/admin.rs | 2 +- .../src/native_contract/token/asset_info.rs | 2 +- .../src/native_contract/token/balance.rs | 34 ++--- .../src/native_contract/token/contract.rs | 40 ++--- .../src/native_contract/token/event.rs | 16 +- soroban-env-host/src/storage.rs | 13 +- soroban-test-wasms/src/lib.rs | 29 ++-- 32 files changed, 207 insertions(+), 238 deletions(-) diff --git a/soroban-env-common/src/compare.rs b/soroban-env-common/src/compare.rs index fc37aa9df..8e2921142 100644 --- a/soroban-env-common/src/compare.rs +++ b/soroban-env-common/src/compare.rs @@ -97,7 +97,7 @@ impl> Compare> for C { type Error = C::Error; fn compare(&self, a: &Box, b: &Box) -> Result { - >::compare(self, &*a, &*b) + >::compare(self, a, b) } } @@ -106,7 +106,7 @@ impl> Compare> for C { type Error = C::Error; fn compare(&self, a: &Rc, b: &Rc) -> Result { - >::compare(self, &*a, &*b) + >::compare(self, a, b) } } diff --git a/soroban-env-common/src/env_val.rs b/soroban-env-common/src/env_val.rs index 113176bf9..251b4b9da 100644 --- a/soroban-env-common/src/env_val.rs +++ b/soroban-env-common/src/env_val.rs @@ -415,7 +415,7 @@ where } ScVal::I256(i) => { assert!(num::is_small_i256_parts(i)); - unsafe { RawVal::from_body_and_tag(i.lo_lo as u64, Tag::I256Small) } + unsafe { RawVal::from_body_and_tag(i.lo_lo, Tag::I256Small) } } ScVal::Symbol(bytes) => { let ss = match std::str::from_utf8(bytes.as_slice()) { diff --git a/soroban-env-common/src/meta.rs b/soroban-env-common/src/meta.rs index 5db0ba54a..c6427e761 100644 --- a/soroban-env-common/src/meta.rs +++ b/soroban-env-common/src/meta.rs @@ -38,7 +38,7 @@ // nonzero pre-release number can be used to force recompiles on interface // changes. -pub const ENV_META_V0_SECTION_NAME: &'static str = "contractenvmetav0"; +pub const ENV_META_V0_SECTION_NAME: &str = "contractenvmetav0"; soroban_env_macros::generate_env_meta_consts!( ledger_protocol_version: 20, diff --git a/soroban-env-common/src/num.rs b/soroban-env-common/src/num.rs index f159f4fe3..9895c4ad8 100644 --- a/soroban-env-common/src/num.rs +++ b/soroban-env-common/src/num.rs @@ -94,7 +94,7 @@ impl From for u64 { impl From for i64 { fn from(value: I64Small) -> Self { - value.0.get_signed_body() as i64 + value.0.get_signed_body() } } @@ -118,7 +118,7 @@ impl From for u128 { impl From for i128 { fn from(value: I128Small) -> Self { - (value.0.get_signed_body() as i64) as i128 + value.0.get_signed_body() as i128 } } @@ -130,7 +130,7 @@ impl From for U256 { impl From for I256 { fn from(value: I256Small) -> Self { - I256::from(value.0.get_signed_body() as i64) + I256::from(value.0.get_signed_body()) } } @@ -229,7 +229,7 @@ impl TryFrom for ScVal { impl TryFrom<&U256Small> for ScVal { type Error = ConversionError; fn try_from(value: &U256Small) -> Result { - value.clone().try_into() + (*value).try_into() } } @@ -250,7 +250,7 @@ impl TryFrom for ScVal { impl TryFrom<&I256Small> for ScVal { type Error = ConversionError; fn try_from(value: &I256Small) -> Result { - value.clone().try_into() + (*value).try_into() } } diff --git a/soroban-env-common/src/object.rs b/soroban-env-common/src/object.rs index 361041824..39b3711ba 100644 --- a/soroban-env-common/src/object.rs +++ b/soroban-env-common/src/object.rs @@ -87,7 +87,7 @@ impl ScValObject { /// Inspect the provided `value` and return `Ok(ScValObject(value))` if it /// is a value that should be represented as an object, else `Err(value)`. pub fn classify(value: ScVal) -> Result { - if let Some(_) = ScValObjRef::classify(&value) { + if ScValObjRef::classify(&value).is_some() { Ok(ScValObject(value)) } else { Err(value) @@ -110,9 +110,9 @@ impl AsRef for ScValObject { #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct ScValObjRef<'a>(&'a ScVal); -impl<'a> Into<&'a ScVal> for ScValObjRef<'a> { - fn into(self) -> &'a ScVal { - self.0 +impl<'a> From> for &'a ScVal { + fn from(val: ScValObjRef<'a>) -> Self { + val.0 } } diff --git a/soroban-env-common/src/raw_val.rs b/soroban-env-common/src/raw_val.rs index d299d4767..e10f80916 100644 --- a/soroban-env-common/src/raw_val.rs +++ b/soroban-env-common/src/raw_val.rs @@ -440,7 +440,7 @@ impl RawValConvertible for u32 { } #[inline(always)] unsafe fn unchecked_from_val(v: RawVal) -> Self { - v.get_major() as u32 + v.get_major() } } @@ -681,8 +681,8 @@ impl Debug for RawVal { } match self.get_tag() { - Tag::U32Val => write!(f, "U32({})", self.get_major() as u32), - Tag::I32Val => write!(f, "I32({})", (self.get_major() as u32) as i32), + Tag::U32Val => write!(f, "U32({})", self.get_major()), + Tag::I32Val => write!(f, "I32({})", self.get_major() as i32), Tag::False => write!(f, "False"), Tag::True => write!(f, "True"), Tag::Void => write!(f, "Void"), @@ -695,10 +695,10 @@ impl Debug for RawVal { Tag::DurationSmall => write!(f, "Duration({})", self.get_body()), // These can't be bigger than u64/i64 so just cast to them. Tag::U128Small => write!(f, "U128({})", self.get_body()), - Tag::I128Small => write!(f, "I128({})", self.get_signed_body() as i64), + Tag::I128Small => write!(f, "I128({})", { self.get_signed_body() }), // These can't be bigger than u64/i64 so just cast to them. Tag::U256Small => write!(f, "U256({})", self.get_body()), - Tag::I256Small => write!(f, "I256({})", self.get_signed_body() as i64), + Tag::I256Small => write!(f, "I256({})", { self.get_signed_body() }), Tag::SymbolSmall => { let ss: SymbolStr = unsafe { ::unchecked_from_val(*self) }.into(); diff --git a/soroban-env-common/src/status.rs b/soroban-env-common/src/status.rs index 7cc041f1c..dd59d4263 100644 --- a/soroban-env-common/src/status.rs +++ b/soroban-env-common/src/status.rs @@ -70,7 +70,7 @@ impl Ord for Status { impl Compare for E { type Error = E::Error; fn compare(&self, a: &Status, b: &Status) -> Result { - Ok(a.cmp(&b)) + Ok(a.cmp(b)) } } @@ -316,7 +316,7 @@ impl Status { ScStatus::HostAuthError(code) => code as i32 as u32, ScStatus::VmError(code) => code as i32 as u32, ScStatus::UnknownError(code) => code as i32 as u32, - ScStatus::ContractError(code) => code as u32, + ScStatus::ContractError(code) => code, }; Self::from_type_and_code(sc.discriminant(), code) } @@ -366,7 +366,7 @@ mod tests { ]; let pairs: Vec<_> = xdr_vals - .into_iter() + .iter() .map(|xdr_val| { let host_val = Status::try_from(xdr_val.clone()).unwrap(); (xdr_val, host_val) @@ -376,7 +376,7 @@ mod tests { let mut pairs_xdr_sorted = pairs.clone(); let mut pairs_host_sorted = pairs_xdr_sorted.clone(); - pairs_xdr_sorted.sort_by(|&(v1, _), &(v2, _)| v1.cmp(&v2)); + pairs_xdr_sorted.sort_by(|&(v1, _), &(v2, _)| v1.cmp(v2)); pairs_host_sorted.sort_by(|&(_, v1), &(_, v2)| v1.cmp(&v2)); diff --git a/soroban-env-common/src/string.rs b/soroban-env-common/src/string.rs index e09ed9755..82c8ae99c 100644 --- a/soroban-env-common/src/string.rs +++ b/soroban-env-common/src/string.rs @@ -12,7 +12,7 @@ impl TryFromVal for String { fn try_from_val(env: &E, v: &StringObject) -> Result { let len: u32 = env.string_len(*v).map_err(|_| ConversionError)?.into(); let len = len as usize; - let mut vec = std::vec![0; len as usize]; + let mut vec = std::vec![0; len]; env.string_copy_to_slice(*v, RawVal::U32_ZERO, &mut vec) .map_err(|_| ConversionError)?; String::from_utf8(vec).map_err(|_| ConversionError) @@ -34,9 +34,7 @@ impl TryFromVal for StringObject { type Error = ConversionError; #[inline(always)] fn try_from_val(env: &E, val: &&str) -> Result { - Ok(env - .string_new_from_slice(*val) - .map_err(|_| ConversionError)?) + env.string_new_from_slice(val).map_err(|_| ConversionError) } } diff --git a/soroban-env-common/src/symbol.rs b/soroban-env-common/src/symbol.rs index c2fa57753..e7142777f 100644 --- a/soroban-env-common/src/symbol.rs +++ b/soroban-env-common/src/symbol.rs @@ -69,7 +69,7 @@ impl TryFromVal for Symbol { fn try_from_val(env: &E, v: &&[u8]) -> Result { // We don't know this byte-slice is actually utf-8 ... - let s: &str = unsafe { core::str::from_utf8_unchecked(*v) }; + let s: &str = unsafe { core::str::from_utf8_unchecked(v) }; // ... but this next conversion step will check that its // _bytes_ are in the symbol-char range, which is a subset // of utf-8, so we're only lying harmlessly. @@ -455,7 +455,7 @@ impl TryFrom for ScVal { impl TryFrom<&SymbolSmall> for ScVal { type Error = ConversionError; fn try_from(s: &SymbolSmall) -> Result { - s.clone().try_into() + (*s).try_into() } } diff --git a/soroban-env-common/src/unimplemented_env.rs b/soroban-env-common/src/unimplemented_env.rs index 41f2e9d80..4e25ea144 100644 --- a/soroban-env-common/src/unimplemented_env.rs +++ b/soroban-env-common/src/unimplemented_env.rs @@ -69,11 +69,11 @@ impl EnvBase for UnimplementedEnv { unimplemented!() } - fn string_new_from_slice<'a>(&self, _s: &'a str) -> Result { + fn string_new_from_slice(&self, _s: &str) -> Result { unimplemented!() } - fn symbol_new_from_slice<'a>(&self, _s: &'a str) -> Result { + fn symbol_new_from_slice(&self, _s: &str) -> Result { unimplemented!() } diff --git a/soroban-env-host/src/auth.rs b/soroban-env-host/src/auth.rs index ba66685e3..480635419 100644 --- a/soroban-env-host/src/auth.rs +++ b/soroban-env-host/src/auth.rs @@ -141,7 +141,7 @@ impl AuthorizedInvocation { let sub_invocations_xdr = xdr_invocation.sub_invocations.into_vec(); let sub_invocations = sub_invocations_xdr .into_iter() - .map(|i| AuthorizedInvocation::from_xdr(i)) + .map(AuthorizedInvocation::from_xdr) .collect::, _>>()?; Ok(Self { contract_id: xdr_invocation.contract_id, @@ -433,7 +433,7 @@ impl AuthorizationManager { // We could also make this included into the authorized stack to // generalize all the host function invocations. Frame::HostFunction(_) => return Ok(()), - Frame::Token(id, fn_name, _) => (id.metered_clone(&self.budget)?, fn_name.clone()), + Frame::Token(id, fn_name, _) => (id.metered_clone(&self.budget)?, *fn_name), #[cfg(any(test, feature = "testutils"))] Frame::TestContract(tc) => (tc.id.clone(), tc.func.clone()), }; @@ -472,7 +472,7 @@ impl AuthorizationManager { // Should only be called in the recording mode. pub(crate) fn get_recorded_auth_payloads(&self) -> Result, HostError> { match &self.mode { - AuthorizationMode::Enforcing => return Err(ScUnknownErrorCode::General.into()), + AuthorizationMode::Enforcing => Err(ScUnknownErrorCode::General.into()), AuthorizationMode::Recording(_) => Ok(self .trackers .iter() @@ -636,7 +636,7 @@ impl AuthorizationTracker { false }; let nonce = if !is_invoker { - Some(host.read_and_consume_nonce(&contract_id, &address)?) + Some(host.read_and_consume_nonce(contract_id, &address)?) } else { None }; @@ -829,15 +829,13 @@ impl AuthorizationTracker { break; } } - } else { - if !self.root_authorized_invocation.is_exhausted - && &self.root_authorized_invocation.contract_id == contract_id - && &self.root_authorized_invocation.function_name == function_name - && &self.root_authorized_invocation.args == args - { - frame_index = Some(0); - self.root_authorized_invocation.is_exhausted = true; - } + } else if !self.root_authorized_invocation.is_exhausted + && &self.root_authorized_invocation.contract_id == contract_id + && &self.root_authorized_invocation.function_name == function_name + && &self.root_authorized_invocation.args == args + { + frame_index = Some(0); + self.root_authorized_invocation.is_exhausted = true; } if frame_index.is_some() { *self.invocation_id_in_call_stack.last_mut().unwrap() = frame_index; @@ -875,7 +873,6 @@ impl AuthorizationTracker { invocation: self.invocation_to_xdr(host.budget_ref())?, nonce: self .nonce - .clone() .ok_or_else(|| host.err_general("unexpected missing nonce"))?, }); @@ -892,7 +889,7 @@ impl AuthorizationTracker { let payload = self.get_signature_payload(host)?; match address { ScAddress::Account(acc) => { - check_account_authentication(host, &acc, &payload, &self.signature_args)?; + check_account_authentication(host, acc, &payload, &self.signature_args)?; } ScAddress::Contract(acc_contract) => { check_account_contract_auth( @@ -984,7 +981,7 @@ impl Host { self.with_mut_storage(|storage| storage.get(&nonce_key, self.budget_ref()))?; match &entry.data { LedgerEntryData::ContractData(ContractDataEntry { val, .. }) => match val { - ScVal::U64(val) => val.clone(), + ScVal::U64(val) => *val, _ => { return Err(self.err_general("unexpected nonce entry type")); } diff --git a/soroban-env-host/src/budget.rs b/soroban-env-host/src/budget.rs index 0cbe225b4..dbb3c482a 100644 --- a/soroban-env-host/src/budget.rs +++ b/soroban-env-host/src/budget.rs @@ -429,14 +429,18 @@ impl Budget { *t_iters = t_iters.saturating_add(iterations); match (t_inputs, input) { (None, None) => Ok(()), - (Some(t), Some(i)) => Ok(*t = t.saturating_add(i.saturating_mul(iterations))), + (Some(t), Some(i)) => { + *t = t.saturating_add(i.saturating_mul(iterations)); + Ok(()) + } // TODO: improve error code "unexpected cost model input" _ => Err(ScUnknownErrorCode::General.into()), } })?; self.get_tracker_mut(ContractCostType::ChargeBudget, |(t_iters, _)| { // we already know `ChargeBudget` has undefined input, so here we just add 1 iteration. - Ok(*t_iters = t_iters.saturating_add(1)) + *t_iters = t_iters.saturating_add(1); + Ok(()) })?; // do the actual budget charging diff --git a/soroban-env-host/src/host.rs b/soroban-env-host/src/host.rs index 6e797db3f..18bb64006 100644 --- a/soroban-env-host/src/host.rs +++ b/soroban-env-host/src/host.rs @@ -152,18 +152,13 @@ pub struct LedgerInfo { pub base_reserve: u32, } -#[derive(Clone)] +#[derive(Clone, Default)] pub enum DiagnosticLevel { + #[default] None, Debug, } -impl Default for DiagnosticLevel { - fn default() -> Self { - DiagnosticLevel::None - } -} - #[derive(Clone, Default)] pub(crate) struct HostImpl { source_account: RefCell>, @@ -311,7 +306,10 @@ impl Host { { match self.0.ledger.borrow_mut().as_mut() { None => Err(self.err_general("missing ledger info")), - Some(li) => Ok(f(li)), + Some(li) => { + f(li); + Ok(()) + } } } @@ -349,7 +347,7 @@ impl Host { where F: FnOnce(&mut InternalEventsBuffer) -> Result, { - f(&mut *self.0.events.borrow_mut()) + f(&mut self.0.events.borrow_mut()) } /// Records a debug event. This in itself is not necessarily an error; it @@ -399,7 +397,7 @@ impl Host { where F: FnOnce(&mut Storage) -> Result, { - f(&mut *self.0.storage.borrow_mut()) + f(&mut self.0.storage.borrow_mut()) } /// Accept a _unique_ (refcount = 1) host reference and destroy the @@ -683,7 +681,7 @@ impl Host { } pub fn get_events(&self) -> Result { - self.0.events.borrow().externalize(&self) + self.0.events.borrow().externalize(self) } pub(crate) fn from_host_val(&self, val: RawVal) -> Result { @@ -796,7 +794,7 @@ impl Host { } } - pub(crate) fn to_host_obj<'a>(&self, ob: &ScValObjRef<'a>) -> Result { + pub(crate) fn to_host_obj(&self, ob: &ScValObjRef<'_>) -> Result { // `ValXdrConv` is const cost in both cpu and mem. The input=0 will be ignored. self.charge_budget(ContractCostType::ValXdrConv, None)?; let val: &ScVal = (*ob).into(); @@ -984,13 +982,12 @@ impl Host { } #[cfg(not(feature = "vm"))] ScContractExecutable::WasmRef(_) => Err(self.err_general("could not dispatch")), - ScContractExecutable::Token => self.with_frame( - Frame::Token(id.clone(), func.clone(), args.to_vec()), - || { + ScContractExecutable::Token => { + self.with_frame(Frame::Token(id.clone(), *func, args.to_vec()), || { use crate::native_contract::{NativeContract, Token}; Token.call(func, self, args) - }, - ), + }) + } } } @@ -1016,17 +1013,16 @@ impl Host { ) -> Result { // Internal host calls may call some special functions that otherwise // aren't allowed to be called. - if !internal_host_call { - if SymbolStr::try_from_val(self, &func)? + if !internal_host_call + && SymbolStr::try_from_val(self, &func)? .to_string() .as_str() .starts_with(RESERVED_CONTRACT_FN_PREFIX) - { - return Err(self.err_status_msg( - ScHostContextErrorCode::UnknownError, - "can't invoke a reserved function directly", - )); - } + { + return Err(self.err_status_msg( + ScHostContextErrorCode::UnknownError, + "can't invoke a reserved function directly", + )); } if !matches!(reentry_mode, ContractReentryMode::Allowed) { let mut is_last_non_host_frame = true; @@ -1056,7 +1052,7 @@ impl Host { } } - self.fn_call_diagnostics(&id, &func, args)?; + self.fn_call_diagnostics(id, &func, args)?; // "testutils" is not covered by budget metering. #[cfg(any(test, feature = "testutils"))] @@ -1140,14 +1136,14 @@ impl Host { } } - let res = self.call_contract_fn(&id, &func, args); + let res = self.call_contract_fn(id, &func, args); match &res { - Ok(res) => self.fn_return_diagnostics(id, &func, &res)?, + Ok(res) => self.fn_return_diagnostics(id, &func, res)?, Err(err) => {} } - return res; + res } // Notes on metering: covered by the called components. @@ -1177,11 +1173,11 @@ impl Host { } HostFunctionArgs::CreateContract(args) => self .with_frame(Frame::HostFunction(hf_type), || { - self.create_contract(args).map(|obj| ::from(obj)) + self.create_contract(args).map(::from) }), HostFunctionArgs::UploadContractWasm(args) => self .with_frame(Frame::HostFunction(hf_type), || { - self.install_contract(args).map(|obj| ::from(obj)) + self.install_contract(args).map(::from) }), } } @@ -1290,7 +1286,7 @@ impl Host { ContractId::SourceAccount(salt) => self.id_preimage_from_source_account(salt)?, ContractId::Ed25519PublicKey(key_with_signature) => { let signature_payload_preimage = self.create_contract_args_hash_preimage( - args.executable.metered_clone(&self.budget_ref())?, + args.executable.metered_clone(self.budget_ref())?, key_with_signature.salt.metered_clone(self.budget_ref())?, )?; let signature_payload = self.metered_hash_xdr(&signature_payload_preimage)?; @@ -1348,7 +1344,7 @@ impl Host { Some(payload.len() as u64), )?; public_key - .verify(payload, &sig) + .verify(payload, sig) .map_err(|_| self.err_general("Failed ED25519 verification")) } @@ -1634,10 +1630,8 @@ impl EnvBase for Host { fn symbol_index_in_strs(&self, sym: Symbol, slices: &[&str]) -> Result { let mut found = None; self.metered_scan_slice_of_slices(slices, |i, slice| { - if self.symbol_matches(slice.as_bytes(), sym)? { - if found.is_none() { - found = Some(i) - } + if self.symbol_matches(slice.as_bytes(), sym)? && found.is_none() { + found = Some(i) } Ok(()) })?; @@ -1791,7 +1785,7 @@ impl VmCallerEnv for Host { data: RawVal, ) -> Result { self.record_contract_event(ContractEventType::Contract, topics, data)?; - Ok(RawVal::VOID.into()) + Ok(RawVal::VOID) } // Notes on metering: covered by the components. @@ -1799,11 +1793,9 @@ impl VmCallerEnv for Host { &self, _vmcaller: &mut VmCaller, ) -> Result { - Ok(self - .add_host_object(ScAddress::Contract( - self.get_current_contract_id_internal()?, - ))? - .into()) + self.add_host_object(ScAddress::Contract( + self.get_current_contract_id_internal()?, + )) } // Notes on metering: covered by `add_host_object`. @@ -2009,7 +2001,7 @@ impl VmCallerEnv for Host { ) -> Result { self.visit_obj(m, move |hm: &HostMap| { hm.get(&k, self)? - .map(|v| *v) + .copied() .ok_or_else(|| self.err_general("map key not found")) // FIXME: need error code }) } @@ -2021,7 +2013,7 @@ impl VmCallerEnv for Host { k: RawVal, ) -> Result { match self.visit_obj(m, |hm: &HostMap| hm.remove(&k, self))? { - Some((mnew, _)) => Ok(self.add_host_object(mnew)?.into()), + Some((mnew, _)) => Ok(self.add_host_object(mnew)?), None => Err(self.err_general("map key not found")), } } @@ -2254,7 +2246,7 @@ impl VmCallerEnv for Host { self.validate_index_lt_bound(i, hv.len())?; hv.set(i as usize, x, self.as_budget()) })?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } fn vec_get( @@ -2295,7 +2287,7 @@ impl VmCallerEnv for Host { x: RawVal, ) -> Result { let vnew = self.visit_obj(v, move |hv: &HostVec| hv.push_front(x, self.as_budget()))?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } fn vec_pop_front( @@ -2304,7 +2296,7 @@ impl VmCallerEnv for Host { v: VecObject, ) -> Result { let vnew = self.visit_obj(v, move |hv: &HostVec| hv.pop_front(self.as_budget()))?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } fn vec_push_back( @@ -2314,7 +2306,7 @@ impl VmCallerEnv for Host { x: RawVal, ) -> Result { let vnew = self.visit_obj(v, move |hv: &HostVec| hv.push_back(x, self.as_budget()))?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } fn vec_pop_back( @@ -2323,7 +2315,7 @@ impl VmCallerEnv for Host { v: VecObject, ) -> Result { let vnew = self.visit_obj(v, move |hv: &HostVec| hv.pop_back(self.as_budget()))?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } fn vec_front(&self, _vmcaller: &mut VmCaller, v: VecObject) -> Result { @@ -2350,7 +2342,7 @@ impl VmCallerEnv for Host { self.validate_index_le_bound(i, hv.len())?; hv.insert(i as usize, x, self.as_budget()) })?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } fn vec_append( @@ -2368,7 +2360,7 @@ impl VmCallerEnv for Host { } }) })?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } fn vec_slice( @@ -2384,7 +2376,7 @@ impl VmCallerEnv for Host { let range = self.valid_range_from_start_end_bound(start, end, hv.len())?; hv.slice(range, self.as_budget()) })?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } fn vec_first_index_of( @@ -2395,7 +2387,7 @@ impl VmCallerEnv for Host { ) -> Result { self.visit_obj(v, |hv: &HostVec| { Ok( - match hv.first_index_of(|other| self.compare(&x, other), &self.as_budget())? { + match hv.first_index_of(|other| self.compare(&x, other), self.as_budget())? { Some(u) => self.usize_to_u32val(u)?.into(), None => RawVal::VOID.into(), }, @@ -2528,7 +2520,7 @@ impl VmCallerEnv for Host { contract_id, key, val, - }) => Ok(self.to_host_val(&val)?.into()), + }) => Ok(self.to_host_val(val)?), _ => Err(self.err_status_msg( ScHostStorageErrorCode::ExpectContractData, "expected contract data", @@ -2703,7 +2695,7 @@ impl VmCallerEnv for Host { let scv = self.from_host_val(v)?; let mut buf = Vec::::new(); self.metered_write_xdr(&scv, &mut buf)?; - Ok(self.add_host_object(self.scbytes_from_vec(buf)?)?.into()) + self.add_host_object(self.scbytes_from_vec(buf)?) } // Notes on metering: covered by components @@ -2715,7 +2707,7 @@ impl VmCallerEnv for Host { let scv = self.visit_obj(b, |hv: &ScBytes| { self.metered_from_xdr::(hv.as_slice()) })?; - Ok(self.to_host_val(&scv)?.into()) + self.to_host_val(&scv) } fn string_copy_to_linear_memory( @@ -2857,9 +2849,7 @@ impl VmCallerEnv for Host { // Notes on metering: covered by `add_host_object` fn bytes_new(&self, _vmcaller: &mut VmCaller) -> Result { - Ok(self - .add_host_object(self.scbytes_from_vec(Vec::::new())?)? - .into()) + self.add_host_object(self.scbytes_from_vec(Vec::::new())?) } // Notes on metering: `get_mut` is free @@ -2882,7 +2872,7 @@ impl VmCallerEnv for Host { } } })?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } // Notes on metering: `get` is free @@ -2918,7 +2908,7 @@ impl VmCallerEnv for Host { vnew.remove(i as usize); Ok(ScBytes(vnew.try_into()?)) })?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } // Notes on metering: `len` is free @@ -2970,7 +2960,7 @@ impl VmCallerEnv for Host { vnew.push(u); Ok(ScBytes(vnew.try_into()?)) })?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } // Notes on metering: `pop` is free @@ -2988,7 +2978,7 @@ impl VmCallerEnv for Host { } Ok(ScBytes(vnew.try_into()?)) })?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } // Notes on metering: `first` is free @@ -3040,7 +3030,7 @@ impl VmCallerEnv for Host { vnew.insert(i as usize, u); Ok(ScBytes(vnew.try_into()?)) })?; - Ok(self.add_host_object(vnew)?.into()) + self.add_host_object(vnew) } fn bytes_append( @@ -3069,7 +3059,7 @@ impl VmCallerEnv for Host { Ok(vnew) }) })?; - Ok(self.add_host_object(ScBytes(vnew.try_into()?))?.into()) + self.add_host_object(ScBytes(vnew.try_into()?)) } fn bytes_slice( @@ -3132,11 +3122,9 @@ impl VmCallerEnv for Host { &self, _vmcaller: &mut VmCaller, ) -> Result { - Ok(self - .with_ledger_info(|li| { - self.add_host_object(self.scbytes_from_slice(li.network_id.as_slice())?) - })? - .into()) + self.with_ledger_info(|li| { + self.add_host_object(self.scbytes_from_slice(li.network_id.as_slice())?) + }) } fn get_current_call_stack( @@ -3147,7 +3135,7 @@ impl VmCallerEnv for Host { let get_host_val_tuple = |id: &Hash, function: &Symbol| -> Result<[RawVal; 2], HostError> { let id_val = self.add_host_object(self.scbytes_from_hash(id)?)?.into(); - let function_val = function.clone().into(); + let function_val = (*function).into(); Ok([id_val, function_val]) }; @@ -3159,14 +3147,14 @@ impl VmCallerEnv for Host { get_host_val_tuple(&vm.contract_id, &function)? } Frame::HostFunction(_) => continue, - Frame::Token(id, function, _) => get_host_val_tuple(&id, &function)?, + Frame::Token(id, function, _) => get_host_val_tuple(id, function)?, #[cfg(any(test, feature = "testutils"))] Frame::TestContract(tc) => get_host_val_tuple(&tc.id, &tc.func)?, }; let inner = MeteredVector::from_array(&vals, self.as_budget())?; outer.push(self.add_host_object(inner)?.into()); } - Ok(self.add_host_object(HostVec::from_vec(outer)?)?.into()) + self.add_host_object(HostVec::from_vec(outer)?) } fn fail_with_status( @@ -3226,7 +3214,7 @@ impl VmCallerEnv for Host { #[cfg(any(test, feature = "testutils"))] Frame::TestContract(c) => &c.args, }; - Ok(self.rawvals_to_scvec(args.iter())?) + self.rawvals_to_scvec(args.iter()) })?; Ok(self diff --git a/soroban-env-host/src/host/comparison.rs b/soroban-env-host/src/host/comparison.rs index 5b8626407..3ab07bab3 100644 --- a/soroban-env-host/src/host/comparison.rs +++ b/soroban-env-host/src/host/comparison.rs @@ -148,7 +148,7 @@ impl Compare> for Budg ContractCostType::HostMemCmp, Some(::DECLARED_SIZE), )?; - Ok(a.0.cmp(&b.0)) + Ok(a.0.cmp(b.0)) } } @@ -225,8 +225,8 @@ impl Compare for Budget { type Error = HostError; fn compare(&self, a: &ScVec, b: &ScVec) -> Result { - let a: &Vec = &*a; - let b: &Vec = &*b; + let a: &Vec = a; + let b: &Vec = b; self.compare(a, b) } } @@ -235,8 +235,8 @@ impl Compare for Budget { type Error = HostError; fn compare(&self, a: &ScMap, b: &ScMap) -> Result { - let a: &Vec = &*a; - let b: &Vec = &*b; + let a: &Vec = a; + let b: &Vec = b; self.compare(a, b) } } diff --git a/soroban-env-host/src/host/data_helper.rs b/soroban-env-host/src/host/data_helper.rs index 915957ed5..8d7011ba5 100644 --- a/soroban-env-host/src/host/data_helper.rs +++ b/soroban-env-host/src/host/data_helper.rs @@ -247,9 +247,9 @@ impl Host { // weight. let weight = min(signer.weight, u8::MAX as u32); // We've found the target signer in the account signers, so return the weight - return Ok(weight + return weight .try_into() - .map_err(|_| self.err_general("signer weight overflow"))?); + .map_err(|_| self.err_general("signer weight overflow")); } } } diff --git a/soroban-env-host/src/host/err_helper.rs b/soroban-env-host/src/host/err_helper.rs index cea4cd9ca..0db6a6da4 100644 --- a/soroban-env-host/src/host/err_helper.rs +++ b/soroban-env-host/src/host/err_helper.rs @@ -94,7 +94,7 @@ impl Host { where DebugError: From, { - res.map_err(|e| self.err(e.into())) + res.map_err(|e| self.err(e)) } } diff --git a/soroban-env-host/src/host/error.rs b/soroban-env-host/src/host/error.rs index 37eccc1e8..95db5bc6b 100644 --- a/soroban-env-host/src/host/error.rs +++ b/soroban-env-host/src/host/error.rs @@ -74,7 +74,7 @@ impl Debug for HostError { .enumerate() { if !wrote_heading { - writeln!(f, "")?; + writeln!(f)?; writeln!(f, "Debug events (newest first):")?; wrote_heading = true; } @@ -85,7 +85,7 @@ impl Debug for HostError { } } } - writeln!(f, "")?; + writeln!(f)?; writeln!(f, "Backtrace (newest first):")?; writeln!(f, "{:?}", bt) } diff --git a/soroban-env-host/src/host/mem_helper.rs b/soroban-env-host/src/host/mem_helper.rs index 260e80fdf..4e3cd9c44 100644 --- a/soroban-env-host/src/host/mem_helper.rs +++ b/soroban-env-host/src/host/mem_helper.rs @@ -201,7 +201,7 @@ impl Host { mut callback: impl FnMut(usize, &str) -> Result<(), HostError>, ) -> Result<(), HostError> { for (i, slice) in slices.iter().enumerate() { - callback(i, *slice)?; + callback(i, slice)?; } Ok(()) } diff --git a/soroban-env-host/src/host/metered_clone.rs b/soroban-env-host/src/host/metered_clone.rs index fc3cf76e0..41ef83d4f 100644 --- a/soroban-env-host/src/host/metered_clone.rs +++ b/soroban-env-host/src/host/metered_clone.rs @@ -358,7 +358,7 @@ impl MeteredClone for Box { charge_heap_alloc::(1, budget)?; charge_shallow_copy::(1, budget)?; // then take care of any substructure clone (recursively) - let inner: &C = &**self; + let inner: &C = self; inner.charge_for_substructure(budget) } } diff --git a/soroban-env-host/src/host/metered_map.rs b/soroban-env-host/src/host/metered_map.rs index 7670f0df3..20b2f4aec 100644 --- a/soroban-env-host/src/host/metered_map.rs +++ b/soroban-env-host/src/host/metered_map.rs @@ -374,7 +374,7 @@ impl<'a, K, V, Ctx> IntoIterator for &'a MeteredOrdMap { type IntoIter = core::slice::Iter<'a, (K, V)>; fn into_iter(self) -> Self::IntoIter { - (&self.map).into_iter() + self.map.iter() } } diff --git a/soroban-env-host/src/host/metered_vector.rs b/soroban-env-host/src/host/metered_vector.rs index 6aea06557..f909b1ed7 100644 --- a/soroban-env-host/src/host/metered_vector.rs +++ b/soroban-env-host/src/host/metered_vector.rs @@ -115,7 +115,7 @@ where } pub fn pop_front(&self, budget: &Budget) -> Result { - if self.vec.len() == 0 { + if self.vec.is_empty() { Err(ScHostObjErrorCode::VecIndexOutOfBound.into()) } else { let iter = self.vec.iter().skip(1).cloned(); @@ -142,7 +142,7 @@ where } pub fn pop_back(&self, budget: &Budget) -> Result { - if self.vec.len() == 0 { + if self.vec.is_empty() { Err(ScHostObjErrorCode::VecIndexOutOfBound.into()) } else { let count = Self::sub_or_overflow(self.vec.len(), 1)?; @@ -212,9 +212,9 @@ where { self.charge_scan(budget)?; let mut i = 0; - let mut iter = self.vec.iter(); + let iter = self.vec.iter(); // this is similar logic to `iter.position(f)` but is fallible - while let Some(val) = iter.next() { + for val in iter { if f(val)? == Ordering::Equal { return Ok(Some(i)); } diff --git a/soroban-env-host/src/host/metered_xdr.rs b/soroban-env-host/src/host/metered_xdr.rs index d94aa207b..11725ba3f 100644 --- a/soroban-env-host/src/host/metered_xdr.rs +++ b/soroban-env-host/src/host/metered_xdr.rs @@ -19,7 +19,7 @@ where fn write(&mut self, buf: &[u8]) -> std::io::Result { self.host .charge_budget(ContractCostType::ValSer, Some(buf.len() as u64)) - .map_err(|e| Into::::into(e))?; + .map_err(Into::::into)?; self.w.write(buf) } @@ -34,7 +34,7 @@ impl Host { obj: &impl WriteXdr, w: &mut Vec, ) -> Result<(), HostError> { - let mut w = MeteredWrite { host: &self, w }; + let mut w = MeteredWrite { host: self, w }; obj.write_xdr(&mut w).map_err(|e| { if let Some(e2) = e.source() { if let Some(e3) = (*e2).downcast_ref::() { diff --git a/soroban-env-host/src/host_object.rs b/soroban-env-host/src/host_object.rs index a8968d28e..2238dab75 100644 --- a/soroban-env-host/src/host_object.rs +++ b/soroban-env-host/src/host_object.rs @@ -102,7 +102,7 @@ impl HostObject { | HostObject::Address(_) | HostObject::NonceKey(_) => None, }; - return Ok(res); + Ok(res) } } diff --git a/soroban-env-host/src/native_contract/account_contract.rs b/soroban-env-host/src/native_contract/account_contract.rs index ca5932782..96e56e8e3 100644 --- a/soroban-env-host/src/native_contract/account_contract.rs +++ b/soroban-env-host/src/native_contract/account_contract.rs @@ -145,7 +145,7 @@ pub(crate) fn check_account_authentication( host.verify_sig_ed25519( sig.public_key.clone().into(), - payload_obj.clone(), + payload_obj, sig.signature.into(), )?; diff --git a/soroban-env-host/src/native_contract/base_types.rs b/soroban-env-host/src/native_contract/base_types.rs index 9b325c179..9132093d1 100644 --- a/soroban-env-host/src/native_contract/base_types.rs +++ b/soroban-env-host/src/native_contract/base_types.rs @@ -68,17 +68,14 @@ impl From> for Bytes { impl Bytes { pub fn push(&mut self, x: u8) -> Result<(), HostError> { let x32: u32 = x.into(); - self.object = self - .host - .bytes_push(self.object.into(), x32.into())? - .try_into()?; + self.object = self.host.bytes_push(self.object, x32.into())?.try_into()?; Ok(()) } pub fn append(&mut self, other: Bytes) -> Result<(), HostError> { self.object = self .host - .bytes_append(self.object.into(), other.object.into())? + .bytes_append(self.object, other.object)? .try_into()?; Ok(()) } @@ -106,7 +103,7 @@ impl TryFromVal for BytesN { fn try_from_val(env: &Host, val: &BytesObject) -> Result { let val = *val; - let len: u32 = env.bytes_len(val.into())?.try_into()?; + let len: u32 = env.bytes_len(val)?.try_into()?; if len == N.try_into() .map_err(|_| env.err_general("bytes buffer overflow"))? @@ -147,9 +144,9 @@ impl TryFromVal> for RawVal { } } -impl Into for BytesN { - fn into(self) -> RawVal { - self.object.into() +impl From> for RawVal { + fn from(val: BytesN) -> Self { + val.object.into() } } @@ -171,7 +168,7 @@ impl BytesN { pub fn to_array(&self) -> Result<[u8; N], HostError> { let mut slice = [0_u8; N]; self.host - .bytes_copy_to_slice(self.object.into(), RawVal::U32_ZERO, &mut slice)?; + .bytes_copy_to_slice(self.object, RawVal::U32_ZERO, &mut slice)?; Ok(slice) } @@ -256,7 +253,7 @@ impl Map { HostError: From<>::Error>, { let k_rv = RawVal::try_from_val(&self.host, k)?; - let v_rv = self.host.map_get(self.object.into(), k_rv)?; + let v_rv = self.host.map_get(self.object, k_rv)?; Ok(V::try_from_val(&self.host, &v_rv)?) } @@ -269,10 +266,7 @@ impl Map { { let k_rv = RawVal::try_from_val(&self.host, k)?; let v_rv = RawVal::try_from_val(&self.host, v)?; - self.object = self - .host - .map_put(self.object.into(), k_rv, v_rv)? - .try_into()?; + self.object = self.host.map_put(self.object, k_rv, v_rv)?.try_into()?; Ok(()) } } @@ -321,9 +315,9 @@ impl TryFromVal for RawVal { } } -impl Into for Vec { - fn into(self) -> RawVal { - self.object.into() +impl From for RawVal { + fn from(val: Vec) -> Self { + val.object.into() } } @@ -339,7 +333,7 @@ impl TryFromVal> for Vec { fn try_from_val(env: &Host, vals: &std::vec::Vec) -> Result { let mut v = Vec::new(env)?; for rv in vals { - v.push_raw(rv.clone())? + v.push_raw(*rv)? } Ok(v) } @@ -409,7 +403,7 @@ impl TryFromVal for Address { fn try_from_val(env: &Host, obj: &AddressObject) -> Result { Ok(Address { host: env.clone(), - object: obj.clone(), + object: *obj, }) } } diff --git a/soroban-env-host/src/native_contract/token/admin.rs b/soroban-env-host/src/native_contract/token/admin.rs index 0574e363b..d6c17a52b 100644 --- a/soroban-env-host/src/native_contract/token/admin.rs +++ b/soroban-env-host/src/native_contract/token/admin.rs @@ -8,7 +8,7 @@ use soroban_env_common::{Env, TryIntoVal}; pub fn read_administrator(e: &Host) -> Result { let key = DataKey::Admin; let rv = e.get_contract_data(key.try_into_val(e)?)?; - Ok(rv.try_into_val(e)?) + rv.try_into_val(e) } // Metering: covered by components diff --git a/soroban-env-host/src/native_contract/token/asset_info.rs b/soroban-env-host/src/native_contract/token/asset_info.rs index 8fab5f447..e3126f526 100644 --- a/soroban-env-host/src/native_contract/token/asset_info.rs +++ b/soroban-env-host/src/native_contract/token/asset_info.rs @@ -12,7 +12,7 @@ pub fn write_asset_info(e: &Host, asset_info: AssetInfo) -> Result<(), HostError pub fn read_asset_info(e: &Host) -> Result { let key = DataKey::AssetInfo; let rv = e.get_contract_data(key.try_into_val(e)?)?; - Ok(rv.try_into_val(e)?) + rv.try_into_val(e) } pub fn has_asset_info(e: &Host) -> Result { diff --git a/soroban-env-host/src/native_contract/token/balance.rs b/soroban-env-host/src/native_contract/token/balance.rs index bec604bd0..66167eafe 100644 --- a/soroban-env-host/src/native_contract/token/balance.rs +++ b/soroban-env-host/src/native_contract/token/balance.rs @@ -83,7 +83,7 @@ pub fn receive_balance(e: &Host, addr: Address, amount: i128) -> Result<(), Host BalanceValue { amount: 0, authorized: true, - clawback: is_asset_clawback_enabled(&e)?, + clawback: is_asset_clawback_enabled(e)?, } }; @@ -112,7 +112,7 @@ pub fn spend_balance_no_authorization_check( "spent amount is too large for an i64", ) })?; - transfer_classic_balance(e, acc_id, -(i64_amount as i64)) + transfer_classic_balance(e, acc_id, -i64_amount) } ScAddress::Contract(_) => { // If a balance exists, calculate new amount and write the existing authorized state as is because @@ -194,7 +194,7 @@ pub fn write_authorization(e: &Host, addr: Address, authorize: bool) -> Result<( let balance = BalanceValue { amount: 0, authorized: authorize, - clawback: is_asset_clawback_enabled(&e)?, + clawback: is_asset_clawback_enabled(e)?, }; write_balance(e, addr, balance) } @@ -223,12 +223,10 @@ pub fn check_clawbackable(e: &Host, addr: Address) -> Result<(), HostError> { match addr.to_sc_address()? { ScAddress::Account(acc_id) => match read_asset_info(e)? { - AssetInfo::Native => { - return Err(e.err_status_msg( - ContractError::OperationNotSupportedError, - "cannot clawback native asset", - )) - } + AssetInfo::Native => Err(e.err_status_msg( + ContractError::OperationNotSupportedError, + "cannot clawback native asset", + )), AssetInfo::AlphaNum4(asset) => { let issuer_account_id = e.account_id_from_bytesobj(asset.issuer.into())?; validate_trustline( @@ -339,7 +337,7 @@ fn get_classic_balance(e: &Host, to_key: AccountId) -> Result<(i64, i64), HostEr // Metering: *mostly* covered by components. The arithmetics are free. fn transfer_account_balance(e: &Host, account_id: AccountId, amount: i64) -> Result<(), HostError> { - let lk = e.to_account_key(account_id.clone()); + let lk = e.to_account_key(account_id); e.with_mut_storage(|storage| { let mut le = storage @@ -424,7 +422,7 @@ fn transfer_trustline_balance( // TODO: Metering analysis //returns (total balance, spendable balance) fn get_account_balance(e: &Host, account_id: AccountId) -> Result<(i64, i64), HostError> { - let lk = e.to_account_key(account_id.clone()); + let lk = e.to_account_key(account_id); e.with_mut_storage(|storage| { let le = storage @@ -436,7 +434,7 @@ fn get_account_balance(e: &Host, account_id: AccountId) -> Result<(i64, i64), Ho _ => Err(e.err_status_msg(ContractError::InternalError, "unexpected entry found")), }?; - let min = get_min_max_account_balance(e, &ae)?.0; + let min = get_min_max_account_balance(e, ae)?.0; if ae.balance < min { return Err(e.err_status_msg( ContractError::InternalError, @@ -596,7 +594,7 @@ fn set_authorization(e: &Host, to_key: AccountId, authorize: bool) -> Result<(), )); } - let issuer_acc = e.load_account(issuer.clone())?; + let issuer_acc = e.load_account(issuer)?; if !authorize && (issuer_acc.flags & (AccountFlags::RevocableFlag as u32) == 0) { return Err(e.err_status_msg( @@ -609,12 +607,10 @@ fn set_authorization(e: &Host, to_key: AccountId, authorize: bool) -> Result<(), }; match read_asset_info(e)? { - AssetInfo::Native => { - return Err(e.err_status_msg( - ContractError::OperationNotSupportedError, - "expected trustline asset", - )) - } + AssetInfo::Native => Err(e.err_status_msg( + ContractError::OperationNotSupportedError, + "expected trustline asset", + )), AssetInfo::AlphaNum4(asset) => { let issuer_account_id = e.account_id_from_bytesobj(asset.issuer.into())?; set_trustline_authorization_safe( diff --git a/soroban-env-host/src/native_contract/token/contract.rs b/soroban-env-host/src/native_contract/token/contract.rs index f8e88281d..04d70632e 100644 --- a/soroban-env-host/src/native_contract/token/contract.rs +++ b/soroban-env-host/src/native_contract/token/contract.rs @@ -113,7 +113,7 @@ fn check_non_native(e: &Host) -> Result<(), HostError> { // Metering: *mostly* covered by components. impl TokenTrait for Token { fn init_asset(e: &Host, asset_bytes: Bytes) -> Result<(), HostError> { - if has_asset_info(&e)? { + if has_asset_info(e)? { return Err(e.err_status_msg( ContractError::AlreadyInitializedError, "token has been already initialized", @@ -135,13 +135,13 @@ impl TokenTrait for Token { } match asset { Asset::Native => { - write_asset_info(&e, AssetInfo::Native)?; + write_asset_info(e, AssetInfo::Native)?; //No admin for the Native token } Asset::CreditAlphanum4(asset4) => { - write_administrator(&e, Address::from_account(e, &asset4.issuer)?)?; + write_administrator(e, Address::from_account(e, &asset4.issuer)?)?; write_asset_info( - &e, + e, AssetInfo::AlphaNum4(AlphaNum4AssetInfo { asset_code: BytesN::<4>::try_from_val( e, @@ -155,9 +155,9 @@ impl TokenTrait for Token { )?; } Asset::CreditAlphanum12(asset12) => { - write_administrator(&e, Address::from_account(e, &asset12.issuer)?)?; + write_administrator(e, Address::from_account(e, &asset12.issuer)?)?; write_asset_info( - &e, + e, AssetInfo::AlphaNum12(AlphaNum12AssetInfo { asset_code: BytesN::<12>::try_from_val( e, @@ -173,7 +173,7 @@ impl TokenTrait for Token { } //Write metadata only after asset_info is set - set_metadata(&e)?; + set_metadata(e)?; Ok(()) } @@ -190,11 +190,11 @@ impl TokenTrait for Token { ) -> Result<(), HostError> { check_nonnegative_amount(e, amount)?; from.require_auth()?; - let allowance = read_allowance(&e, from.clone(), spender.clone())?; + let allowance = read_allowance(e, from.clone(), spender.clone())?; let new_allowance = allowance .checked_add(amount) .ok_or_else(|| e.err_status(ContractError::OverflowError))?; - write_allowance(&e, from.clone(), spender.clone(), new_allowance)?; + write_allowance(e, from.clone(), spender.clone(), new_allowance)?; event::increase_allowance(e, from, spender, amount)?; Ok(()) } @@ -207,11 +207,11 @@ impl TokenTrait for Token { ) -> Result<(), HostError> { check_nonnegative_amount(e, amount)?; from.require_auth()?; - let allowance = read_allowance(&e, from.clone(), spender.clone())?; + let allowance = read_allowance(e, from.clone(), spender.clone())?; if amount >= allowance { - write_allowance(&e, from.clone(), spender.clone(), 0)?; + write_allowance(e, from.clone(), spender.clone(), 0)?; } else { - write_allowance(&e, from.clone(), spender.clone(), allowance - amount)?; + write_allowance(e, from.clone(), spender.clone(), allowance - amount)?; } event::decrease_allowance(e, from, spender, amount)?; Ok(()) @@ -228,7 +228,7 @@ impl TokenTrait for Token { // Metering: covered by components fn authorized(e: &Host, addr: Address) -> Result { - is_authorized(&e, addr) + is_authorized(e, addr) } // Metering: covered by components @@ -263,7 +263,7 @@ impl TokenTrait for Token { check_nonnegative_amount(e, amount)?; check_non_native(e)?; from.require_auth()?; - spend_balance(&e, from.clone(), amount)?; + spend_balance(e, from.clone(), amount)?; event::burn(e, from, amount)?; Ok(()) } @@ -273,8 +273,8 @@ impl TokenTrait for Token { check_nonnegative_amount(e, amount)?; check_non_native(e)?; spender.require_auth()?; - spend_allowance(&e, from.clone(), spender, amount)?; - spend_balance(&e, from.clone(), amount)?; + spend_allowance(e, from.clone(), spender, amount)?; + spend_balance(e, from.clone(), amount)?; event::burn(e, from, amount)?; Ok(()) } @@ -282,10 +282,10 @@ impl TokenTrait for Token { // Metering: covered by components fn clawback(e: &Host, from: Address, amount: i128) -> Result<(), HostError> { check_nonnegative_amount(e, amount)?; - check_clawbackable(&e, from.clone())?; + check_clawbackable(e, from.clone())?; let admin = read_administrator(e)?; admin.require_auth()?; - spend_balance_no_authorization_check(e, from.clone(), amount.clone())?; + spend_balance_no_authorization_check(e, from.clone(), amount)?; event::clawback(e, admin, from, amount)?; Ok(()) } @@ -324,10 +324,10 @@ impl TokenTrait for Token { } fn name(e: &Host) -> Result { - read_name(&e) + read_name(e) } fn symbol(e: &Host) -> Result { - read_symbol(&e) + read_symbol(e) } } diff --git a/soroban-env-host/src/native_contract/token/event.rs b/soroban-env-host/src/native_contract/token/event.rs index 6cd6c9b95..1f733aa12 100644 --- a/soroban-env-host/src/native_contract/token/event.rs +++ b/soroban-env-host/src/native_contract/token/event.rs @@ -15,7 +15,7 @@ pub(crate) fn increase_allowance( topics.push(&Symbol::try_from_val(e, &"increase_allowance")?)?; topics.push(&from)?; topics.push(&to)?; - topics.push(&read_name(&e)?)?; + topics.push(&read_name(e)?)?; e.contract_event(topics.into(), amount.try_into_val(e)?)?; Ok(()) } @@ -30,7 +30,7 @@ pub(crate) fn decrease_allowance( topics.push(&Symbol::try_from_val(e, &"decrease_allowance")?)?; topics.push(&from)?; topics.push(&to)?; - topics.push(&read_name(&e)?)?; + topics.push(&read_name(e)?)?; e.contract_event(topics.into(), amount.try_into_val(e)?)?; Ok(()) } @@ -45,7 +45,7 @@ pub(crate) fn transfer( topics.push(&Symbol::try_from_val(e, &"transfer")?)?; topics.push(&from)?; topics.push(&to)?; - topics.push(&read_name(&e)?)?; + topics.push(&read_name(e)?)?; e.contract_event(topics.into(), amount.try_into_val(e)?)?; Ok(()) } @@ -55,7 +55,7 @@ pub(crate) fn mint(e: &Host, admin: Address, to: Address, amount: i128) -> Resul topics.push(&Symbol::try_from_val(e, &"mint")?)?; topics.push(&admin)?; topics.push(&to)?; - topics.push(&read_name(&e)?)?; + topics.push(&read_name(e)?)?; e.contract_event(topics.into(), amount.try_into_val(e)?)?; Ok(()) } @@ -70,7 +70,7 @@ pub(crate) fn clawback( topics.push(&Symbol::try_from_val(e, &"clawback")?)?; topics.push(&admin)?; topics.push(&from)?; - topics.push(&read_name(&e)?)?; + topics.push(&read_name(e)?)?; e.contract_event(topics.into(), amount.try_into_val(e)?)?; Ok(()) } @@ -85,7 +85,7 @@ pub(crate) fn set_authorized( topics.push(&Symbol::try_from_val(e, &"set_authorized")?)?; topics.push(&admin)?; topics.push(&id)?; - topics.push(&read_name(&e)?)?; + topics.push(&read_name(e)?)?; e.contract_event(topics.into(), authorize.try_into_val(e)?)?; Ok(()) } @@ -94,7 +94,7 @@ pub(crate) fn set_admin(e: &Host, admin: Address, new_admin: Address) -> Result< let mut topics = Vec::new(e)?; topics.push(&Symbol::try_from_val(e, &"set_admin")?)?; topics.push(&admin)?; - topics.push(&read_name(&e)?)?; + topics.push(&read_name(e)?)?; e.contract_event(topics.into(), new_admin.try_into_val(e)?)?; Ok(()) } @@ -103,7 +103,7 @@ pub(crate) fn burn(e: &Host, from: Address, amount: i128) -> Result<(), HostErro let mut topics = Vec::new(e)?; topics.push(&Symbol::try_from_val(e, &"burn")?)?; topics.push(&from)?; - topics.push(&read_name(&e)?)?; + topics.push(&read_name(e)?)?; e.contract_event(topics.into(), amount.try_into_val(e)?)?; Ok(()) } diff --git a/soroban-env-host/src/storage.rs b/soroban-env-host/src/storage.rs index d6cdf2d5b..bd5e32dfa 100644 --- a/soroban-env-host/src/storage.rs +++ b/soroban-env-host/src/storage.rs @@ -114,18 +114,13 @@ impl Footprint { } } -#[derive(Clone)] +#[derive(Clone, Default)] pub enum FootprintMode { Recording(Rc), + #[default] Enforcing, } -impl Default for FootprintMode { - fn default() -> Self { - FootprintMode::Enforcing - } -} - /// A special-purpose map from [LedgerKey]s to [LedgerEntry]s. Represents a /// transactional batch of contract IO from and to durable storage, while /// partitioning that IO between concurrently executing groups of contracts @@ -205,7 +200,7 @@ impl Storage { match self.map.get::>(key, budget)? { None => Err(ScHostStorageErrorCode::MissingKeyInGet.into()), Some(None) => Err(ScHostStorageErrorCode::GetOnDeletedKey.into()), - Some(Some(val)) => Ok(Rc::clone(&val)), + Some(Some(val)) => Ok(Rc::clone(val)), } } @@ -226,7 +221,7 @@ impl Storage { }; self.map = self .map - .insert(Rc::clone(key), val.map(|v| Rc::clone(v)), budget)?; + .insert(Rc::clone(key), val.map(Rc::clone), budget)?; Ok(()) } diff --git a/soroban-test-wasms/src/lib.rs b/soroban-test-wasms/src/lib.rs index 835b6ccf3..bb0a869af 100644 --- a/soroban-test-wasms/src/lib.rs +++ b/soroban-test-wasms/src/lib.rs @@ -42,27 +42,24 @@ //! documentation purpopses without having to worry about breaking tests in //! the host here. -pub const ADD_I32: &'static [u8] = - include_bytes!("../wasm-workspace/opt/example_add_i32.wasm").as_slice(); -pub const CREATE_CONTRACT: &'static [u8] = +pub const ADD_I32: &[u8] = include_bytes!("../wasm-workspace/opt/example_add_i32.wasm").as_slice(); +pub const CREATE_CONTRACT: &[u8] = include_bytes!("../wasm-workspace/opt/example_create_contract.wasm").as_slice(); -pub const CONTRACT_STORAGE: &'static [u8] = +pub const CONTRACT_STORAGE: &[u8] = include_bytes!("../wasm-workspace/opt/example_contract_data.wasm").as_slice(); -pub const LINEAR_MEMORY: &'static [u8] = +pub const LINEAR_MEMORY: &[u8] = include_bytes!("../wasm-workspace/opt/example_linear_memory.wasm").as_slice(); -pub const VEC: &'static [u8] = include_bytes!("../wasm-workspace/opt/example_vec.wasm").as_slice(); -pub const INVOKE_CONTRACT: &'static [u8] = +pub const VEC: &[u8] = include_bytes!("../wasm-workspace/opt/example_vec.wasm").as_slice(); +pub const INVOKE_CONTRACT: &[u8] = include_bytes!("../wasm-workspace/opt/example_invoke_contract.wasm").as_slice(); -pub const HOSTILE: &'static [u8] = - include_bytes!("../wasm-workspace/opt/example_hostile.wasm").as_slice(); -pub const FIB: &'static [u8] = include_bytes!("../wasm-workspace/opt/example_fib.wasm").as_slice(); -pub const FANNKUCH: &'static [u8] = +pub const HOSTILE: &[u8] = include_bytes!("../wasm-workspace/opt/example_hostile.wasm").as_slice(); +pub const FIB: &[u8] = include_bytes!("../wasm-workspace/opt/example_fib.wasm").as_slice(); +pub const FANNKUCH: &[u8] = include_bytes!("../wasm-workspace/opt/example_fannkuch.wasm").as_slice(); -pub const COMPLEX: &'static [u8] = - include_bytes!("../wasm-workspace/opt/example_complex.wasm").as_slice(); -pub const SIMPLE_ACCOUNT_CONTRACT: &'static [u8] = +pub const COMPLEX: &[u8] = include_bytes!("../wasm-workspace/opt/example_complex.wasm").as_slice(); +pub const SIMPLE_ACCOUNT_CONTRACT: &[u8] = include_bytes!("../wasm-workspace/opt/example_simple_account.wasm").as_slice(); -pub const AUTH_TEST_CONTRACT: &'static [u8] = +pub const AUTH_TEST_CONTRACT: &[u8] = include_bytes!("../wasm-workspace/opt/auth_test_contract.wasm").as_slice(); -pub const UPDATEABLE_CONTRACT: &'static [u8] = +pub const UPDATEABLE_CONTRACT: &[u8] = include_bytes!("../wasm-workspace/opt/example_updateable_contract.wasm").as_slice();