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

Commit dbca043

Browse files
authored
Merge pull request #940 from DanGould/pj-response-errors
2 parents ff4410b + 6e5bd38 commit dbca043

File tree

7 files changed

+29
-30
lines changed

7 files changed

+29
-30
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mutiny-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cbc = { version = "0.1", features = ["alloc"] }
4444
aes = { version = "0.8" }
4545
jwt-compact = { version = "0.8.0-beta.1", features = ["es256k"] }
4646
argon2 = { version = "0.5.0", features = ["password-hash", "alloc"] }
47-
payjoin = { version = "0.10.0", features = ["send", "base64"] }
47+
payjoin = { version = "0.13.0", features = ["send", "base64"] }
4848
gluesql = { version = "0.15", default-features = false, features = ["memory-storage"] }
4949
gluesql-core = "0.15.0"
5050
bincode = "1.3.3"

mutiny-core/src/error.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ pub enum MutinyError {
147147
/// Payjoin request creation failed.
148148
#[error("Failed to create payjoin request.")]
149149
PayjoinCreateRequest,
150-
/// Payjoin response validation failed.
151-
#[error("Failed to validate payjoin response.")]
152-
PayjoinValidateResponse(payjoin::send::ValidationError),
150+
/// Payjoin request failed.
151+
#[error("Payjoin response error: {0}")]
152+
PayjoinResponse(payjoin::send::ResponseError),
153153
/// Payjoin configuration error
154154
#[error("Payjoin configuration failed.")]
155155
PayjoinConfigError,
@@ -471,8 +471,8 @@ impl From<payjoin::send::CreateRequestError> for MutinyError {
471471
}
472472
}
473473

474-
impl From<payjoin::send::ValidationError> for MutinyError {
475-
fn from(e: payjoin::send::ValidationError) -> Self {
476-
Self::PayjoinValidateResponse(e)
474+
impl From<payjoin::send::ResponseError> for MutinyError {
475+
fn from(e: payjoin::send::ResponseError) -> Self {
476+
Self::PayjoinResponse(e)
477477
}
478478
}

mutiny-core/src/nodemanager.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use lightning::util::logger::*;
4646
use lightning::{log_debug, log_error, log_info, log_warn};
4747
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription};
4848
use lightning_transaction_sync::EsploraSyncClient;
49-
use payjoin::{PjUri, PjUriExt};
49+
use payjoin::Uri;
5050
use reqwest::Client;
5151
use serde::{Deserialize, Serialize};
5252
use serde_json::Value;
@@ -777,16 +777,15 @@ impl<S: MutinyStorage> NodeManager<S> {
777777

778778
pub async fn send_payjoin(
779779
&self,
780-
uri: PjUri<'_>,
780+
uri: Uri<'_, payjoin::bitcoin::address::NetworkChecked>,
781781
amount: u64,
782782
labels: Vec<String>,
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

789-
let payout_scripts = std::iter::once(uri.address.script_pubkey());
790789
let fee_rate = if let Some(rate) = fee_rate {
791790
FeeRate::from_sat_per_vb(rate)
792791
} else {
@@ -797,17 +796,18 @@ impl<S: MutinyStorage> NodeManager<S> {
797796
let original_psbt = payjoin::bitcoin::psbt::PartiallySignedTransaction::from_str(
798797
&original_psbt.to_string(),
799798
)
800-
.map_err(|_| MutinyError::PayjoinConfigError)?;
801-
let pj_params =
802-
payjoin::send::Configuration::recommended(&original_psbt, payout_scripts, fee_rate)
803-
.map_err(|_| MutinyError::PayjoinConfigError)?;
804-
799+
.map_err(|_| MutinyError::WalletOperationFailed)?;
805800
log_debug!(self.logger, "Creating payjoin request");
806-
let (req, ctx) = uri.create_pj_request(original_psbt.clone(), pj_params)?;
801+
let (req, ctx) =
802+
payjoin::send::RequestBuilder::from_psbt_and_uri(original_psbt.clone(), uri)
803+
.unwrap()
804+
.build_recommended(fee_rate)
805+
.map_err(|_| MutinyError::PayjoinCreateRequest)?
806+
.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/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ getrandom = { version = "0.2", features = ["js"] }
4141
futures = "0.3.25"
4242
urlencoding = "2.1.2"
4343
once_cell = "1.18.0"
44-
payjoin = { version = "0.10.0", features = ["send", "base64"] }
44+
payjoin = { version = "0.13.0", features = ["send", "base64"] }
4545
fedimint-core = "0.2.1"
4646

4747
# The `console_error_panic_hook` crate provides better debugging of panics by

mutiny-wasm/src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ pub enum MutinyJsError {
147147
/// Payjoin request creation failed.
148148
#[error("Failed to create payjoin request.")]
149149
PayjoinCreateRequest,
150-
/// Payjoin response validation failed.
151-
#[error("Failed to validate payjoin response.")]
152-
PayjoinValidateResponse,
150+
// Payjoin request failed.
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::PayjoinValidateResponse(_) => MutinyJsError::PayjoinValidateResponse,
212+
MutinyError::PayjoinResponse(e) => MutinyJsError::PayjoinResponse(e.to_string()),
213213
}
214214
}
215215
}

mutiny-wasm/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use mutiny_core::{
4343
nodemanager::{create_lsp_config, NodeManager},
4444
};
4545
use mutiny_core::{logging::MutinyLogger, nostr::ProfileType};
46-
use payjoin::UriExt;
4746
use std::str::FromStr;
4847
use std::sync::Arc;
4948
use std::{
@@ -487,9 +486,7 @@ impl MutinyWallet {
487486
// I know walia parses `pj=` and `pjos=` but payjoin::Uri parses the whole bip21 uri
488487
let pj_uri = payjoin::Uri::try_from(payjoin_uri.as_str())
489488
.map_err(|_| MutinyJsError::InvalidArgumentsError)?
490-
.assume_checked()
491-
.check_pj_supported()
492-
.map_err(|_| MutinyJsError::InvalidArgumentsError)?;
489+
.assume_checked();
493490
Ok(self
494491
.inner
495492
.node_manager

0 commit comments

Comments
 (0)