feat: add apply_update related error

This commit is contained in:
Matthew committed 2024-04-23 10:52:46 -05:00
1 parent c63e7ad392
commit 126bc61df6
4 files changed
+27 -6

No files matched your search

+6 -1
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);
+14 -1
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");
}
}
+1
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;
+6 -4
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?