use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
use nostr_sdk::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let proxy: Proxy = Proxy::onion(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)));
let client = Client::builder().proxy(proxy).build();
client.add_relay("wss://relay.damus.io").await?;
client
.add_relay("ws://oxtrdevav64z64yb7x6rjg4ntzqjhedm5b5zjqulugknhzr46ny2qbad.onion")
.await?;
client.connect().await;
let keys = Keys::parse("nsec1ufnus6pju578ste3v90xd5m2decpuzpql2295m3sknqcjzyys9ls0qlc85")?;
let filter: Filter = Filter::new().pubkey(keys.public_key()).limit(0);
client.subscribe(filter).await?;
let mut notifications = client.notifications();
while let Some(notification) = notifications.next().await {
if let ClientNotification::Event { event, .. } = notification {
if event.kind == Kind::GiftWrap {
let UnwrappedGift { rumor, .. } = UnwrappedGift::from_gift_wrap(&keys, &event)?;
println!("Rumor: {}", rumor.as_json());
} else {
println!("{:?}", event);
}
}
}
Ok(())
}