feat: add apply_update related error

This commit is contained in:
Matthew 2024-04-17 11:45:20 -05:00
parent c63e7ad392
commit 126bc61df6
No known key found for this signature in database
GPG Key ID: 8D4FCD82DD54DDD2
4 changed files with 27 additions and 6 deletions

View File

@ -130,6 +130,11 @@ interface ExtractTxError {
OtherExtractTransactionError(); OtherExtractTransactionError();
}; };
[Error]
interface CannotConnectError {
Include(u32 height);
};
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// bdk crate - types module // bdk crate - types module
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -226,7 +231,7 @@ interface Wallet {
Balance get_balance(); Balance get_balance();
[Throws=Alpha3Error] [Throws=CannotConnectError]
void apply_update(Update update); void apply_update(Update update);
boolean is_mine([ByRef] Script script); boolean is_mine([ByRef] Script script);

View File

@ -120,6 +120,12 @@ pub enum TxidParseError {
InvalidTxid { txid: String }, InvalidTxid { txid: String },
} }
#[derive(Debug, thiserror::Error)]
pub enum CannotConnectError {
#[error("cannot include height: {height}")]
Include { height: u32 },
}
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum AddressError { pub enum AddressError {
// Errors coming from the ParseError enum // Errors coming from the ParseError enum
@ -575,7 +581,7 @@ impl From<bdk::bitcoin::psbt::ExtractTxError> for ExtractTxError {
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::error::{EsploraError, PersistenceError, WalletCreationError}; use crate::error::{CannotConnectError, EsploraError, PersistenceError, WalletCreationError};
use crate::CalculateFeeError; use crate::CalculateFeeError;
use crate::OutPoint; use crate::OutPoint;
use crate::SignerError; use crate::SignerError;
@ -793,4 +799,11 @@ mod test {
assert_eq!(error.to_string(), message); assert_eq!(error.to_string(), message);
} }
} }
#[test]
fn test_cannot_connect_error_include() {
let error = CannotConnectError::Include { height: 42 };
assert_eq!(format!("{}", error), "cannot include height: 42");
}
} }

View File

@ -16,6 +16,7 @@ use crate::descriptor::Descriptor;
use crate::error::AddressError; use crate::error::AddressError;
use crate::error::Alpha3Error; use crate::error::Alpha3Error;
use crate::error::CalculateFeeError; use crate::error::CalculateFeeError;
use crate::error::CannotConnectError;
use crate::error::DescriptorError; use crate::error::DescriptorError;
use crate::error::EsploraError; use crate::error::EsploraError;
use crate::error::ExtractTxError; use crate::error::ExtractTxError;

View File

@ -1,8 +1,8 @@
use crate::bitcoin::{OutPoint, Psbt, Script, Transaction}; use crate::bitcoin::{OutPoint, Psbt, Script, Transaction};
use crate::descriptor::Descriptor; use crate::descriptor::Descriptor;
use crate::error::{ use crate::error::{
Alpha3Error, CalculateFeeError, PersistenceError, SignerError, TxidParseError, Alpha3Error, CalculateFeeError, CannotConnectError, PersistenceError, SignerError,
WalletCreationError, TxidParseError, WalletCreationError,
}; };
use crate::types::{ use crate::types::{
AddressIndex, AddressInfo, Balance, CanonicalTx, FeeRate, LocalOutput, ScriptAmount, AddressIndex, AddressInfo, Balance, CanonicalTx, FeeRate, LocalOutput, ScriptAmount,
@ -58,10 +58,12 @@ impl Wallet {
.into() .into()
} }
pub fn apply_update(&self, update: Arc<Update>) -> Result<(), Alpha3Error> { pub fn apply_update(&self, update: Arc<Update>) -> Result<(), CannotConnectError> {
self.get_wallet() self.get_wallet()
.apply_update(update.0.clone()) .apply_update(update.0.clone())
.map_err(|_| Alpha3Error::Generic) .map_err(|e| CannotConnectError::Include {
height: e.try_include_height,
})
} }
// TODO: This is the fallible version of get_internal_address; should I rename it to get_internal_address? // TODO: This is the fallible version of get_internal_address; should I rename it to get_internal_address?