feat: add sqlite error

This commit is contained in:
thunderbiscuit 2024-06-04 09:58:30 -04:00
parent 19b4e1159a
commit 65702f401b
No known key found for this signature in database
GPG Key ID: 88253696EB836462
3 changed files with 36 additions and 17 deletions

View File

@ -236,6 +236,12 @@ interface SignerError {
External(string error_message); External(string error_message);
}; };
[Error]
interface SqliteError {
InvalidNetwork(Network expected, Network given);
Sqlite(string rusqlite_error);
};
[Error] [Error]
interface TransactionError { interface TransactionError {
Io(); Io();

View File

@ -1,8 +1,10 @@
use crate::bitcoin::OutPoint; use crate::bitcoin::OutPoint;
use crate::Network;
use bdk_electrum::electrum_client::Error as BdkElectrumError; use bdk_electrum::electrum_client::Error as BdkElectrumError;
use bdk_esplora::esplora_client::{Error as BdkEsploraError, Error}; use bdk_esplora::esplora_client::{Error as BdkEsploraError, Error};
use bdk_sqlite::rusqlite::Error as BdkSqliteError; use bdk_sqlite::rusqlite::Error as BdkRusqliteError;
use bdk_sqlite::Error as BdkSqliteError;
use bdk_wallet::bitcoin::address::Error as BdkAddressError; use bdk_wallet::bitcoin::address::Error as BdkAddressError;
use bdk_wallet::bitcoin::address::ParseError; use bdk_wallet::bitcoin::address::ParseError;
use bdk_wallet::bitcoin::amount::ParseAmountError as BdkParseAmountError; use bdk_wallet::bitcoin::amount::ParseAmountError as BdkParseAmountError;
@ -11,7 +13,6 @@ use bdk_wallet::bitcoin::consensus::encode::Error as BdkEncodeError;
use bdk_wallet::bitcoin::psbt::Error as BdkPsbtError; use bdk_wallet::bitcoin::psbt::Error as BdkPsbtError;
use bdk_wallet::bitcoin::psbt::ExtractTxError as BdkExtractTxError; use bdk_wallet::bitcoin::psbt::ExtractTxError as BdkExtractTxError;
use bdk_wallet::bitcoin::psbt::PsbtParseError as BdkPsbtParseError; use bdk_wallet::bitcoin::psbt::PsbtParseError as BdkPsbtParseError;
use bdk_wallet::bitcoin::Network;
use bdk_wallet::chain::local_chain::CannotConnectError as BdkCannotConnectError; use bdk_wallet::chain::local_chain::CannotConnectError as BdkCannotConnectError;
use bdk_wallet::chain::tx_graph::CalculateFeeError as BdkCalculateFeeError; use bdk_wallet::chain::tx_graph::CalculateFeeError as BdkCalculateFeeError;
use bdk_wallet::descriptor::DescriptorError as BdkDescriptorError; use bdk_wallet::descriptor::DescriptorError as BdkDescriptorError;
@ -575,6 +576,17 @@ pub enum SignerError {
External { error_message: String }, External { error_message: String },
} }
#[derive(Debug, thiserror::Error)]
pub enum SqliteError {
// This error is renamed from Network to InvalidNetwork to avoid conflict with the Network enum
// in uniffi.
#[error("invalid network, cannot change the one already stored in the database")]
InvalidNetwork { expected: Network, given: Network },
#[error("SQLite error: {rusqlite_error}")]
Sqlite { rusqlite_error: String },
}
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum TransactionError { pub enum TransactionError {
#[error("io error")] #[error("io error")]
@ -1211,27 +1223,27 @@ impl From<BdkEncodeError> for TransactionError {
} }
} }
// impl From<BdkFileError> for WalletCreationError { impl From<BdkRusqliteError> for WalletCreationError {
// fn from(error: BdkFileError) -> Self { fn from(error: BdkRusqliteError) -> Self {
// match error {
// BdkFileError::Io(e) => WalletCreationError::Io {
// error_message: e.to_string(),
// },
// BdkFileError::InvalidMagicBytes { got, expected } => {
// WalletCreationError::InvalidMagicBytes { got, expected }
// }
// }
// }
// }
impl From<BdkSqliteError> for WalletCreationError {
fn from(error: BdkSqliteError) -> Self {
WalletCreationError::Sqlite { WalletCreationError::Sqlite {
error_message: error.to_string(), error_message: error.to_string(),
} }
} }
} }
impl From<BdkSqliteError> for SqliteError {
fn from(error: BdkSqliteError) -> Self {
match error {
BdkSqliteError::Network { expected, given } => {
SqliteError::InvalidNetwork { expected, given }
}
BdkSqliteError::Sqlite(e) => SqliteError::Sqlite {
rusqlite_error: e.to_string(),
},
}
}
}
impl From<NewOrLoadError> for WalletCreationError { impl From<NewOrLoadError> for WalletCreationError {
fn from(error: NewOrLoadError) -> Self { fn from(error: NewOrLoadError) -> Self {
match error { match error {

View File

@ -36,6 +36,7 @@ use crate::error::PersistenceError;
use crate::error::PsbtError; use crate::error::PsbtError;
use crate::error::PsbtParseError; use crate::error::PsbtParseError;
use crate::error::SignerError; use crate::error::SignerError;
use crate::error::SqliteError;
use crate::error::TransactionError; use crate::error::TransactionError;
use crate::error::TxidParseError; use crate::error::TxidParseError;
use crate::error::WalletCreationError; use crate::error::WalletCreationError;