use std::num::NonZeroU8;
use nostr::nips::nip13::SingleThreadPow;
use nostr_sdk::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let client = Client::new();
client.add_relay("wss://relay.damus.io").await?;
client.add_relay("wss://nostr.wine").await?;
client.add_relay("wss://relay.rip").await?;
client.connect().await;
let keys = Keys::parse("nsec1ufnus6pju578ste3v90xd5m2decpuzpql2295m3sknqcjzyys9ls0qlc85")?;
let event = EventBuilder::new(Kind::TextNote, "Hello world").finalize(&keys)?;
let output = client.send_event(&event).await?;
println!("Event ID: {}", output.id().to_bech32()?);
println!("Sent to: {:?}", output.success);
println!("Not sent to: {:?}", output.failed);
let unsigned = EventBuilder::new(Kind::TextNote, "POW text note from rust-nostr")
.finalize_unsigned(keys.public_key());
let unsigned = unsigned
.mine_async(&SingleThreadPow, NonZeroU8::new(20).unwrap())
.await?;
let event = unsigned.finalize(&keys)?;
client.send_event(&event).await?;
Ok(())
}