2020-08-31 11:26:36 +02:00
|
|
|
// Magical Bitcoin Library
|
|
|
|
// Written in 2020 by
|
|
|
|
// Alekos Filini <alekos.filini@gmail.com>
|
|
|
|
//
|
|
|
|
// Copyright (c) 2020 Magical Bitcoin
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
// SOFTWARE.
|
|
|
|
|
2020-08-17 10:58:45 +02:00
|
|
|
use std::fmt;
|
|
|
|
|
2020-08-12 12:51:50 +02:00
|
|
|
use bitcoin::{Address, OutPoint};
|
2020-02-07 23:22:28 +01:00
|
|
|
|
2020-09-04 11:44:49 +02:00
|
|
|
/// Errors that can be thrown by the [`Wallet`](crate::wallet::Wallet)
|
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,
|
2020-10-28 10:37:47 +01:00
|
|
|
SingleRecipientMultipleOutputs,
|
|
|
|
SingleRecipientNoInputs,
|
|
|
|
NoRecipients,
|
|
|
|
NoUtxosSelected,
|
2020-02-07 23:22:28 +01:00
|
|
|
OutputBelowDustLimit(usize),
|
|
|
|
InsufficientFunds,
|
2020-10-31 16:24:59 +01:00
|
|
|
BnBTotalTriesExceeded,
|
|
|
|
BnBNoExactMatch,
|
2020-08-10 10:49:34 +02:00
|
|
|
InvalidAddressNetwork(Address),
|
2020-02-07 23:22:28 +01:00
|
|
|
UnknownUTXO,
|
|
|
|
DifferentTransactions,
|
2020-08-13 16:51:27 +02:00
|
|
|
TransactionNotFound,
|
|
|
|
TransactionConfirmed,
|
|
|
|
IrreplaceableTransaction,
|
2020-08-31 10:49:44 +02:00
|
|
|
FeeRateTooLow {
|
|
|
|
required: crate::types::FeeRate,
|
|
|
|
},
|
2020-10-22 09:11:58 +02:00
|
|
|
FeeTooLow {
|
|
|
|
required: u64,
|
|
|
|
},
|
2020-02-07 23:22:28 +01:00
|
|
|
|
2020-09-21 15:44:07 +02:00
|
|
|
Key(crate::keys::KeyError),
|
|
|
|
|
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-11-10 15:06:14 +01:00
|
|
|
SpendingPolicyRequired(crate::types::ScriptType),
|
2020-02-07 23:22:28 +01:00
|
|
|
InvalidPolicyPathError(crate::descriptor::policy::PolicyError),
|
|
|
|
|
2020-08-12 12:51:50 +02:00
|
|
|
Signer(crate::wallet::signer::SignerError),
|
2020-02-07 23:22:28 +01:00
|
|
|
|
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-08-15 23:21:13 +02:00
|
|
|
AddressValidator(crate::wallet::address_validator::AddressValidatorError),
|
2020-01-27 22:02:55 +01:00
|
|
|
|
2020-02-05 11:59:02 +01:00
|
|
|
Encode(bitcoin::consensus::encode::Error),
|
2020-08-12 12:51:50 +02:00
|
|
|
Miniscript(miniscript::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),
|
2020-08-25 16:07:26 +02:00
|
|
|
#[cfg(feature = "compact_filters")]
|
|
|
|
CompactFilters(crate::blockchain::compact_filters::CompactFiltersError),
|
2020-05-07 15:14:05 +02:00
|
|
|
#[cfg(feature = "key-value-db")]
|
2020-02-05 11:59:02 +01:00
|
|
|
Sled(sled::Error),
|
2020-01-27 22:02:55 +01:00
|
|
|
}
|
|
|
|
|
2020-08-17 10:58:45 +02:00
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{:?}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::error::Error for 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);
|
2020-08-15 23:21:13 +02:00
|
|
|
impl_error!(
|
|
|
|
crate::wallet::address_validator::AddressValidatorError,
|
|
|
|
AddressValidator
|
|
|
|
);
|
2020-02-07 23:22:28 +01:00
|
|
|
impl_error!(
|
|
|
|
crate::descriptor::policy::PolicyError,
|
|
|
|
InvalidPolicyPathError
|
|
|
|
);
|
2020-08-12 12:51:50 +02:00
|
|
|
impl_error!(crate::wallet::signer::SignerError, Signer);
|
2020-02-07 23:22:28 +01:00
|
|
|
|
2020-09-21 15:44:07 +02:00
|
|
|
impl From<crate::keys::KeyError> for Error {
|
|
|
|
fn from(key_error: crate::keys::KeyError) -> Error {
|
|
|
|
match key_error {
|
|
|
|
crate::keys::KeyError::Miniscript(inner) => Error::Miniscript(inner),
|
|
|
|
crate::keys::KeyError::BIP32(inner) => Error::BIP32(inner),
|
|
|
|
crate::keys::KeyError::InvalidChecksum => Error::ChecksumMismatch,
|
2020-10-07 14:18:50 -07:00
|
|
|
e => Error::Key(e),
|
2020-09-21 15:44:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 11:59:02 +01:00
|
|
|
impl_error!(bitcoin::consensus::encode::Error, Encode);
|
2020-08-12 12:51:50 +02:00
|
|
|
impl_error!(miniscript::Error, Miniscript);
|
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);
|
2020-08-25 16:07:26 +02:00
|
|
|
|
|
|
|
#[cfg(feature = "compact_filters")]
|
|
|
|
impl From<crate::blockchain::compact_filters::CompactFiltersError> for Error {
|
|
|
|
fn from(other: crate::blockchain::compact_filters::CompactFiltersError) -> Self {
|
|
|
|
match other {
|
|
|
|
crate::blockchain::compact_filters::CompactFiltersError::Global(e) => *e,
|
|
|
|
err @ _ => Error::CompactFilters(err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|