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();
};
[Error]
interface CannotConnectError {
Include(u32 height);
};
// ------------------------------------------------------------------------
// bdk crate - types module
// ------------------------------------------------------------------------
@ -226,7 +231,7 @@ interface Wallet {
Balance get_balance();
[Throws=Alpha3Error]
[Throws=CannotConnectError]
void apply_update(Update update);
boolean is_mine([ByRef] Script script);

View File

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

View File

@ -1,8 +1,8 @@
use crate::bitcoin::{OutPoint, Psbt, Script, Transaction};
use crate::descriptor::Descriptor;
use crate::error::{
Alpha3Error, CalculateFeeError, PersistenceError, SignerError, TxidParseError,
WalletCreationError,
Alpha3Error, CalculateFeeError, CannotConnectError, PersistenceError, SignerError,
TxidParseError, WalletCreationError,
};
use crate::types::{
AddressIndex, AddressInfo, Balance, CanonicalTx, FeeRate, LocalOutput, ScriptAmount,
@ -58,10 +58,12 @@ impl Wallet {
.into()
}
pub fn apply_update(&self, update: Arc<Update>) -> Result<(), Alpha3Error> {
pub fn apply_update(&self, update: Arc<Update>) -> Result<(), CannotConnectError> {
self.get_wallet()
.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?