From 22bec6d363bb3349e26f56243bef9e72277a6790 Mon Sep 17 00:00:00 2001 From: LLFourn Date: Tue, 21 Feb 2023 16:50:24 +1100 Subject: [PATCH] Delete unused errors --- crates/bdk/src/error.rs | 92 ------------------------------------ crates/bdk/src/wallet/mod.rs | 9 ---- 2 files changed, 101 deletions(-) diff --git a/crates/bdk/src/error.rs b/crates/bdk/src/error.rs index 8cb349a5..fcbb8288 100644 --- a/crates/bdk/src/error.rs +++ b/crates/bdk/src/error.rs @@ -18,12 +18,8 @@ use core::fmt; /// Errors that can be thrown by the [`Wallet`](crate::wallet::Wallet) #[derive(Debug)] pub enum Error { - /// Wrong number of bytes found when trying to convert to u32 - InvalidU32Bytes(Vec), /// Generic error Generic(String), - /// This error is thrown when trying to convert Bare and Public key script to address - ScriptDoesntHaveAddressForm, /// Cannot build a tx without recipients NoRecipients, /// `manually_selected_only` option is selected but no utxo has been passed @@ -79,52 +75,18 @@ pub enum Error { InvalidPolicyPathError(crate::descriptor::policy::PolicyError), /// Signing error Signer(crate::wallet::signer::SignerError), - /// Invalid network - InvalidNetwork { - /// requested network, for example what is given as bdk-cli option - requested: Network, - /// found network, for example the network of the bitcoin node - found: Network, - }, - - /// Progress value must be between `0.0` (included) and `100.0` (included) - InvalidProgressValue(f32), - /// Progress update error (maybe the channel has been closed) - ProgressUpdateError, /// Requested outpoint doesn't exist in the tx (vout greater than available outputs) InvalidOutpoint(OutPoint), - /// Error related to the parsing and usage of descriptors Descriptor(crate::descriptor::error::Error), - /// Encoding error - Encode(bitcoin::consensus::encode::Error), /// Miniscript error Miniscript(miniscript::Error), /// Miniscript PSBT error MiniscriptPsbt(MiniscriptPsbtError), /// BIP32 error Bip32(bitcoin::util::bip32::Error), - /// A secp256k1 error - Secp256k1(bitcoin::secp256k1::Error), - /// Error serializing or deserializing JSON data - Json(serde_json::Error), - /// Hex decoding error - Hex(bitcoin::hashes::hex::Error), /// Partially signed bitcoin transaction error Psbt(bitcoin::util::psbt::Error), - /// Partially signed bitcoin transaction parse error - PsbtParse(bitcoin::util::psbt::PsbtParseError), - - //KeyMismatch(bitcoin::secp256k1::PublicKey, bitcoin::secp256k1::PublicKey), - //MissingInputUTXO(usize), - //InvalidAddressNetwork(Address), - //DifferentTransactions, - //DifferentDescriptorStructure, - //Uncapable(crate::blockchain::Capability), - //MissingCachedAddresses, - /// [`crate::blockchain::WalletSync`] sync attempt failed due to missing scripts in cache which - /// are needed to satisfy `stop_gap`. - MissingCachedScripts(MissingCachedScripts), } /// Errors returned by miniscript when updating inconsistent PSBTs @@ -147,25 +109,10 @@ impl fmt::Display for MiniscriptPsbtError { impl std::error::Error for MiniscriptPsbtError {} -/// Represents the last failed [`crate::blockchain::WalletSync`] sync attempt in which we were short -/// on cached `scriptPubKey`s. -#[derive(Debug)] -pub struct MissingCachedScripts { - /// Number of scripts in which txs were requested during last request. - pub last_count: usize, - /// Minimum number of scripts to cache more of in order to satisfy `stop_gap`. - pub missing_count: usize, -} - impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::InvalidU32Bytes(_) => write!( - f, - "Wrong number of bytes found when trying to convert to u32" - ), Self::Generic(err) => write!(f, "Generic error: {}", err), - Self::ScriptDoesntHaveAddressForm => write!(f, "Script doesn't have address form"), Self::NoRecipients => write!(f, "Cannot build tx without recipients"), Self::NoUtxosSelected => write!(f, "No UTXO selected"), Self::OutputBelowDustLimit(limit) => { @@ -201,50 +148,16 @@ impl fmt::Display for Error { } Self::InvalidPolicyPathError(err) => write!(f, "Invalid policy path: {}", err), Self::Signer(err) => write!(f, "Signer error: {}", err), - Self::InvalidNetwork { requested, found } => write!( - f, - "Invalid network: requested {} but found {}", - requested, found - ), - #[cfg(feature = "verify")] - Self::Verification(err) => write!(f, "Transaction verification error: {}", err), - Self::InvalidProgressValue(progress) => { - write!(f, "Invalid progress value: {}", progress) - } - Self::ProgressUpdateError => write!( - f, - "Progress update error (maybe the channel has been closed)" - ), Self::InvalidOutpoint(outpoint) => write!( f, "Requested outpoint doesn't exist in the tx: {}", outpoint ), Self::Descriptor(err) => write!(f, "Descriptor error: {}", err), - Self::Encode(err) => write!(f, "Encoding error: {}", err), Self::Miniscript(err) => write!(f, "Miniscript error: {}", err), Self::MiniscriptPsbt(err) => write!(f, "Miniscript PSBT error: {}", err), Self::Bip32(err) => write!(f, "BIP32 error: {}", err), - Self::Secp256k1(err) => write!(f, "Secp256k1 error: {}", err), - Self::Json(err) => write!(f, "Serialize/Deserialize JSON error: {}", err), - Self::Hex(err) => write!(f, "Hex decoding error: {}", err), Self::Psbt(err) => write!(f, "PSBT error: {}", err), - Self::PsbtParse(err) => write!(f, "Impossible to parse PSBT: {}", err), - Self::MissingCachedScripts(missing_cached_scripts) => { - write!(f, "Missing cached scripts: {:?}", missing_cached_scripts) - } - #[cfg(feature = "electrum")] - Self::Electrum(err) => write!(f, "Electrum client error: {}", err), - #[cfg(feature = "esplora")] - Self::Esplora(err) => write!(f, "Esplora client error: {}", err), - #[cfg(feature = "compact_filters")] - Self::CompactFilters(err) => write!(f, "Compact filters client error: {}", err), - #[cfg(feature = "key-value-db")] - Self::Sled(err) => write!(f, "Sled database error: {}", err), - #[cfg(feature = "rpc")] - Self::Rpc(err) => write!(f, "RPC client error: {}", err), - #[cfg(feature = "sqlite")] - Self::Rusqlite(err) => write!(f, "SQLite error: {}", err), } } } @@ -280,12 +193,7 @@ impl From for Error { } } -impl_error!(bitcoin::consensus::encode::Error, Encode); impl_error!(miniscript::Error, Miniscript); impl_error!(MiniscriptPsbtError, MiniscriptPsbt); impl_error!(bitcoin::util::bip32::Error, Bip32); -impl_error!(bitcoin::secp256k1::Error, Secp256k1); -impl_error!(serde_json::Error, Json); -impl_error!(bitcoin::hashes::hex::Error, Hex); impl_error!(bitcoin::util::psbt::Error, Psbt); -impl_error!(bitcoin::util::psbt::PsbtParseError, PsbtParse); diff --git a/crates/bdk/src/wallet/mod.rs b/crates/bdk/src/wallet/mod.rs index d4dd571f..862a5d68 100644 --- a/crates/bdk/src/wallet/mod.rs +++ b/crates/bdk/src/wallet/mod.rs @@ -336,9 +336,6 @@ impl Wallet { } /// Return the list of unspent outputs of this wallet - /// - /// Note that this method only operates on the internal database, which first needs to be - /// [`Wallet::sync`] manually. pub fn list_unspent(&self) -> Vec { self.keychain_tracker .full_utxos() @@ -416,9 +413,6 @@ impl Wallet { /// /// Optionally fill the [`TransactionDetails::transaction`] field with the raw transaction if /// `include_raw` is `true`. - /// - /// Note that this method only operates on the internal database, which first needs to be - /// [`Wallet::sync`] manually. pub fn get_tx(&self, txid: Txid, include_raw: bool) -> Option { let (&confirmation_time, tx) = self.keychain_tracker.chain_graph().get_tx_in_chain(txid)?; let graph = self.keychain_tracker.graph(); @@ -535,9 +529,6 @@ impl Wallet { /// Return the balance, separated into available, trusted-pending, untrusted-pending and immature /// values. - /// - /// Note that this method only operates on the internal database, which first needs to be - /// [`Wallet::sync`] manually. pub fn get_balance(&self) -> Balance { self.keychain_tracker.balance(|keychain| match keychain { KeychainKind::External => false,