Skip to content

Commit

Permalink
feat: add sqlite error
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Jun 4, 2024
1 parent 19b4e11 commit b78dd95
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
6 changes: 6 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ interface SignerError {
External(string error_message);
};

[Error]
interface SqliteError {
Network(Network expected, Network given);
Sqlite(string rusqlite_error);
};

[Error]
interface TransactionError {
Io();
Expand Down
28 changes: 12 additions & 16 deletions bdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::bitcoin::OutPoint;

use bdk_electrum::electrum_client::Error as BdkElectrumError;
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_wallet::bitcoin::address::Error as BdkAddressError;
use bdk_wallet::bitcoin::address::ParseError;
use bdk_wallet::bitcoin::amount::ParseAmountError as BdkParseAmountError;
Expand Down Expand Up @@ -575,6 +575,15 @@ pub enum SignerError {
External { error_message: String },
}

#[derive(Debug, thiserror::Error)]
pub enum SqliteError {
#[error("invalid network, cannot change the one already stored in the database")]
Network { expected: Network, given: Network },

#[error("SQLite error: {rusqlite_error}")]
Sqlite { rusqlite_error: String },
}

#[derive(Debug, thiserror::Error)]
pub enum TransactionError {
#[error("io error")]
Expand Down Expand Up @@ -1211,21 +1220,8 @@ impl From<BdkEncodeError> for TransactionError {
}
}

// impl From<BdkFileError> for WalletCreationError {
// fn from(error: BdkFileError) -> 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 {
impl From<BdkRusqliteError> for WalletCreationError {
fn from(error: BdkRusqliteError) -> Self {
WalletCreationError::Sqlite {
error_message: error.to_string(),
}
Expand Down
1 change: 1 addition & 0 deletions bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::error::PersistenceError;
use crate::error::PsbtError;
use crate::error::PsbtParseError;
use crate::error::SignerError;
use crate::error::SqliteError;
use crate::error::TransactionError;
use crate::error::TxidParseError;
use crate::error::WalletCreationError;
Expand Down

0 comments on commit b78dd95

Please sign in to comment.