From 852592136db6c82aa63bcf79222786a6f889af8d Mon Sep 17 00:00:00 2001 From: Lorenzo Delgado Date: Tue, 4 Jun 2024 12:48:04 +0200 Subject: [PATCH] chore(ci): add rustfmt checks and fix format issues (#22) Signed-off-by: Lorenzo Delgado --- .github/renovate.json5 | 109 ++++++++++ .github/workflows/ci.yml | 54 +++++ .gitignore | 11 +- Cargo.lock | 426 +++++++++++++++++++++++++++++++++++++++ rust-toolchain.toml | 3 + rustfmt.toml | 4 + src/pool.rs | 10 +- src/prelude.rs | 15 +- src/tests.rs | 14 +- src/voucher.rs | 12 +- 10 files changed, 632 insertions(+), 26 deletions(-) create mode 100644 .github/renovate.json5 create mode 100644 .github/workflows/ci.yml create mode 100644 Cargo.lock create mode 100644 rust-toolchain.toml create mode 100644 rustfmt.toml diff --git a/.github/renovate.json5 b/.github/renovate.json5 new file mode 100644 index 0000000..284c355 --- /dev/null +++ b/.github/renovate.json5 @@ -0,0 +1,109 @@ +{ + $schema: 'https://docs.renovatebot.com/renovate-schema.json', + extends: [ + 'config:recommended', + ':semanticCommits', + ':semanticCommitTypeAll(chore)', + 'helpers:pinGitHubActionDigests', + ], + schedule: [ + 'before 6am on Monday', + ], + configMigration: true, + rebaseWhen: 'behind-base-branch', + lockFileMaintenance: { + enabled: true, + }, + packageRules: [ + { + groupName: 'futures crates', + groupSlug: 'futures', + matchManagers: [ + 'cargo', + ], + matchPackageNames: [ + 'futures', + ], + matchPackagePrefixes: [ + 'futures-', + 'futures_', + ], + }, + { + groupName: 'serde crates', + groupSlug: 'serde', + matchManagers: [ + 'cargo', + ], + matchPackageNames: [ + 'serde', + ], + matchPackagePrefixes: [ + 'serde-', + 'serde_', + ], + }, + { + groupName: 'tonic crates', + groupSlug: 'tonic', + matchManagers: [ + 'cargo', + ], + matchSourceUrlPrefixes: [ + 'https://github.com/hyperium/tonic', + 'https://github.com/tokio-rs/prost', + ], + }, + { + groupName: 'tracing crates', + groupSlug: 'tracing', + matchManagers: [ + 'cargo', + ], + matchSourceUrlPrefixes: [ + 'https://github.com/tokio-rs/tracing', + ], + matchPackagePrefixes: [ + 'tracing-', + 'tracing_', + ], + }, + { + groupName: 'alloy-rs core types monorepo', + groupSlug: 'alloy-core', + matchManagers: [ + 'cargo', + ], + matchSourceUrlPrefixes: [ + 'https://github.com/alloy-rs/core', + ], + }, + { + groupName: 'async-graphql crates', + groupSlug: 'async-graphql', + matchManagers: [ + 'cargo', + ], + matchPackageNames: [ + 'async-graphql', + ], + matchPackagePrefixes: [ + 'async-graphql-', + ], + }, + ], + customManagers: [ + { + customType: 'regex', + fileMatch: [ + '^rust-toolchain(\\.toml)?$', + ], + matchStrings: [ + 'channel\\s*=\\s*"(?\\d+\\.\\d+\\.\\d+)"', + ], + depNameTemplate: 'rust', + packageNameTemplate: 'rust-lang/rust', + datasourceTemplate: 'github-releases', + }, + ], +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d95d498 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,54 @@ +name: ci +on: + pull_request: + push: + branches: [ main ] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: full + GH_USER: ${{ github.repository_owner }} + GH_TOKEN: ${{ secrets.GH_PRIVATE_TOKEN }} + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + components: clippy + + - name: Cache rust build files + uses: Leafwing-Studios/cargo-cache@c7e8aa40ae2c975774d3bd766beb92927cfd7771 # v1 + + - name: check (release) + run: cargo check --workspace --all-targets --all-features --release + + - name: clippy + run: cargo clippy --workspace --all-targets --all-features -- -D warnings --force-warn deprecated --force-warn dead-code + + - name: unit-tests + run: cargo test --all-features --lib + + format: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@nightly + with: + toolchain: nightly + components: rustfmt + + - run: cargo +nightly fmt --all -- --check diff --git a/.gitignore b/.gitignore index 96ef6c0..8e298ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ -/target -Cargo.lock +## IDEs and Editors +.idea/ +.vscode/ + +## Rust +debug/ +target/ +**/*.rs.bk +*.pdb diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b3344d9 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,426 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "either" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "parity-scale-codec" +version = "3.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "primitive-types" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" +dependencies = [ + "fixed-hash", + "impl-codec", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "receipts" +version = "0.1.0" +dependencies = [ + "itertools", + "lazy_static", + "primitive-types", + "rand", + "rustc-hex", + "secp256k1", + "tiny-keccak", +] + +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + +[[package]] +name = "secp256k1" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" +dependencies = [ + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" +dependencies = [ + "cc", +] + +[[package]] +name = "serde" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "toml_datetime" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" + +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..02cb8fc --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "stable" +profile = "default" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..52f7421 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,4 @@ +unstable_features = true +imports_granularity = "Crate" +group_imports = "StdExternalCrate" +reorder_modules = true diff --git a/src/pool.rs b/src/pool.rs index 0868c0c..1abe52e 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -1,7 +1,9 @@ -use crate::prelude::*; +use std::fmt; + use rand::RngCore; use secp256k1::SecretKey; -use std::fmt; + +use crate::prelude::*; // Keep track of the offsets to index the data in an array. // I'm really happy with how this turned out to make book-keeping easier. @@ -81,7 +83,7 @@ impl ReceiptPool { } pub fn commit(&mut self, signer: &SecretKey, locked_fee: U256) -> Result, BorrowFail> { - let receipt = if self.receipt_cache.len() == 0 { + let receipt = if self.receipt_cache.is_empty() { let mut receipt_id = ReceiptId::default(); rng().fill_bytes(&mut receipt_id); PooledReceipt { @@ -152,7 +154,7 @@ mod tests { #[track_caller] fn assert_successful_borrow(pool: &mut ReceiptPool, fee: impl Into) -> Vec { - pool.commit(&test_signer(), U256::from(fee.into())) + pool.commit(&test_signer(), fee.into()) .expect("Should be able to borrow") } diff --git a/src/prelude.rs b/src/prelude.rs index af71360..5bab9cf 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,11 +1,10 @@ +pub use std::convert::TryInto as _; +use std::{fmt, mem::size_of}; + use lazy_static::lazy_static; +pub use primitive_types::U256; +pub use rand::{thread_rng as rng, Rng as _}; use secp256k1::{Message, Secp256k1, SecretKey}; -use std::{fmt, mem::size_of}; -pub use { - primitive_types::U256, - rand::{thread_rng as rng, Rng as _}, - std::convert::TryInto as _, -}; pub type Bytes32 = [u8; 32]; pub type Address = [u8; 20]; @@ -28,7 +27,7 @@ lazy_static! { pub fn hash_bytes(bytes: &[u8]) -> Bytes32 { use tiny_keccak::Hasher; let mut hasher = tiny_keccak::Keccak::v256(); - hasher.update(&bytes); + hasher.update(bytes); let mut output = Bytes32::default(); hasher.finalize(&mut output); output @@ -65,7 +64,7 @@ pub fn sign(data: &[u8], signer: &SecretKey) -> Result { }; let mut serialized = [0; 65]; - (&mut serialized[..64]).copy_from_slice(&signature); + serialized[..64].copy_from_slice(&signature); serialized[64] = recovery_id; Ok(serialized) diff --git a/src/tests.rs b/src/tests.rs index 5bb2f77..5957cd4 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,8 +1,8 @@ -use crate::prelude::*; -use crate::*; +use std::{convert::TryFrom, time::Instant}; + use secp256k1::{PublicKey, SecretKey}; -use std::convert::TryFrom; -use std::time::Instant; + +use crate::{prelude::*, *}; pub fn bytes(id: u8) -> [u8; N] { [id; N] @@ -88,8 +88,8 @@ fn attempt_to_double_collect_with_partial_voucher_rejects() { .unwrap() }; - let partial_1 = to_partial((&borrows[5..]).to_vec()); - let partial_2 = to_partial((&borrows[..5]).to_vec()); + let partial_1 = to_partial(borrows[5..].to_vec()); + let partial_2 = to_partial(borrows[..5].to_vec()); for ordering in [ vec![partial_1.clone(), partial_2.clone()], @@ -208,7 +208,7 @@ fn partial_vouchers_combine() { ); let partial_vouchers: Vec = receipts .chunks(112 * batch_size) - .map(|receipts| create_partial_voucher(receipts)) + .map(create_partial_voucher) .collect(); let oneshot_receipt = receipts_to_voucher( &allocation_id, diff --git a/src/voucher.rs b/src/voucher.rs index 32e364a..cb10c34 100644 --- a/src/voucher.rs +++ b/src/voucher.rs @@ -1,9 +1,11 @@ -use crate::prelude::*; +use std::fmt; + use itertools::Itertools as _; use secp256k1::{ecdsa, Message, PublicKey, SecretKey}; -use std::fmt; use tiny_keccak::{Hasher, Keccak}; +use crate::prelude::*; + #[derive(Debug, PartialEq)] pub enum VoucherError { InvalidData, @@ -151,7 +153,7 @@ fn verify_receipts( if Receipts::new(data)? .map(|receipt| *receipt.id) .tuple_windows() - .any(|(a, b)| !(a < b)) + .any(|(a, b)| a >= b) { return Err(VoucherError::UnorderedReceipts); } @@ -191,7 +193,7 @@ pub fn combine_partial_vouchers( voucher_signer: &SecretKey, partial_vouchers: &[PartialVoucher], ) -> Result { - if partial_vouchers.len() == 0 { + if partial_vouchers.is_empty() { return Err(VoucherError::NoValue); } @@ -212,7 +214,7 @@ pub fn combine_partial_vouchers( } // Verify signatures - let partial_voucher_signer = PublicKey::from_secret_key(&SECP256K1, &voucher_signer); + let partial_voucher_signer = PublicKey::from_secret_key(&SECP256K1, voucher_signer); for partial_voucher in partial_vouchers { let mut hasher = Keccak::v256(); hasher.update(allocation_id);