Skip to content

Commit

Permalink
Fixup NWC
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcaseria committed Sep 23, 2024
1 parent 9e7e258 commit 427b9a2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
3 changes: 3 additions & 0 deletions crates/cdk-nostr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ thiserror = "1"
tokio = "1"
tracing = "0.1"
url = "2.3"

[dev-dependencies]
tokio-stream = "0.1"
44 changes: 22 additions & 22 deletions crates/cdk-nostr/examples/app_pay_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use lightning_invoice::Bolt11Invoice;
use nostr_database::{MemoryDatabase, MemoryDatabaseOptions};
use nostr_sdk::{
nips::nip47::{self, NostrWalletConnectURI, PayInvoiceRequestParams},
Alphabet, EventSource, Filter, Keys, Kind, SingleLetterTag,
Alphabet, Filter, FilterOptions, Keys, Kind, SingleLetterTag,
};
use tokio_stream::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -17,7 +18,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let connect_uri = NostrWalletConnectURI::from_str(&args[1])?;
let invoice = Bolt11Invoice::from_str(&args[2])?;

let keys = Keys::generate();
let keys = Keys::new(connect_uri.secret.clone());
let client = nostr_sdk::Client::builder()
.database(MemoryDatabase::with_opts(MemoryDatabaseOptions {
events: true,
Expand All @@ -35,30 +36,29 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
});
let event = request.to_event(&connect_uri)?;
let event_id = event.id;

let mut stream = client
.pool()
.stream_events_of(
vec![Filter::new()
.kind(Kind::WalletConnectResponse)
.custom_tag(SingleLetterTag::lowercase(Alphabet::E), vec![event_id])],
Duration::from_secs(60),
FilterOptions::WaitForEventsAfterEOSE(1),
)
.await?;
client.send_event(event).await?;

loop {
let events = client
.get_events_of(
vec![Filter::new()
.kind(Kind::WalletConnectResponse)
.custom_tag(SingleLetterTag::lowercase(Alphabet::E), vec![event_id])],
EventSource::relays(None),
)
.await?;
if let Some(event) = events.first() {
match nip47::Response::from_event(&connect_uri, event) {
Ok(response) => {
println!("{:?}", response);
break;
}
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(1);
}
if let Some(event) = stream.next().await {
match nip47::Response::from_event(&connect_uri, &event) {
Ok(response) => {
println!("{:?}", response);
}
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}
tokio::time::sleep(Duration::from_secs(1)).await;
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions crates/cdk-nostr/src/nwc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ impl WalletConnection {
fn filter(&self, service_pubkey: PublicKey, since: Timestamp) -> Filter {
Filter::new()
.kind(Kind::WalletConnectRequest)
.author(self.keys.public_key())
.since(since)
.custom_tag(
SingleLetterTag::lowercase(Alphabet::P),
Expand Down

0 comments on commit 427b9a2

Please sign in to comment.