Skip to content

Commit

Permalink
Merge pull request #905 from MutinyWallet/nostr-26
Browse files Browse the repository at this point in the history
Update rust-nostr to v0.26
  • Loading branch information
TonyGiorgio authored Dec 28, 2023
2 parents f17881b + 131bab4 commit 7390372
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 151 deletions.
133 changes: 107 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mutiny-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ futures-util = { version = "0.3", default-features = false }
reqwest = { version = "0.11", default-features = false, features = ["json"] }
async-trait = "0.1.68"
url = { version = "2.3.1", features = ["serde"] }
nostr = { version = "0.24.0", default-features = false, features = ["nip47"] }
nostr-sdk = { version = "0.24.0", default-features = false }
nostr = { version = "0.26.0", default-features = false, features = ["nip47"] }
nostr-sdk = { version = "0.26.0", default-features = false }
cbc = { version = "0.1", features = ["alloc"] }
aes = { version = "0.8" }
jwt-compact = { version = "0.8.0-beta.1", features = ["es256k"] }
Expand Down
21 changes: 7 additions & 14 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use crate::{
use crate::{nodemanager::NodeManager, nostr::ProfileType};
use crate::{nostr::NostrManager, utils::sleep};
use ::nostr::key::XOnlyPublicKey;
use ::nostr::{Event, Kind, Metadata};
use ::nostr::{Event, JsonUtil, Kind, Metadata};
use bdk_chain::ConfirmationTime;
use bip39::Mnemonic;
use bitcoin::util::bip32::ExtendedPrivKey;
Expand Down Expand Up @@ -473,19 +473,12 @@ impl<S: MutinyStorage> MutinyWallet<S> {
log_warn!(logger, "Failed to clear expired NWC invoices: {e}");
}

// clear successful single-use profiles

let client = Client::new(&nostr.primary_key);

#[cfg(target_arch = "wasm32")]
let add_relay_res = client.add_relays(nostr.get_relays()).await;

#[cfg(not(target_arch = "wasm32"))]
let add_relay_res = client
.add_relays(nostr.get_relays().into_iter().map(|s| (s, None)).collect())
.await;

add_relay_res.expect("Failed to add relays");
client
.add_relays(nostr.get_relays())
.await
.expect("Failed to add relays");
client.connect().await;

let mut last_filters = nostr.get_nwc_filters();
Expand Down Expand Up @@ -513,7 +506,7 @@ impl<S: MutinyStorage> MutinyWallet<S> {
select! {
notification = read_fut => {
match notification {
Ok(RelayPoolNotification::Event(_url, event)) => {
Ok(RelayPoolNotification::Event { event, .. }) => {
if event.kind == Kind::WalletConnectRequest && event.verify().is_ok() {
match nostr.handle_nwc_request(event, &self_clone).await {
Ok(Some(event)) => {
Expand All @@ -528,7 +521,7 @@ impl<S: MutinyStorage> MutinyWallet<S> {
}
}
},
Ok(RelayPoolNotification::Message(_, _)) => {}, // ignore messages
Ok(RelayPoolNotification::Message { .. }) => {}, // ignore messages
Ok(RelayPoolNotification::Shutdown) => break, // if we disconnect, we restart to reconnect
Ok(RelayPoolNotification::Stop) => {}, // Currently unused
Ok(RelayPoolNotification::RelayStatus { .. }) => {}, // Currently unused
Expand Down
15 changes: 11 additions & 4 deletions mutiny-core/src/nodemanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use lightning_transaction_sync::EsploraSyncClient;
use lnurl::lnurl::LnUrl;
use lnurl::{AsyncClient as LnUrlClient, LnUrlResponse, Response};
use nostr::key::XOnlyPublicKey;
use nostr::{EventBuilder, Keys, Kind, Tag, TagKind};
use nostr::{EventBuilder, JsonUtil, Keys, Kind, Tag, TagKind};
use payjoin::{PjUri, PjUriExt};
use reqwest::Client;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -1617,13 +1617,20 @@ impl<S: MutinyStorage> NodeManager<S> {
let zap_request = match zap_npub {
Some(zap_npub) => {
let tags = vec![
Tag::PubKey(zap_npub, None),
Tag::Amount(msats),
Tag::PublicKey {
public_key: zap_npub,
relay_url: None,
alias: None,
},
Tag::Amount {
millisats: msats,
bolt11: None,
},
Tag::Lnurl(lnurl.to_string()),
Tag::Relays(vec!["wss://nostr.mutinywallet.com".into()]),
Tag::Generic(TagKind::Custom("anon".to_string()), vec![]),
];
EventBuilder::new(Kind::ZapRequest, "", &tags)
EventBuilder::new(Kind::ZapRequest, "", tags)
.to_event(&Keys::generate())
.ok()
.map(|z| z.as_json())
Expand Down
Loading

0 comments on commit 7390372

Please sign in to comment.