From 13c119e144886fae2f07999c03f0495781fbdd8a Mon Sep 17 00:00:00 2001 From: "Dr. Maxim Orlovsky" Date: Tue, 27 Dec 2022 20:36:42 +0100 Subject: [PATCH] Fix clippy lints --- build.rs | 9 ++++----- cli/build.rs | 11 +++++------ cli/src/command.rs | 4 ++-- rpc/src/client.rs | 2 +- rpc/src/error.rs | 10 ++++++++++ rpc/src/reveal.rs | 4 ++-- src/bucketd/processor.rs | 10 +++++----- src/bucketd/service.rs | 8 ++------ src/db.rs | 38 +++++++++++++++++++------------------- src/lib.rs | 1 + 10 files changed, 51 insertions(+), 46 deletions(-) diff --git a/build.rs b/build.rs index adbd653..8838a64 100644 --- a/build.rs +++ b/build.rs @@ -9,8 +9,7 @@ // You should have received a copy of the MIT License along with this software. // If not, see . -use std::env; -use std::fs; +use std::{env, fs}; use clap::IntoApp; use clap_complete::generate_to; @@ -35,9 +34,9 @@ fn main() -> Result<(), configure_me_codegen::Error> { fs::create_dir_all(outdir).expect("failed to create shell dir"); for app in [rgbd::Opts::command(), bucketd::Opts::command()].iter_mut() { let name = app.get_name().to_string(); - generate_to(Bash, app, &name, &outdir)?; - generate_to(PowerShell, app, &name, &outdir)?; - generate_to(Zsh, app, &name, &outdir)?; + generate_to(Bash, app, &name, outdir)?; + generate_to(PowerShell, app, &name, outdir)?; + generate_to(Zsh, app, &name, outdir)?; } // configure_me_codegen::build_script_auto() } diff --git a/cli/build.rs b/cli/build.rs index 6be9750..329ad90 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -27,12 +27,11 @@ fn main() -> Result<(), configure_me_codegen::Error> { if env::var("DOCS_RS").is_err() { let outdir = "../shell"; fs::create_dir_all(outdir).expect("failed to create shell dir"); - for app in [cli::Opts::command()].iter_mut() { - let name = app.get_name().to_string(); - generate_to(Bash, app, &name, &outdir)?; - generate_to(PowerShell, app, &name, &outdir)?; - generate_to(Zsh, app, &name, &outdir)?; - } + let mut app = cli::Opts::command(); + let name = app.get_name().to_string(); + generate_to(Bash, &mut app, &name, outdir)?; + generate_to(PowerShell, &mut app, &name, outdir)?; + generate_to(Zsh, &mut app, &name, outdir)?; } // configure_me_codegen::build_script_auto() Ok(()) diff --git a/cli/src/command.rs b/cli/src/command.rs index 2c8f39d..6ee77a5 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -239,7 +239,7 @@ impl Exec for Opts { let outpoints: BTreeSet<_> = psbt.inputs.iter().map(|input| input.previous_outpoint).collect(); - let state_map = client.outpoint_state(outpoints.clone(), progress)?; + let state_map = client.outpoint_state(outpoints, progress)?; for (cid, outpoint_map) in state_map { if cid == contract_id { continue; @@ -286,7 +286,7 @@ impl Exec for Opts { consignment, reveal, } => { - let consignment = StateTransfer::strict_file_load(&consignment)?; + let consignment = StateTransfer::strict_file_load(consignment)?; let status = client.consume_transfer(consignment, force, reveal, progress)?; report_validation(status); } diff --git a/rpc/src/client.rs b/rpc/src/client.rs index 0ad0698..634fc45 100644 --- a/rpc/src/client.rs +++ b/rpc/src/client.rs @@ -320,6 +320,6 @@ impl esb::Handler for Handler { fn handle_err(&mut self, _: &mut Bus, err: esb::Error) -> Result<(), Self::Error> { // We simply propagate the error since it already has been reported - Err(err.into()) + Err(err) } } diff --git a/rpc/src/error.rs b/rpc/src/error.rs index 2017f8c..97c7b53 100644 --- a/rpc/src/error.rs +++ b/rpc/src/error.rs @@ -52,6 +52,16 @@ impl Display for FailureCode { impl From for FailureCode { fn from(value: u16) -> Self { match value { + x if x == FailureCode::ChainMismatch as u16 => FailureCode::ChainMismatch, + x if x == FailureCode::Encoding as u16 => FailureCode::Encoding, + x if x == FailureCode::Esb as u16 => FailureCode::Esb, + x if x == FailureCode::Store as u16 => FailureCode::Store, + x if x == FailureCode::Stash as u16 => FailureCode::Stash, + x if x == FailureCode::Absent as u16 => FailureCode::Absent, + x if x == FailureCode::Finalize as u16 => FailureCode::Finalize, + x if x == FailureCode::ElectrumConnectivity as u16 => FailureCode::ElectrumConnectivity, + x if x == FailureCode::UnexpectedRequest as u16 => FailureCode::UnexpectedRequest, + x if x == FailureCode::Launcher as u16 => FailureCode::Launcher, _ => FailureCode::Unknown, } } diff --git a/rpc/src/reveal.rs b/rpc/src/reveal.rs index cafc9d1..63ba25b 100644 --- a/rpc/src/reveal.rs +++ b/rpc/src/reveal.rs @@ -43,7 +43,7 @@ impl ::core::str::FromStr for Reveal { return Err(ParseRevealError::TooLong); } let find_method = s.find('@'); - if find_method == None { + if find_method.is_none() { return Err(ParseRevealError::Format); } @@ -53,7 +53,7 @@ impl ::core::str::FromStr for Reveal { } let find_blind = s.find('#'); - if find_blind == None { + if find_blind.is_none() { return Err(ParseRevealError::Format); } diff --git a/src/bucketd/processor.rs b/src/bucketd/processor.rs index 752ea59..1275192 100644 --- a/src/bucketd/processor.rs +++ b/src/bucketd/processor.rs @@ -157,7 +157,7 @@ impl Runtime { let chunk = self .store .retrieve_chunk(storm_rpc::DB_TABLE_CHUNKS, chunk_id)? - .expect(&format!("Chunk {} is absent", chunk_id)); + .unwrap_or_else(|| panic!("Chunk {} is absent", chunk_id)); writer.write_all(chunk.as_slice()).expect("memory writers do not error"); } @@ -227,7 +227,7 @@ impl Runtime { method: close_method, blinding: blinding_factor, txid: Some(outpoint.txid), - vout: outpoint.vout as u32, + vout: outpoint.vout, }; let concealed_seals = consignment @@ -289,7 +289,7 @@ impl Runtime { method: close_method, blinding: blinding_factor, txid: Some(outpoint.txid), - vout: outpoint.vout as u32, + vout: outpoint.vout, }; let mut owned_rights: BTreeMap = bmap! {}; @@ -400,7 +400,7 @@ impl Runtime { debug!("Processing state extension {}", node_id); trace!("State transition: {:?}", extension); - state.add_extension(&extension); + state.add_extension(extension); trace!("Contract state now is {:?}", state); self.store.store_sten(db::NODE_CONTRACTS, node_id, &contract_id)?; @@ -425,7 +425,7 @@ impl Runtime { .retrieve_sten(db::DISCLOSURES, txid)? .ok_or(StashError::DisclosureAbsent(txid))?; - for (_anchor_id, (anchor, bundle_map)) in disclosure.anchored_bundles() { + for (anchor, bundle_map) in disclosure.anchored_bundles().values() { for (contract_id, bundle) in bundle_map { let mut state: ContractState = self .store diff --git a/src/bucketd/service.rs b/src/bucketd/service.rs index 4498153..94d304e 100644 --- a/src/bucketd/service.rs +++ b/src/bucketd/service.rs @@ -154,12 +154,8 @@ impl Runtime { _client_id: ClientId, message: RpcMsg, ) -> Result<(), DaemonError> { - match message { - wrong_msg => { - error!("Request is not supported by the RPC interface"); - return Err(DaemonError::wrong_esb_msg(ServiceBus::Rpc, &wrong_msg)); - } - } + error!("Request is not supported by the RPC interface"); + Err(DaemonError::wrong_esb_msg(ServiceBus::Rpc, &message)) } fn handle_ctl( diff --git a/src/db.rs b/src/db.rs index 65fda38..b1200ca 100644 --- a/src/db.rs +++ b/src/db.rs @@ -8,27 +8,27 @@ // You should have received a copy of the MIT License along with this software. // If not, see . -pub const SCHEMATA: &'static str = "schemata"; -pub const CONTRACTS: &'static str = "contracts"; -pub const BUNDLES: &'static str = "bundles"; -pub const GENESIS: &'static str = "genesis"; -pub const TRANSITIONS: &'static str = "transitions"; -pub const ANCHORS: &'static str = "anchors"; -pub const EXTENSIONS: &'static str = "extensions"; -pub const ALU_LIBS: &'static str = "alu"; - -pub const OUTPOINTS: &'static str = "outpoints"; -pub const NODE_CONTRACTS: &'static str = "node_contracts"; -pub const TRANSITION_WITNESS: &'static str = "transition_txid"; -pub const CONTRACT_TRANSITIONS: &'static str = "contract_transitions"; - -pub const DISCLOSURES: &'static str = "disclosures"; +pub const SCHEMATA: &str = "schemata"; +pub const CONTRACTS: &str = "contracts"; +pub const BUNDLES: &str = "bundles"; +pub const GENESIS: &str = "genesis"; +pub const TRANSITIONS: &str = "transitions"; +pub const ANCHORS: &str = "anchors"; +pub const EXTENSIONS: &str = "extensions"; +pub const ALU_LIBS: &str = "alu"; + +pub const OUTPOINTS: &str = "outpoints"; +pub const NODE_CONTRACTS: &str = "node_contracts"; +pub const TRANSITION_WITNESS: &str = "transition_txid"; +pub const CONTRACT_TRANSITIONS: &str = "contract_transitions"; + +pub const DISCLOSURES: &str = "disclosures"; // Storm intgration -pub const ATTACHMENT_CHUNKS: &'static str = "chunks"; -pub const ATTACHMENT_INDEX: &'static str = "attachments"; -pub const ATTACHMENT_CONTAINER_HEADERS: &'static str = "container_headers"; -pub const ATTACHMENT_CONTAINERS: &'static str = "containers"; +pub const ATTACHMENT_CHUNKS: &str = "chunks"; +pub const ATTACHMENT_INDEX: &str = "attachments"; +pub const ATTACHMENT_CONTAINER_HEADERS: &str = "container_headers"; +pub const ATTACHMENT_CONTAINERS: &str = "containers"; pub(crate) trait StoreRpcExt { fn retrieve_sten( diff --git a/src/lib.rs b/src/lib.rs index be7a32c..b74f69a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ dead_code, //missing_docs )] +#![allow(clippy::result_large_err)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] #[macro_use]