From 535e4f191f15d09b9fa54ff49ef37b0efd0a713e Mon Sep 17 00:00:00 2001 From: Molly Karcher Date: Fri, 5 Jan 2024 18:52:30 -0500 Subject: [PATCH] resolve clippy errors --- .github/workflows/rust.yml | 6 ++++++ cmd/crates/soroban-spec-tools/src/lib.rs | 4 ++-- cmd/crates/soroban-spec-typescript/src/lib.rs | 2 +- cmd/soroban-cli/src/commands/contract/deploy.rs | 2 +- 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 +----- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 599b4cbe9..0bc4e7e65 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -47,6 +47,12 @@ jobs: target: x86_64-unknown-linux-gnu - os: ubuntu-latest target: aarch64-unknown-linux-gnu + - os: macos-latest + target: x86_64-apple-darwin + - os: macos-latest + target: aarch64-apple-darwin + - os: windows-latest-8-cores + target: x86_64-pc-windows-msvc runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 diff --git a/cmd/crates/soroban-spec-tools/src/lib.rs b/cmd/crates/soroban-spec-tools/src/lib.rs index e7b72d1b0..7f310fd99 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 4225b8aab..790f43b07 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/deploy.rs b/cmd/soroban-cli/src/commands/contract/deploy.rs index 1be8a3f54..c89654a4d 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy.rs @@ -207,7 +207,7 @@ fn get_contract_id( contract_id_preimage: ContractIdPreimage, network_passphrase: &str, ) -> Result { - let network_id = Hash(Sha256::digest(network_passphrase.as_bytes()).try_into()?); + 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 78be7b381..2b6322b88 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 fb7f560fa..38b8a84a1 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 cda5a3857..9e36938dd 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 ab0382b48..ff0018a94 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()),