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

Commit eeb760e

Browse files
authored
Merge pull request #1155 from johncantrell97/nwc-fixups
nwc fixups
2 parents 73710b1 + a3aba9f commit eeb760e

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

mutiny-core/src/nostr/nwc.rs

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,7 @@ impl NostrWalletConnect {
421421
let mut needs_save = false;
422422
let mut needs_delete = false;
423423
let mut result = None;
424-
if self.profile.active()
425-
&& event.kind == Kind::WalletConnectRequest
426-
&& event.pubkey == client_pubkey
427-
{
424+
if event.kind == Kind::WalletConnectRequest && event.pubkey == client_pubkey {
428425
let server_key = self.server_key.secret_key()?;
429426

430427
let decrypted = decrypt(server_key, &client_pubkey, &event.content)?;
@@ -446,6 +443,18 @@ impl NostrWalletConnect {
446443
}
447444
};
448445

446+
// only respond to commands sent to active profiles
447+
if !self.profile.active() {
448+
return self
449+
.get_skipped_error_event(
450+
&event,
451+
req.method,
452+
ErrorCode::Other,
453+
"Nostr profile inactive".to_string(),
454+
)
455+
.map(Some);
456+
}
457+
449458
// only respond to commands that are allowed by the profile
450459
if !self.profile.available_commands().contains(&req.method) {
451460
return self
@@ -593,28 +602,38 @@ impl NostrWalletConnect {
593602
.label
594603
.clone()
595604
.unwrap_or(self.profile.name.clone());
596-
let invoice = node.create_invoice(amount_sats, vec![label]).await?;
597-
let bolt11 = invoice.bolt11.expect("just made");
598605

599-
let content = Response {
600-
result_type: Method::MakeInvoice,
601-
error: None,
602-
result: Some(ResponseResult::MakeInvoice(MakeInvoiceResponseResult {
603-
invoice: bolt11.to_string(),
604-
payment_hash: bolt11.payment_hash().to_string(),
605-
})),
606-
};
606+
let response = match node.create_invoice(amount_sats, vec![label]).await {
607+
Err(e) => self.get_skipped_error_event(
608+
&event,
609+
Method::MakeInvoice,
610+
ErrorCode::Other,
611+
format!("Failed to create invoice: {:?}", e),
612+
)?,
613+
Ok(invoice) => {
614+
let bolt11 = invoice.bolt11.expect("just made");
615+
616+
let content = Response {
617+
result_type: Method::MakeInvoice,
618+
error: None,
619+
result: Some(ResponseResult::MakeInvoice(MakeInvoiceResponseResult {
620+
invoice: bolt11.to_string(),
621+
payment_hash: bolt11.payment_hash().to_string(),
622+
})),
623+
};
607624

608-
let encrypted = encrypt(
609-
self.server_key.secret_key()?,
610-
&self.client_key.public_key(),
611-
content.as_json(),
612-
)?;
625+
let encrypted = encrypt(
626+
self.server_key.secret_key()?,
627+
&self.client_key.public_key(),
628+
content.as_json(),
629+
)?;
613630

614-
let p_tag = Tag::public_key(event.pubkey);
615-
let e_tag = Tag::event(event.id);
616-
let response = EventBuilder::new(Kind::WalletConnectResponse, encrypted, [p_tag, e_tag])
617-
.to_event(&self.server_key)?;
631+
let p_tag = Tag::public_key(event.pubkey);
632+
let e_tag = Tag::event(event.id);
633+
EventBuilder::new(Kind::WalletConnectResponse, encrypted, [p_tag, e_tag])
634+
.to_event(&self.server_key)?
635+
}
636+
};
618637

619638
Ok(Some(response))
620639
}

0 commit comments

Comments
 (0)