From 376621abdfc15e7ee00286338c932298a980517c Mon Sep 17 00:00:00 2001 From: pythcoiner Date: Mon, 18 Nov 2024 07:26:33 +0100 Subject: [PATCH] clippyfy --- .github/workflows/main.yml | 2 +- liana-gui/src/app/state/settings/bitcoind.rs | 11 ++++---- liana-gui/src/app/view/hw.rs | 26 +++++++++---------- liana-gui/src/daemon/client/jsonrpc.rs | 11 ++++++-- liana-gui/src/installer/step/node/bitcoind.rs | 11 ++++---- liana-gui/src/installer/view/mod.rs | 16 ++++++------ liana-gui/src/lianalite/client/auth.rs | 6 ++--- liana-gui/src/lianalite/client/backend/mod.rs | 2 +- liana-gui/src/main.rs | 3 ++- liana/src/commands/mod.rs | 8 +++--- liana/src/database/sqlite/schema.rs | 1 + liana/src/descriptors/mod.rs | 6 ++--- liana/src/spend.rs | 26 +++++++++---------- 13 files changed, 70 insertions(+), 59 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8bcf4d75..7c600cc1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.78.0 + toolchain: 1.82.0 components: rustfmt, clippy override: true - name: rustfmt diff --git a/liana-gui/src/app/state/settings/bitcoind.rs b/liana-gui/src/app/state/settings/bitcoind.rs index 424f1912..52c59e25 100644 --- a/liana-gui/src/app/state/settings/bitcoind.rs +++ b/liana-gui/src/app/state/settings/bitcoind.rs @@ -336,11 +336,12 @@ impl BitcoindSettings { let rpc_auth = match self.selected_auth_type { RpcAuthType::CookieFile => { let new_path = PathBuf::from_str(&self.rpc_auth_vals.cookie_path.value); - if let Ok(path) = new_path { - self.rpc_auth_vals.cookie_path.valid = true; - Some(BitcoindRpcAuth::CookieFile(path)) - } else { - None + match new_path { + Ok(path) => { + self.rpc_auth_vals.cookie_path.valid = true; + Some(BitcoindRpcAuth::CookieFile(path)) + } + Err(_) => None, } } RpcAuthType::UserPass => Some(BitcoindRpcAuth::UserPass( diff --git a/liana-gui/src/app/view/hw.rs b/liana-gui/src/app/view/hw.rs index eb843eba..4c15ef5f 100644 --- a/liana-gui/src/app/view/hw.rs +++ b/liana-gui/src/app/view/hw.rs @@ -51,19 +51,19 @@ pub fn hw_list_view( .. } => match reason { UnsupportedReason::NotPartOfWallet(fg) => { - hw::unrelated_hardware_wallet(&kind.to_string(), version.as_ref(), fg) + hw::unrelated_hardware_wallet(kind.to_string(), version.as_ref(), fg) } UnsupportedReason::WrongNetwork => { - hw::wrong_network_hardware_wallet(&kind.to_string(), version.as_ref()) + hw::wrong_network_hardware_wallet(kind.to_string(), version.as_ref()) } UnsupportedReason::Version { minimal_supported_version, } => hw::unsupported_version_hardware_wallet( - &kind.to_string(), + kind.to_string(), version.as_ref(), minimal_supported_version, ), - _ => hw::unsupported_hardware_wallet(&kind.to_string(), version.as_ref()), + _ => hw::unsupported_hardware_wallet(kind.to_string(), version.as_ref()), }, HardwareWallet::Locked { kind, pairing_code, .. @@ -119,19 +119,19 @@ pub fn hw_list_view_for_registration( .. } => match reason { UnsupportedReason::NotPartOfWallet(fg) => { - hw::unrelated_hardware_wallet(&kind.to_string(), version.as_ref(), fg) + hw::unrelated_hardware_wallet(kind.to_string(), version.as_ref(), fg) } UnsupportedReason::WrongNetwork => { - hw::wrong_network_hardware_wallet(&kind.to_string(), version.as_ref()) + hw::wrong_network_hardware_wallet(kind.to_string(), version.as_ref()) } UnsupportedReason::Version { minimal_supported_version, } => hw::unsupported_version_hardware_wallet( - &kind.to_string(), + kind.to_string(), version.as_ref(), minimal_supported_version, ), - _ => hw::unsupported_hardware_wallet(&kind.to_string(), version.as_ref()), + _ => hw::unsupported_hardware_wallet(kind.to_string(), version.as_ref()), }, HardwareWallet::Locked { kind, pairing_code, .. @@ -175,7 +175,7 @@ pub fn hw_list_view_verify_address( match kind { DeviceKind::Specter | DeviceKind::SpecterSimulator => { (hw::unimplemented_method_hardware_wallet( - &kind.to_string(), + kind.to_string(), version.as_ref(), fingerprint, "Liana cannot request the device to display the address. \n The verification must be done manually with the device control." @@ -198,19 +198,19 @@ pub fn hw_list_view_verify_address( } => ( match reason { UnsupportedReason::NotPartOfWallet(fg) => { - hw::unrelated_hardware_wallet(&kind.to_string(), version.as_ref(), fg) + hw::unrelated_hardware_wallet(kind.to_string(), version.as_ref(), fg) } UnsupportedReason::WrongNetwork => { - hw::wrong_network_hardware_wallet(&kind.to_string(), version.as_ref()) + hw::wrong_network_hardware_wallet(kind.to_string(), version.as_ref()) } UnsupportedReason::Version { minimal_supported_version, } => hw::unsupported_version_hardware_wallet( - &kind.to_string(), + kind.to_string(), version.as_ref(), minimal_supported_version, ), - _ => hw::unsupported_hardware_wallet(&kind.to_string(), version.as_ref()), + _ => hw::unsupported_hardware_wallet(kind.to_string(), version.as_ref()), }, false, ), diff --git a/liana-gui/src/daemon/client/jsonrpc.rs b/liana-gui/src/daemon/client/jsonrpc.rs index 3eeb12dd..1bc99681 100644 --- a/liana-gui/src/daemon/client/jsonrpc.rs +++ b/liana-gui/src/daemon/client/jsonrpc.rs @@ -22,6 +22,8 @@ use std::os::unix::net::UnixStream; use std::fmt::Debug; + +#[cfg(not(windows))] use std::io::Write; use std::path::{Path, PathBuf}; use std::time::Duration; @@ -29,13 +31,17 @@ use std::{error, fmt, io}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; + +#[cfg(not(windows))] use serde_json::Deserializer; +#[cfg(not(windows))] use tracing::debug; /// A handle to a remote JSONRPC server #[derive(Debug, Clone)] pub struct JsonRPCClient { + #[cfg(not(windows))] sockpath: PathBuf, timeout: Option, } @@ -56,6 +62,7 @@ impl JsonRPCClient { /// Creates a new client pub fn new>(sockpath: P) -> JsonRPCClient { JsonRPCClient { + #[cfg(not(windows))] sockpath: sockpath.as_ref().to_path_buf(), timeout: None, } @@ -70,8 +77,8 @@ impl JsonRPCClient { #[cfg(windows)] pub fn send_request( &self, - method: &str, - params: Option, + _method: &str, + _params: Option, ) -> Result, Error> { Err(Error::NotSupported) } diff --git a/liana-gui/src/installer/step/node/bitcoind.rs b/liana-gui/src/installer/step/node/bitcoind.rs index 7255cbcd..16bd32c1 100644 --- a/liana-gui/src/installer/step/node/bitcoind.rs +++ b/liana-gui/src/installer/step/node/bitcoind.rs @@ -452,11 +452,12 @@ impl DefineBitcoind { let addr = std::net::SocketAddr::from_str(&self.address.value); let rpc_auth = match self.selected_auth_type { RpcAuthType::CookieFile => { - if let Ok(path) = PathBuf::from_str(&self.rpc_auth_vals.cookie_path.value) { - Some(BitcoindRpcAuth::CookieFile(path)) - } else { - self.rpc_auth_vals.cookie_path.valid = false; - None + match PathBuf::from_str(&self.rpc_auth_vals.cookie_path.value) { + Ok(path) => Some(BitcoindRpcAuth::CookieFile(path)), + Err(_) => { + self.rpc_auth_vals.cookie_path.valid = false; + None + } } } RpcAuthType::UserPass => Some(BitcoindRpcAuth::UserPass( diff --git a/liana-gui/src/installer/view/mod.rs b/liana-gui/src/installer/view/mod.rs index e2087cc5..acd3b7d7 100644 --- a/liana-gui/src/installer/view/mod.rs +++ b/liana-gui/src/installer/view/mod.rs @@ -430,19 +430,19 @@ pub fn hardware_wallet_xpubs<'a>( .. } => match reason { UnsupportedReason::NotPartOfWallet(fg) => { - hw::unrelated_hardware_wallet(&kind.to_string(), version.as_ref(), fg) + hw::unrelated_hardware_wallet(kind.to_string(), version.as_ref(), fg) } UnsupportedReason::WrongNetwork => { - hw::wrong_network_hardware_wallet(&kind.to_string(), version.as_ref()) + hw::wrong_network_hardware_wallet(kind.to_string(), version.as_ref()) } UnsupportedReason::Version { minimal_supported_version, } => hw::unsupported_version_hardware_wallet( - &kind.to_string(), + kind.to_string(), version.as_ref(), minimal_supported_version, ), - _ => hw::unsupported_hardware_wallet(&kind.to_string(), version.as_ref()), + _ => hw::unsupported_hardware_wallet(kind.to_string(), version.as_ref()), }, HardwareWallet::Locked { kind, pairing_code, .. @@ -1596,19 +1596,19 @@ pub fn hw_list_view( .. } => match reason { UnsupportedReason::NotPartOfWallet(fg) => { - hw::unrelated_hardware_wallet(&kind.to_string(), version.as_ref(), fg) + hw::unrelated_hardware_wallet(kind.to_string(), version.as_ref(), fg) } UnsupportedReason::WrongNetwork => { - hw::wrong_network_hardware_wallet(&kind.to_string(), version.as_ref()) + hw::wrong_network_hardware_wallet(kind.to_string(), version.as_ref()) } UnsupportedReason::Version { minimal_supported_version, } => hw::unsupported_version_hardware_wallet( - &kind.to_string(), + kind.to_string(), version.as_ref(), minimal_supported_version, ), - _ => hw::unsupported_hardware_wallet(&kind.to_string(), version.as_ref()), + _ => hw::unsupported_hardware_wallet(kind.to_string(), version.as_ref()), }, HardwareWallet::Locked { kind, pairing_code, .. diff --git a/liana-gui/src/lianalite/client/auth.rs b/liana-gui/src/lianalite/client/auth.rs index af7ef714..8a50561d 100644 --- a/liana-gui/src/lianalite/client/auth.rs +++ b/liana-gui/src/lianalite/client/auth.rs @@ -94,7 +94,7 @@ impl AuthClient { let response: Response = self .request( Method::POST, - &format!( + format!( "{}/auth/v1/otp?redirect_to=https://desktop.lianalite.com", self.url ), @@ -128,7 +128,7 @@ impl AuthClient { pub async fn verify_otp(&self, token: &str) -> Result { let response: Response = self .http - .post(&format!("{}/auth/v1/verify", self.url)) + .post(format!("{}/auth/v1/verify", self.url)) .header("apikey", &self.api_public_key) .header("Content-Type", "application/json") .json(&VerifyOtp { @@ -154,7 +154,7 @@ impl AuthClient { ) -> Result { let response: Response = self .http - .post(&format!( + .post(format!( "{}/auth/v1/token?grant_type=refresh_token", self.url )) diff --git a/liana-gui/src/lianalite/client/backend/mod.rs b/liana-gui/src/lianalite/client/backend/mod.rs index 957871cc..8d4b33fc 100644 --- a/liana-gui/src/lianalite/client/backend/mod.rs +++ b/liana-gui/src/lianalite/client/backend/mod.rs @@ -77,7 +77,7 @@ impl BackendClient { let response = request( &http, Method::GET, - &format!("{}/v1/me", url), + format!("{}/v1/me", url), &credentials.access_token, ) .send() diff --git a/liana-gui/src/main.rs b/liana-gui/src/main.rs index 57c0a120..c753a2c3 100644 --- a/liana-gui/src/main.rs +++ b/liana-gui/src/main.rs @@ -4,11 +4,12 @@ use std::{ collections::HashMap, error::Error, io::Write, path::PathBuf, process, str::FromStr, sync::Arc, }; +#[cfg(target_os = "linux")] +use iced::window::settings::PlatformSpecific; use iced::{ event::{self, Event}, executor, keyboard, widget::{focus_next, focus_previous}, - window::settings::PlatformSpecific, Application, Command, Settings, Size, Subscription, }; use tracing::{error, info}; diff --git a/liana/src/commands/mod.rs b/liana/src/commands/mod.rs index ae17e0ea..70f67422 100644 --- a/liana/src/commands/mod.rs +++ b/liana/src/commands/mod.rs @@ -745,11 +745,11 @@ impl DaemonControl { /// transaction will be used in the replacement. /// In both cases: /// - if the previous transaction includes a change output to one of our own change addresses, - /// this same address will be used for change in the RBF transaction, if required. If the previous - /// transaction pays to more than one of our change addresses, then the one receiving the highest - /// value will be used as a change address and the others will be treated as non-change outputs. + /// this same address will be used for change in the RBF transaction, if required. If the previous + /// transaction pays to more than one of our change addresses, then the one receiving the highest + /// value will be used as a change address and the others will be treated as non-change outputs. /// - the RBF transaction may include additional confirmed coins as inputs if required - /// in order to pay the higher fee (this applies also when replacing a self-send). + /// in order to pay the higher fee (this applies also when replacing a self-send). /// /// `feerate_vb` is the target feerate for the RBF transaction (in sat/vb). If `None`, it will be set /// to 1 sat/vb larger than the feerate of the previous transaction, which is the minimum value allowed diff --git a/liana/src/database/sqlite/schema.rs b/liana/src/database/sqlite/schema.rs index 7a61e307..57d01a0c 100644 --- a/liana/src/database/sqlite/schema.rs +++ b/liana/src/database/sqlite/schema.rs @@ -135,6 +135,7 @@ impl TryFrom<&rusqlite::Row<'_>> for DbTip { /// A row in the "wallets" table. #[derive(Clone, Debug)] pub struct DbWallet { + #[allow(dead_code)] pub id: i64, pub timestamp: u32, pub main_descriptor: LianaDescriptor, diff --git a/liana/src/descriptors/mod.rs b/liana/src/descriptors/mod.rs index 2456f32e..0f2b2aa0 100644 --- a/liana/src/descriptors/mod.rs +++ b/liana/src/descriptors/mod.rs @@ -400,7 +400,7 @@ impl LianaDescriptor { /// This analysis assumes that: /// - The PSBT only contains input that spends Liana coins. Otherwise the analysis will be off. /// - The PSBT is consistent across inputs (the sequence is the same across inputs, the - /// signatures are either absent or present for all inputs, ..) + /// signatures are either absent or present for all inputs, ..) /// - The provided signatures are valid for this script. pub fn partial_spend_info(&self, psbt: &Psbt) -> Result { // Check the PSBT isn't empty or malformed. @@ -524,9 +524,9 @@ impl LianaDescriptor { /// Prune the BIP32 derivations in all the PSBT inputs for all the spending paths but the /// latest available one. For instance: /// - If there is two recovery paths, and the PSBT's first input nSequence isn't set to unlock - /// any of them, prune all but the primary path's bip32 derivations. + /// any of them, prune all but the primary path's bip32 derivations. /// - If there is two recovery paths, and the PSBT's first input nSequence is set to unlock the - /// first one, prune all but the first recovery path's bip32 derivations. + /// first one, prune all but the first recovery path's bip32 derivations. /// - Etc.. pub fn prune_bip32_derivs_last_avail(&self, psbt: Psbt) -> Result { let spend_info = self.partial_spend_info(&psbt)?; diff --git a/liana/src/spend.rs b/liana/src/spend.rs index 9465b775..5a907ae5 100644 --- a/liana/src/spend.rs +++ b/liana/src/spend.rs @@ -416,7 +416,7 @@ fn select_coins_for_spend( i if i >= 100 => 10_000, _ => 100_000, }; - #[cfg(debug)] + #[cfg(debug_assertions)] let bnb_rounds = bnb_rounds / 1_000; if let Err(e) = selector.run_bnb(lowest_fee_change_cond, bnb_rounds) { log::debug!( @@ -508,9 +508,9 @@ fn derived_desc( /// /// The approach follows that taken by Bitcoin Core: /// - most of the time, the value returned will be the current -/// block height, but will randomly be up to 100 blocks earlier. +/// block height, but will randomly be up to 100 blocks earlier. /// - if the current tip is more than [`MAX_ANTI_FEE_SNIPING_TIP_AGE_SECS`] -/// seconds old, a locktime value of 0 will be returned. +/// seconds old, a locktime value of 0 will be returned. pub fn anti_fee_sniping_locktime( now: Duration, tip_height: u32, @@ -613,22 +613,22 @@ pub struct CreateSpendRes { /// /// More about the parameters: /// * `main_descriptor`: the multipath Liana descriptor, used to derive the addresses of the -/// candidate coins. +/// candidate coins. /// * `secp`: necessary to derive data from the descriptor. /// * `tx_getter`: an interface to get the wallet transaction for the prevouts of the transaction. -/// Wouldn't be necessary if we only spent Taproot coins. +/// Wouldn't be necessary if we only spent Taproot coins. /// * `destinations`: a list of addresses and amounts, one per recipient i.e. per output in the -/// transaction created. If empty all the `candidate_coins` get spent and a single change output -/// is created to the provided `change_addr`. Can be used to sweep all, or some, coins from the -/// wallet. +/// transaction created. If empty all the `candidate_coins` get spent and a single change output +/// is created to the provided `change_addr`. Can be used to sweep all, or some, coins from the +/// wallet. /// * `candidate_coins`: a list of coins to consider including as input of the transaction. If -/// `destinations` is empty, they will all be included as inputs of the transaction. Otherwise, a -/// coin selection algorithm will be run to spend the most efficient subset of them to meet the -/// `destinations` requirements. +/// `destinations` is empty, they will all be included as inputs of the transaction. Otherwise, a +/// coin selection algorithm will be run to spend the most efficient subset of them to meet the +/// `destinations` requirements. /// * `fees`: the target feerate (in sats/vb) and, if necessary, minimum absolute fee for this tx. /// * `change_addr`: the address to use for a change output if we need to create one. Can be set to -/// an external address (if combined with an empty list of `destinations` it's useful to sweep some -/// or all coins of a wallet to an external address). +/// an external address (if combined with an empty list of `destinations` it's useful to sweep some +/// or all coins of a wallet to an external address). /// * `locktime`: the locktime to use for the transaction. #[allow(clippy::too_many_arguments)] pub fn create_spend(