/// 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<u8>),
/// 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
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
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) => {
}
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),
}
}
}
}
}
-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);