main.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. use nostr_rs_client::{Error as ClientError, Pool, Url};
  2. use nostr_rs_types::{client::Subscribe, Response};
  3. #[derive(Debug, thiserror::Error)]
  4. pub enum Error {
  5. #[error("Nostr: {0}")]
  6. Addr(#[from] nostr_rs_types::types::addr::Error),
  7. #[error("client: {0}")]
  8. Client(#[from] ClientError),
  9. }
  10. #[tokio::main]
  11. async fn main() {
  12. env_logger::init();
  13. let mut clients = Pool::new_with_clients(vec![
  14. Url::parse("wss://relay.damus.io/").expect("valid url"),
  15. Url::parse("wss://brb.io").expect("valid url"),
  16. Url::parse("wss://nos.lol").expect("valid url"),
  17. Url::parse("wss://relay.current.fyi").expect("valid url"),
  18. Url::parse("wss://eden.nostr.land").expect("valid url"),
  19. Url::parse("wss://relay.snort.social").expect("valid url"),
  20. ]);
  21. let _ = clients.subscribe(Subscribe::default().into()).await;
  22. loop {
  23. if let Some((msg, relayed_by)) = clients.recv().await {
  24. match msg {
  25. Response::Event(x) => {
  26. println!("{} => {:?}", relayed_by, x);
  27. }
  28. Response::EndOfStoredEvents(_) => {}
  29. msg => {
  30. println!("{} {:?}", relayed_by, msg);
  31. }
  32. }
  33. }
  34. }
  35. }