Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 6e5bd38

Browse files
committed
Handle payjoin errors according to BIP 78
"The receiver is allowed to return implementation specific errors which may assist the sender to diagnose any issue. However, it is important that error codes that are not well-known and that the message do not appear on the sender's software user interface. Such error codes or messages could be used maliciously to phish a non- technical user. Instead those errors or messages can only appear in debug logs. It is advised to hard code the description of the well known error codes into the sender's software." See: https://github.com/bitcoin/bips/blob/master/bip-0078.mediawiki#receivers-well-known-errors This commit displays templates based on a particular \`ResponseError\` and debugs the rest, according to this specification.
1 parent 4a07b5d commit 6e5bd38

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

mutiny-core/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub enum MutinyError {
148148
#[error("Failed to create payjoin request.")]
149149
PayjoinCreateRequest,
150150
/// Payjoin request failed.
151-
#[error("Payjoin response error.")]
151+
#[error("Payjoin response error: {0}")]
152152
PayjoinResponse(payjoin::send::ResponseError),
153153
/// Payjoin configuration error
154154
#[error("Payjoin configuration failed.")]

mutiny-core/src/nodemanager.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ impl<S: MutinyStorage> NodeManager<S> {
783783
fee_rate: Option<f32>,
784784
) -> Result<Txid, MutinyError> {
785785
let address = Address::from_str(&uri.address.to_string())
786-
.map_err(|_| MutinyError::PayjoinConfigError)?;
786+
.map_err(|_| MutinyError::InvalidArgumentsError)?;
787787
let original_psbt = self.wallet.create_signed_psbt(address, amount, fee_rate)?;
788788

789789
let fee_rate = if let Some(rate) = fee_rate {
@@ -796,18 +796,18 @@ impl<S: MutinyStorage> NodeManager<S> {
796796
let original_psbt = payjoin::bitcoin::psbt::PartiallySignedTransaction::from_str(
797797
&original_psbt.to_string(),
798798
)
799-
.map_err(|_| MutinyError::PayjoinConfigError)?;
799+
.map_err(|_| MutinyError::WalletOperationFailed)?;
800800
log_debug!(self.logger, "Creating payjoin request");
801801
let (req, ctx) =
802802
payjoin::send::RequestBuilder::from_psbt_and_uri(original_psbt.clone(), uri)
803803
.unwrap()
804804
.build_recommended(fee_rate)
805-
.map_err(|_| MutinyError::PayjoinConfigError)?
805+
.map_err(|_| MutinyError::PayjoinCreateRequest)?
806806
.extract_v1()?;
807807

808808
let client = Client::builder()
809809
.build()
810-
.map_err(|_| MutinyError::PayjoinConfigError)?;
810+
.map_err(|e| MutinyError::Other(e.into()))?;
811811

812812
log_debug!(self.logger, "Sending payjoin request");
813813
let res = client
@@ -825,7 +825,8 @@ impl<S: MutinyStorage> NodeManager<S> {
825825

826826
log_debug!(self.logger, "Processing payjoin response");
827827
let proposal_psbt = ctx.process_response(&mut cursor).map_err(|e| {
828-
log_error!(self.logger, "Error processing payjoin response: {e}");
828+
// unrecognized error contents may only appear in debug logs and will not Display
829+
log_debug!(self.logger, "Payjoin response error: {:?}", e);
829830
e
830831
})?;
831832

mutiny-wasm/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ pub enum MutinyJsError {
148148
#[error("Failed to create payjoin request.")]
149149
PayjoinCreateRequest,
150150
// Payjoin request failed.
151-
#[error("Payjoin response error.")]
152-
PayjoinResponse,
151+
#[error("Payjoin response error: {0}")]
152+
PayjoinResponse(String),
153153
/// Payjoin configuration error
154154
#[error("Payjoin configuration failed.")]
155155
PayjoinConfigError,
@@ -209,7 +209,7 @@ impl From<MutinyError> for MutinyJsError {
209209
MutinyError::NetworkMismatch => MutinyJsError::NetworkMismatch,
210210
MutinyError::PayjoinConfigError => MutinyJsError::PayjoinConfigError,
211211
MutinyError::PayjoinCreateRequest => MutinyJsError::PayjoinCreateRequest,
212-
MutinyError::PayjoinResponse(_) => MutinyJsError::PayjoinResponse,
212+
MutinyError::PayjoinResponse(e) => MutinyJsError::PayjoinResponse(e.to_string()),
213213
}
214214
}
215215
}

0 commit comments

Comments
 (0)