From a3aba9fb83c08c1a68cca78cf19c356c80884664 Mon Sep 17 00:00:00 2001 From: John Cantrell Date: Tue, 23 Apr 2024 10:00:47 -0400 Subject: [PATCH] return error response when create_invoice fails --- mutiny-core/src/nostr/nwc.rs | 48 ++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/mutiny-core/src/nostr/nwc.rs b/mutiny-core/src/nostr/nwc.rs index f57761958..92676d734 100644 --- a/mutiny-core/src/nostr/nwc.rs +++ b/mutiny-core/src/nostr/nwc.rs @@ -602,28 +602,38 @@ impl NostrWalletConnect { .label .clone() .unwrap_or(self.profile.name.clone()); - let invoice = node.create_invoice(amount_sats, vec![label]).await?; - let bolt11 = invoice.bolt11.expect("just made"); - let content = Response { - result_type: Method::MakeInvoice, - error: None, - result: Some(ResponseResult::MakeInvoice(MakeInvoiceResponseResult { - invoice: bolt11.to_string(), - payment_hash: bolt11.payment_hash().to_string(), - })), - }; + let response = match node.create_invoice(amount_sats, vec![label]).await { + Err(e) => self.get_skipped_error_event( + &event, + Method::MakeInvoice, + ErrorCode::Other, + format!("Failed to create invoice: {:?}", e), + )?, + Ok(invoice) => { + let bolt11 = invoice.bolt11.expect("just made"); + + let content = Response { + result_type: Method::MakeInvoice, + error: None, + result: Some(ResponseResult::MakeInvoice(MakeInvoiceResponseResult { + invoice: bolt11.to_string(), + payment_hash: bolt11.payment_hash().to_string(), + })), + }; - let encrypted = encrypt( - self.server_key.secret_key()?, - &self.client_key.public_key(), - content.as_json(), - )?; + let encrypted = encrypt( + self.server_key.secret_key()?, + &self.client_key.public_key(), + content.as_json(), + )?; - let p_tag = Tag::public_key(event.pubkey); - let e_tag = Tag::event(event.id); - let response = EventBuilder::new(Kind::WalletConnectResponse, encrypted, [p_tag, e_tag]) - .to_event(&self.server_key)?; + let p_tag = Tag::public_key(event.pubkey); + let e_tag = Tag::event(event.id); + EventBuilder::new(Kind::WalletConnectResponse, encrypted, [p_tag, e_tag]) + .to_event(&self.server_key)? + } + }; Ok(Some(response)) }