Deserialize error from create_spend http response

Instead of having a simple ugly message like:
data did not match any variant of untagged enum DraftPsbtResult
This commit is contained in:
edouardparis 2024-09-11 12:53:17 +02:00
parent a0bafa4cdc
commit b73193ae77
2 changed files with 12 additions and 0 deletions

View File

@ -284,6 +284,7 @@ pub struct Psbt {
pub enum DraftPsbtResult {
Success(DraftPsbt),
InsufficientFunds(InsufficientFundsInfo),
Error(DraftPsbtError),
}
#[derive(Clone, Deserialize)]
@ -291,6 +292,11 @@ pub struct InsufficientFundsInfo {
pub missing: u64,
}
#[derive(Clone, Deserialize)]
pub struct DraftPsbtError {
pub error: String,
}
#[derive(Clone, Deserialize)]
pub struct DraftPsbt {
pub uuid: Option<String>,

View File

@ -753,6 +753,9 @@ impl Daemon for BackendWalletClient {
api::DraftPsbtResult::InsufficientFunds(api::InsufficientFundsInfo { missing }) => {
Ok(CreateSpendResult::InsufficientFunds { missing })
}
api::DraftPsbtResult::Error(api::DraftPsbtError { error }) => {
Err(DaemonError::Unexpected(error))
}
}
}
@ -790,6 +793,9 @@ impl Daemon for BackendWalletClient {
api::DraftPsbtResult::InsufficientFunds(api::InsufficientFundsInfo { missing }) => {
Ok(CreateSpendResult::InsufficientFunds { missing })
}
api::DraftPsbtResult::Error(api::DraftPsbtError { error }) => {
Err(DaemonError::Unexpected(error))
}
}
}