From 54beb23f13fca04867e024bcfbacde4b3af70395 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Wed, 10 Jan 2024 14:10:25 -0500 Subject: [PATCH] fix: fix clippy warnings --- bdk-ffi/Cargo.lock | 1 - bdk-ffi/Cargo.toml | 1 - bdk-ffi/src/bitcoin.rs | 12 ++++++------ bdk-ffi/src/descriptor.rs | 10 +++------- bdk-ffi/src/error.rs | 24 ++++++++---------------- bdk-ffi/src/esplora.rs | 10 +++------- bdk-ffi/src/keys.rs | 14 +++++++------- bdk-ffi/src/lib.rs | 2 +- bdk-ffi/src/wallet.rs | 14 ++++++-------- 9 files changed, 34 insertions(+), 54 deletions(-) diff --git a/bdk-ffi/Cargo.lock b/bdk-ffi/Cargo.lock index eb9f746..e8df64f 100644 --- a/bdk-ffi/Cargo.lock +++ b/bdk-ffi/Cargo.lock @@ -163,7 +163,6 @@ dependencies = [ "assert_matches", "bdk", "bdk_esplora", - "thiserror", "uniffi", ] diff --git a/bdk-ffi/Cargo.toml b/bdk-ffi/Cargo.toml index 9958140..d2afa2b 100644 --- a/bdk-ffi/Cargo.toml +++ b/bdk-ffi/Cargo.toml @@ -30,7 +30,6 @@ bdk = { version = "1.0.0-alpha.3", features = ["all-keys", "keys-bip39"] } bdk_esplora = { version = "0.5.0", default-features = false, features = ["std", "blocking"] } uniffi = { version = "=0.25.1" } -thiserror = "1.0.50" [build-dependencies] uniffi = { version = "=0.25.1", features = ["build"] } diff --git a/bdk-ffi/src/bitcoin.rs b/bdk-ffi/src/bitcoin.rs index 8f250d6..af6528e 100644 --- a/bdk-ffi/src/bitcoin.rs +++ b/bdk-ffi/src/bitcoin.rs @@ -9,10 +9,10 @@ use bdk::bitcoin::OutPoint as BdkOutPoint; use bdk::bitcoin::Transaction as BdkTransaction; use bdk::bitcoin::Txid; +use crate::error::Alpha3Error; use std::io::Cursor; use std::str::FromStr; use std::sync::{Arc, Mutex}; -use crate::error::Alpha3Error; #[derive(Clone, Debug, PartialEq, Eq)] pub struct Script(pub(crate) BdkScriptBuf); @@ -74,11 +74,11 @@ impl Address { pub fn new(address: String, network: Network) -> Result { let parsed_address = address .parse::>() - .map_err(|e| Alpha3Error::Generic)?; + .map_err(|_| Alpha3Error::Generic)?; let network_checked_address = parsed_address .require_network(network.into()) - .map_err(|e| Alpha3Error::Generic)?; + .map_err(|_| Alpha3Error::Generic)?; Ok(Address { inner: network_checked_address, @@ -153,8 +153,8 @@ pub struct Transaction { impl Transaction { pub fn new(transaction_bytes: Vec) -> Result { let mut decoder = Cursor::new(transaction_bytes); - let tx: BdkTransaction = BdkTransaction::consensus_decode(&mut decoder) - .map_err(|e| Alpha3Error::Generic)?; + let tx: BdkTransaction = + BdkTransaction::consensus_decode(&mut decoder).map_err(|_| Alpha3Error::Generic)?; Ok(Transaction { inner: tx }) } @@ -233,7 +233,7 @@ impl PartiallySignedTransaction { pub(crate) fn new(psbt_base64: String) -> Result { let psbt: BdkPartiallySignedTransaction = BdkPartiallySignedTransaction::from_str(&psbt_base64) - .map_err(|e| Alpha3Error::Generic)?; + .map_err(|_| Alpha3Error::Generic)?; Ok(PartiallySignedTransaction { inner: Mutex::new(psbt), diff --git a/bdk-ffi/src/descriptor.rs b/bdk-ffi/src/descriptor.rs index aa020f0..5274116 100644 --- a/bdk-ffi/src/descriptor.rs +++ b/bdk-ffi/src/descriptor.rs @@ -1,7 +1,7 @@ +use crate::error::Alpha3Error; use crate::keys::DescriptorPublicKey; use crate::keys::DescriptorSecretKey; use crate::Network; -use crate::error::Alpha3Error; use bdk::bitcoin::bip32::Fingerprint; use bdk::bitcoin::key::Secp256k1; @@ -281,8 +281,7 @@ mod test { use crate::*; use assert_matches::assert_matches; - use bdk::descriptor::DescriptorError::Key; - use bdk::keys::KeyError::InvalidNetwork; + use crate::Alpha3Error; fn get_descriptor_secret_key() -> DescriptorSecretKey { let mnemonic = Mnemonic::from_string("chaos fabric time speed sponsor all flat solution wisdom trophy crack object robot pave observe combine where aware bench orient secret primary cable detect".to_string()).unwrap(); @@ -400,9 +399,6 @@ mod test { let descriptor2 = Descriptor::new("wpkh(tprv8hwWMmPE4BVNxGdVt3HhEERZhondQvodUY7Ajyseyhudr4WabJqWKWLr4Wi2r26CDaNCQhhxEftEaNzz7dPGhWuKFU4VULesmhEfZYyBXdE/0/*)".to_string(), Network::Bitcoin); // Creating a Descriptor using an extended key that doesn't match the network provided will throw and InvalidNetwork Error assert!(descriptor1.is_ok()); - assert_matches!( - descriptor2.unwrap_err(), - bdk::Error::Descriptor(Key(InvalidNetwork)) - ) + assert_matches!(descriptor2.unwrap_err(), Alpha3Error::Generic) } } diff --git a/bdk-ffi/src/error.rs b/bdk-ffi/src/error.rs index 928f76d..d19fceb 100644 --- a/bdk-ffi/src/error.rs +++ b/bdk-ffi/src/error.rs @@ -7,20 +7,24 @@ use std::fmt; use bdk::descriptor::DescriptorError; use bdk::wallet::error::{BuildFeeBumpError, CreateTxError}; use bdk::wallet::tx_builder::{AddUtxoError, AllowShrinkingError}; -use bdk::wallet::{NewError, NewOrLoadError}; +use bdk::wallet::NewError; use std::convert::Infallible; -#[derive(Debug, thiserror::Error)] +#[derive(Debug)] pub enum Alpha3Error { Generic, } impl fmt::Display for Alpha3Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "Error in FFI") + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Alpha3Error::Generic => write!(f, "Error in FFI"), + } } } +impl std::error::Error for Alpha3Error {} + impl From for Alpha3Error { fn from(_: DescriptorError) -> Self { Alpha3Error::Generic @@ -57,24 +61,12 @@ impl From for Alpha3Error { } } -// impl From> for TempFfiError { -// fn from(_: FileError<'_>) -> Self { -// TempFfiError::FfiError -// } -// } - impl From> for Alpha3Error { fn from(_: NewError) -> Self { Alpha3Error::Generic } } -// impl From> for Alpha3Error { -// fn from(_: NewOrLoadError) -> Self { -// Alpha3Error::Alpha3Error -// } -// } - impl From> for Alpha3Error { fn from(_: CreateTxError) -> Self { Alpha3Error::Generic diff --git a/bdk-ffi/src/esplora.rs b/bdk-ffi/src/esplora.rs index d0be950..28ba2a6 100644 --- a/bdk-ffi/src/esplora.rs +++ b/bdk-ffi/src/esplora.rs @@ -1,5 +1,5 @@ -use crate::wallet::{Update, Wallet}; use crate::error::Alpha3Error; +use crate::wallet::{Update, Wallet}; use bdk::bitcoin::Transaction as BdkTransaction; use bdk::wallet::Update as BdkUpdate; @@ -32,11 +32,7 @@ impl EsploraClient { let (update_graph, last_active_indices) = self .0 - .full_scan( - keychain_spks, - stop_gap as usize, - parallel_requests as usize, - ) + .full_scan(keychain_spks, stop_gap as usize, parallel_requests as usize) .unwrap(); let missing_heights = update_graph.missing_heights(wallet.local_chain()); @@ -60,7 +56,7 @@ impl EsploraClient { let bdk_transaction: BdkTransaction = transaction.into(); self.0 .broadcast(&bdk_transaction) - .map_err(|e| Alpha3Error::Generic) + .map_err(|_| Alpha3Error::Generic) } // pub fn estimate_fee(); diff --git a/bdk-ffi/src/keys.rs b/bdk-ffi/src/keys.rs index 1609090..8112d61 100644 --- a/bdk-ffi/src/keys.rs +++ b/bdk-ffi/src/keys.rs @@ -1,5 +1,5 @@ -use crate::Network; use crate::error::Alpha3Error; +use crate::Network; use bdk::bitcoin::bip32::DerivationPath as BdkDerivationPath; use bdk::bitcoin::key::Secp256k1; @@ -38,13 +38,13 @@ impl Mnemonic { pub(crate) fn from_string(mnemonic: String) -> Result { BdkMnemonic::from_str(&mnemonic) .map(|m| Mnemonic { inner: m }) - .map_err(|e| Alpha3Error::Generic) + .map_err(|_| Alpha3Error::Generic) } pub(crate) fn from_entropy(entropy: Vec) -> Result { BdkMnemonic::from_entropy(entropy.as_slice()) .map(|m| Mnemonic { inner: m }) - .map_err(|e| Alpha3Error::Generic) + .map_err(|_| Alpha3Error::Generic) } pub(crate) fn as_string(&self) -> String { @@ -62,7 +62,7 @@ impl DerivationPath { .map(|x| DerivationPath { inner_mutex: Mutex::new(x), }) - .map_err(|e| Alpha3Error::Generic) + .map_err(|_| Alpha3Error::Generic) } } @@ -88,7 +88,7 @@ impl DescriptorSecretKey { pub(crate) fn from_string(private_key: String) -> Result { let descriptor_secret_key = BdkDescriptorSecretKey::from_str(private_key.as_str()) - .map_err(|e| Alpha3Error::Generic)?; + .map_err(|_| Alpha3Error::Generic)?; Ok(Self { inner: descriptor_secret_key, }) @@ -179,7 +179,7 @@ pub struct DescriptorPublicKey { impl DescriptorPublicKey { pub(crate) fn from_string(public_key: String) -> Result { let descriptor_public_key = BdkDescriptorPublicKey::from_str(public_key.as_str()) - .map_err(|e| Alpha3Error::Generic)?; + .map_err(|_| Alpha3Error::Generic)?; Ok(Self { inner: descriptor_public_key, }) @@ -242,9 +242,9 @@ impl DescriptorPublicKey { mod test { use crate::keys::{DerivationPath, DescriptorPublicKey, DescriptorSecretKey, Mnemonic}; // use bdk::bitcoin::hashes::hex::ToHex; + use crate::error::Alpha3Error; use bdk::bitcoin::Network; use std::sync::Arc; - use crate::error::Alpha3Error; fn get_inner() -> DescriptorSecretKey { let mnemonic = Mnemonic::from_string("chaos fabric time speed sponsor all flat solution wisdom trophy crack object robot pave observe combine where aware bench orient secret primary cable detect".to_string()).unwrap(); diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index c68a398..c90f4c8 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -14,6 +14,7 @@ use crate::bitcoin::Script; use crate::bitcoin::Transaction; use crate::bitcoin::TxOut; use crate::descriptor::Descriptor; +use crate::error::Alpha3Error; use crate::error::CalculateFeeError; use crate::esplora::EsploraClient; use crate::keys::DerivationPath; @@ -22,7 +23,6 @@ use crate::keys::DescriptorSecretKey; use crate::keys::Mnemonic; use crate::types::AddressIndex; use crate::types::AddressInfo; -use crate::error::Alpha3Error; use crate::types::Balance; use crate::types::FeeRate; use crate::types::LocalOutput; diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index a3bd2c9..18248d8 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -11,7 +11,7 @@ use bdk::bitcoin::psbt::PartiallySignedTransaction as BdkPartiallySignedTransact use bdk::bitcoin::{OutPoint as BdkOutPoint, Sequence, Txid}; use bdk::wallet::tx_builder::ChangeSpendPolicy; use bdk::wallet::Update as BdkUpdate; -use bdk::{FeeRate as BdkFeeRate}; +use bdk::FeeRate as BdkFeeRate; use bdk::{SignOptions, Wallet as BdkWallet}; use std::collections::HashSet; @@ -68,7 +68,7 @@ impl Wallet { pub fn apply_update(&self, update: Arc) -> Result<(), Alpha3Error> { self.get_wallet() .apply_update(update.0.clone()) - .map_err(|e| Alpha3Error::Generic) + .map_err(|_| Alpha3Error::Generic) } pub fn is_mine(&self, script: &Script) -> bool { @@ -85,7 +85,7 @@ impl Wallet { let mut psbt = psbt.inner.lock().unwrap(); self.get_wallet() .sign(&mut psbt, SignOptions::default()) - .map_err(|e| Alpha3Error::Generic) + .map_err(|_| Alpha3Error::Generic) } pub fn sent_and_received(&self, tx: &Transaction) -> SentAndReceivedValues { @@ -561,8 +561,7 @@ impl BumpFeeTxBuilder { &self, wallet: &Wallet, ) -> Result, Alpha3Error> { - let txid = - Txid::from_str(self.txid.as_str()).map_err(|e| Alpha3Error::Generic)?; + let txid = Txid::from_str(self.txid.as_str()).map_err(|_| Alpha3Error::Generic)?; let mut wallet = wallet.get_wallet(); let mut tx_builder = wallet.build_fee_bump(txid)?; tx_builder.fee_rate(BdkFeeRate::from_sat_per_vb(self.fee_rate)); @@ -579,9 +578,8 @@ impl BumpFeeTxBuilder { } } } - let psbt: BdkPartiallySignedTransaction = tx_builder - .finish() - .map_err(|e| Alpha3Error::Generic)?; + let psbt: BdkPartiallySignedTransaction = + tx_builder.finish().map_err(|_| Alpha3Error::Generic)?; Ok(Arc::new(psbt.into())) }