From cc2552d7d2ad3607688133fcfc9d237a38a74474 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 3 Jan 2024 16:34:28 -0500 Subject: [PATCH] fix: clippy --- cmd/crates/soroban-spec-tools/src/lib.rs | 4 ++-- cmd/crates/soroban-spec-typescript/src/lib.rs | 2 +- cmd/soroban-cli/src/commands/contract/id/wasm.rs | 6 +----- cmd/soroban-cli/src/commands/contract/invoke.rs | 2 +- cmd/soroban-cli/src/commands/contract/restore.rs | 2 +- cmd/soroban-cli/src/rpc/txn.rs | 6 +++--- cmd/soroban-cli/src/utils.rs | 6 +----- 7 files changed, 10 insertions(+), 18 deletions(-) diff --git a/cmd/crates/soroban-spec-tools/src/lib.rs b/cmd/crates/soroban-spec-tools/src/lib.rs index e7b72d1b07..7f310fd996 100644 --- a/cmd/crates/soroban-spec-tools/src/lib.rs +++ b/cmd/crates/soroban-spec-tools/src/lib.rs @@ -386,7 +386,7 @@ impl Spec { let val = self.from_json(v, &f.type_)?; let key = StringM::from_str(name).unwrap(); Ok(ScMapEntry { - key: ScVal::Symbol(key.try_into()?), + key: ScVal::Symbol(key.into()), val, }) }) @@ -1135,7 +1135,7 @@ impl Spec { match self.find(&name.to_utf8_string_lossy()).ok()? { ScSpecEntry::UdtStructV0(ScSpecUdtStructV0 { fields, .. }) if fields - .get(0) + .first() .map(|f| f.name.to_utf8_string_lossy() == "0") .unwrap_or_default() => { diff --git a/cmd/crates/soroban-spec-typescript/src/lib.rs b/cmd/crates/soroban-spec-typescript/src/lib.rs index 4225b8aab7..790f43b071 100644 --- a/cmd/crates/soroban-spec-typescript/src/lib.rs +++ b/cmd/crates/soroban-spec-typescript/src/lib.rs @@ -182,7 +182,7 @@ pub fn entry_to_parser(entry: &Entry) -> Option<(String, String)> { } let output = outputs - .get(0) + .first() .map(|_| format!("this.spec.funcResToNative(\"{name}\", result)")) .unwrap_or_default(); let parse_result_xdr = if return_type == "void" { diff --git a/cmd/soroban-cli/src/commands/contract/id/wasm.rs b/cmd/soroban-cli/src/commands/contract/id/wasm.rs index 4097e7bbf8..9c02f07d24 100644 --- a/cmd/soroban-cli/src/commands/contract/id/wasm.rs +++ b/cmd/soroban-cli/src/commands/contract/id/wasm.rs @@ -58,11 +58,7 @@ pub fn get_contract_id( contract_id_preimage: ContractIdPreimage, network_passphrase: &str, ) -> Result { - let network_id = Hash( - Sha256::digest(network_passphrase.as_bytes()) - .try_into() - .unwrap(), - ); + let network_id = Hash(Sha256::digest(network_passphrase.as_bytes()).into()); let preimage = HashIdPreimage::ContractId(HashIdPreimageContractId { network_id, contract_id_preimage, diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index e72a46c04d..669342b065 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -365,7 +365,7 @@ fn log_resources(resources: &SorobanResources) { pub fn output_to_string(spec: &Spec, res: &ScVal, function: &str) -> Result { let mut res_str = String::new(); - if let Some(output) = spec.find_function(function)?.outputs.get(0) { + if let Some(output) = spec.find_function(function)?.outputs.first() { res_str = spec .xdr_to_json(res, output) .map_err(|e| Error::CannotPrintResult { diff --git a/cmd/soroban-cli/src/commands/contract/restore.rs b/cmd/soroban-cli/src/commands/contract/restore.rs index fb7f560fae..38b8a84a19 100644 --- a/cmd/soroban-cli/src/commands/contract/restore.rs +++ b/cmd/soroban-cli/src/commands/contract/restore.rs @@ -182,7 +182,7 @@ impl Cmd { } fn parse_operations(ops: &[OperationMeta]) -> Option { - ops.get(0).and_then(|op| { + ops.first().and_then(|op| { op.changes.iter().find_map(|entry| match entry { LedgerEntryChange::Updated(LedgerEntry { data: diff --git a/cmd/soroban-cli/src/rpc/txn.rs b/cmd/soroban-cli/src/rpc/txn.rs index cda5a38575..9e36938ddd 100644 --- a/cmd/soroban-cli/src/rpc/txn.rs +++ b/cmd/soroban-cli/src/rpc/txn.rs @@ -125,10 +125,10 @@ impl Assembled { pub fn auth(&self) -> VecM { self.txn .operations - .get(0) + .first() .and_then(|op| match op.body { OperationBody::InvokeHostFunction(ref body) => (matches!( - body.auth.get(0).map(|x| &x.root_invocation.function), + body.auth.first().map(|x| &x.root_invocation.function), Some(&SorobanAuthorizedFunction::ContractFn(_)) )) .then_some(body.auth.clone()), @@ -235,7 +235,7 @@ fn sign_soroban_authorizations( body: OperationBody::InvokeHostFunction(InvokeHostFunctionOp { auth, .. }), .. }] if matches!( - auth.get(0).map(|x| &x.root_invocation.function), + auth.first().map(|x| &x.root_invocation.function), Some(&SorobanAuthorizedFunction::ContractFn(_)) ) => { diff --git a/cmd/soroban-cli/src/utils.rs b/cmd/soroban-cli/src/utils.rs index ab0382b489..ff0018a94c 100644 --- a/cmd/soroban-cli/src/utils.rs +++ b/cmd/soroban-cli/src/utils.rs @@ -103,11 +103,7 @@ pub fn contract_id_hash_from_asset( asset: &Asset, network_passphrase: &str, ) -> Result { - let network_id = Hash( - Sha256::digest(network_passphrase.as_bytes()) - .try_into() - .unwrap(), - ); + let network_id = Hash(Sha256::digest(network_passphrase.as_bytes()).into()); let preimage = HashIdPreimage::ContractId(HashIdPreimageContractId { network_id, contract_id_preimage: ContractIdPreimage::Asset(asset.clone()),