Skip to content

Commit

Permalink
return error response when create_invoice fails
Browse files Browse the repository at this point in the history
  • Loading branch information
johncantrell97 committed Apr 23, 2024
1 parent 9109707 commit a3aba9f
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions mutiny-core/src/nostr/nwc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit a3aba9f

Please sign in to comment.