2020-08-06 13:09:39 +02:00
|
|
|
use bitcoin::{Address, OutPoint, Script, Txid};
|
2020-02-07 23:22:28 +01:00
|
|
|
|
2020-01-27 22:02:55 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
|
|
|
KeyMismatch(bitcoin::secp256k1::PublicKey, bitcoin::secp256k1::PublicKey),
|
|
|
|
MissingInputUTXO(usize),
|
2020-02-05 11:59:02 +01:00
|
|
|
InvalidU32Bytes(Vec<u8>),
|
|
|
|
Generic(String),
|
2020-02-07 23:22:28 +01:00
|
|
|
ScriptDoesntHaveAddressForm,
|
|
|
|
SendAllMultipleOutputs,
|
|
|
|
OutputBelowDustLimit(usize),
|
|
|
|
InsufficientFunds,
|
2020-08-06 13:09:39 +02:00
|
|
|
InvalidAddressNetork(Address),
|
2020-02-07 23:22:28 +01:00
|
|
|
UnknownUTXO,
|
|
|
|
DifferentTransactions,
|
|
|
|
|
2020-02-15 21:27:51 +01:00
|
|
|
ChecksumMismatch,
|
2020-02-17 14:22:53 +01:00
|
|
|
DifferentDescriptorStructure,
|
2020-02-15 21:27:51 +01:00
|
|
|
|
2020-02-07 23:22:28 +01:00
|
|
|
SpendingPolicyRequired,
|
|
|
|
InvalidPolicyPathError(crate::descriptor::policy::PolicyError),
|
|
|
|
|
|
|
|
// Signing errors (expected, received)
|
|
|
|
InputTxidMismatch((Txid, OutPoint)),
|
|
|
|
InputRedeemScriptMismatch((Script, Script)), // scriptPubKey, redeemScript
|
|
|
|
InputWitnessScriptMismatch((Script, Script)), // scriptPubKey, redeemScript
|
|
|
|
InputUnknownSegwitScript(Script),
|
|
|
|
InputMissingWitnessScript(usize),
|
|
|
|
MissingUTXO,
|
|
|
|
|
2020-05-03 16:15:11 +02:00
|
|
|
// Blockchain interface errors
|
|
|
|
Uncapable(crate::blockchain::Capability),
|
2020-05-06 16:50:03 +02:00
|
|
|
OfflineClient,
|
2020-05-03 16:15:11 +02:00
|
|
|
InvalidProgressValue(f32),
|
|
|
|
ProgressUpdateError,
|
|
|
|
MissingCachedAddresses,
|
|
|
|
InvalidOutpoint(OutPoint),
|
|
|
|
|
2020-02-07 23:22:28 +01:00
|
|
|
Descriptor(crate::descriptor::error::Error),
|
2020-01-27 22:02:55 +01:00
|
|
|
|
2020-02-05 11:59:02 +01:00
|
|
|
Encode(bitcoin::consensus::encode::Error),
|
2020-01-27 22:02:55 +01:00
|
|
|
BIP32(bitcoin::util::bip32::Error),
|
|
|
|
Secp256k1(bitcoin::secp256k1::Error),
|
2020-02-05 11:59:02 +01:00
|
|
|
JSON(serde_json::Error),
|
2020-02-07 23:22:28 +01:00
|
|
|
Hex(bitcoin::hashes::hex::Error),
|
|
|
|
PSBT(bitcoin::util::psbt::Error),
|
2020-02-05 11:59:02 +01:00
|
|
|
|
2020-05-07 15:14:05 +02:00
|
|
|
#[cfg(feature = "electrum")]
|
2020-02-07 23:22:28 +01:00
|
|
|
Electrum(electrum_client::Error),
|
2020-05-07 15:14:05 +02:00
|
|
|
#[cfg(feature = "esplora")]
|
|
|
|
Esplora(crate::blockchain::esplora::EsploraError),
|
|
|
|
#[cfg(feature = "key-value-db")]
|
2020-02-05 11:59:02 +01:00
|
|
|
Sled(sled::Error),
|
2020-01-27 22:02:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! impl_error {
|
|
|
|
( $from:ty, $to:ident ) => {
|
|
|
|
impl std::convert::From<$from> for Error {
|
|
|
|
fn from(err: $from) -> Self {
|
|
|
|
Error::$to(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-07 23:22:28 +01:00
|
|
|
impl_error!(crate::descriptor::error::Error, Descriptor);
|
|
|
|
impl_error!(
|
|
|
|
crate::descriptor::policy::PolicyError,
|
|
|
|
InvalidPolicyPathError
|
|
|
|
);
|
|
|
|
|
2020-02-05 11:59:02 +01:00
|
|
|
impl_error!(bitcoin::consensus::encode::Error, Encode);
|
2020-01-27 22:02:55 +01:00
|
|
|
impl_error!(bitcoin::util::bip32::Error, BIP32);
|
|
|
|
impl_error!(bitcoin::secp256k1::Error, Secp256k1);
|
2020-02-05 11:59:02 +01:00
|
|
|
impl_error!(serde_json::Error, JSON);
|
2020-02-07 23:22:28 +01:00
|
|
|
impl_error!(bitcoin::hashes::hex::Error, Hex);
|
|
|
|
impl_error!(bitcoin::util::psbt::Error, PSBT);
|
2020-02-05 11:59:02 +01:00
|
|
|
|
2020-05-07 15:14:05 +02:00
|
|
|
#[cfg(feature = "electrum")]
|
2020-02-07 23:22:28 +01:00
|
|
|
impl_error!(electrum_client::Error, Electrum);
|
2020-05-07 15:14:05 +02:00
|
|
|
#[cfg(feature = "esplora")]
|
|
|
|
impl_error!(crate::blockchain::esplora::EsploraError, Esplora);
|
|
|
|
#[cfg(feature = "key-value-db")]
|
2020-02-05 11:59:02 +01:00
|
|
|
impl_error!(sled::Error, Sled);
|