bdk-ffi/src/error.rs

95 lines
3.5 KiB
Rust
Raw Normal View History

use ::safer_ffi::prelude::*;
use bdk::Error;
#[derive_ReprC]
#[repr(u16)]
#[derive(Debug)]
pub enum FfiError {
None,
InvalidU32Bytes,
Generic,
ScriptDoesntHaveAddressForm,
SingleRecipientMultipleOutputs,
SingleRecipientNoInputs,
NoRecipients,
NoUtxosSelected,
OutputBelowDustLimit,
InsufficientFunds,
BnBTotalTriesExceeded,
BnBNoExactMatch,
UnknownUtxo,
TransactionNotFound,
TransactionConfirmed,
IrreplaceableTransaction,
FeeRateTooLow,
FeeTooLow,
MissingKeyOrigin,
Key,
ChecksumMismatch,
SpendingPolicyRequired,
InvalidPolicyPathError,
Signer,
InvalidProgressValue,
ProgressUpdateError,
InvalidOutpoint,
Descriptor,
AddressValidator,
Encode,
Miniscript,
Bip32,
Secp256k1,
Json,
Hex,
Psbt,
Electrum,
// Esplora,
// CompactFilters,
Sled,
}
impl From<&bdk::Error> for FfiError {
fn from(error: &bdk::Error) -> Self {
match error {
Error::InvalidU32Bytes(_) => FfiError::InvalidU32Bytes,
Error::Generic(_) => FfiError::Generic,
Error::ScriptDoesntHaveAddressForm => FfiError::ScriptDoesntHaveAddressForm,
Error::SingleRecipientMultipleOutputs => FfiError::SingleRecipientMultipleOutputs,
Error::SingleRecipientNoInputs => FfiError::SingleRecipientNoInputs,
Error::NoRecipients => FfiError::NoRecipients,
Error::NoUtxosSelected => FfiError::NoUtxosSelected,
Error::OutputBelowDustLimit(_) => FfiError::OutputBelowDustLimit,
Error::InsufficientFunds { .. } => FfiError::InsufficientFunds,
Error::BnBTotalTriesExceeded => FfiError::BnBTotalTriesExceeded,
Error::BnBNoExactMatch => FfiError::BnBNoExactMatch,
Error::UnknownUtxo => FfiError::UnknownUtxo,
Error::TransactionNotFound => FfiError::TransactionNotFound,
Error::TransactionConfirmed => FfiError::TransactionConfirmed,
Error::IrreplaceableTransaction => FfiError::IrreplaceableTransaction,
Error::FeeRateTooLow { .. } => FfiError::FeeRateTooLow,
Error::FeeTooLow { .. } => FfiError::FeeTooLow,
Error::MissingKeyOrigin(_) => FfiError::MissingKeyOrigin,
Error::Key(_) => FfiError::Key,
Error::ChecksumMismatch => FfiError::ChecksumMismatch,
Error::SpendingPolicyRequired(_) => FfiError::SpendingPolicyRequired,
Error::InvalidPolicyPathError(_) => FfiError::InvalidPolicyPathError,
Error::Signer(_) => FfiError::Signer,
Error::InvalidProgressValue(_) => FfiError::InvalidProgressValue,
Error::ProgressUpdateError => FfiError::ProgressUpdateError,
Error::InvalidOutpoint(_) => FfiError::InvalidOutpoint,
Error::Descriptor(_) => FfiError::Descriptor,
Error::AddressValidator(_) => FfiError::AddressValidator,
Error::Encode(_) => FfiError::Encode,
Error::Miniscript(_) => FfiError::Miniscript,
Error::Bip32(_) => FfiError::Bip32,
Error::Secp256k1(_) => FfiError::Secp256k1,
Error::Json(_) => FfiError::Json,
Error::Hex(_) => FfiError::Hex,
Error::Psbt(_) => FfiError::Psbt,
Error::Electrum(_) => FfiError::Electrum,
// Error::Esplora(_) => JniError::Esplora,
// Error::CompactFilters(_) => JniError::CompactFilters,
Error::Sled(_) => FfiError::Sled,
}
}
}