@@ -16,47 +16,58 @@ async fn main() -> Result<()> {
1616 . database ( database)
1717 . build ( ) ;
1818
19- client. add_relay ( "wss://relay.damus.io" ) . await ?;
20- client. add_relay ( "wss://nostr.wine" ) . await ?;
21- client. add_relay ( "wss://nostr.oxtr.dev" ) . await ?;
22-
23- client. connect ( ) . await ;
24-
25- // Publish a text note
26- let builder = EventBuilder :: text_note ( "Hello world" ) ;
27- client. send_event_builder ( builder) . await ?;
28-
29- // Negentropy sync
30- let filter = Filter :: new ( ) . author ( keys. public_key ( ) ) ;
31- let ( tx, mut rx) = SyncProgress :: channel ( ) ;
32- let opts = SyncOptions :: default ( ) . progress ( tx) ;
33-
34- tokio:: spawn ( async move {
35- while rx. changed ( ) . await . is_ok ( ) {
36- let progress = * rx. borrow_and_update ( ) ;
37- if progress. total > 0 {
38- println ! ( "{:.2}%" , progress. percentage( ) * 100.0 ) ;
39- }
40- }
41- } ) ;
42- let output = client. sync ( filter, & opts) . await ?;
43-
44- println ! ( "Local: {}" , output. local. len( ) ) ;
45- println ! ( "Remote: {}" , output. remote. len( ) ) ;
46- println ! ( "Sent: {}" , output. sent. len( ) ) ;
47- println ! ( "Received: {}" , output. received. len( ) ) ;
48- println ! ( "Failures:" ) ;
49- for ( url, map) in output. send_failures . iter ( ) {
50- println ! ( "* '{url}':" ) ;
51- for ( id, e) in map. iter ( ) {
52- println ! ( " - {id}: {e}" ) ;
53- }
54- }
19+ // client.add_relay("wss://relay.damus.io").await?;
20+ // client.add_relay("wss://nostr.wine").await?;
21+ // client.add_relay("wss://nostr.oxtr.dev").await?;
22+ //
23+ // client.connect().await;
24+
25+ // // Publish a text note
26+ // let builder = EventBuilder::text_note("Hello world");
27+ // client.send_event_builder(builder).await?;
28+
29+ // // Negentropy sync
30+ // let filter = Filter::new().author(keys.public_key());
31+ // let (tx, mut rx) = SyncProgress::channel();
32+ // let opts = SyncOptions::default().progress(tx);
33+ //
34+ // tokio::spawn(async move {
35+ // while rx.changed().await.is_ok() {
36+ // let progress = *rx.borrow_and_update();
37+ // if progress.total > 0 {
38+ // println!("{:.2}%", progress.percentage() * 100.0);
39+ // }
40+ // }
41+ // });
42+ // let output = client.sync(filter, &opts).await?;
43+ //
44+ // println!("Local: {}", output.local.len());
45+ // println!("Remote: {}", output.remote.len());
46+ // println!("Sent: {}", output.sent.len());
47+ // println!("Received: {}", output.received.len());
48+ // println!("Failures:");
49+ // for (url, map) in output.send_failures.iter() {
50+ // println!("* '{url}':");
51+ // for (id, e) in map.iter() {
52+ // println!(" - {id}: {e}");
53+ // }
54+ // }
55+ //
56+ // // Query events from database
57+ // let filter = Filter::new().author(keys.public_key()).limit(10);
58+ // let events = client.database().query(filter).await?;
59+ // println!("Events: {events:?}");
5560
56- // Query events from database
57- let filter = Filter :: new ( ) . author ( keys. public_key ( ) ) . limit ( 10 ) ;
58- let events = client. database ( ) . query ( filter) . await ?;
59- println ! ( "Events: {events:?}" ) ;
61+ // Database downcasting
62+ // let database = client.database().clone();
63+ // let upcast = database as Arc<dyn Any + Send + Sync>;
64+ // let lmdb: &NostrLMDB = upcast.downcast_ref().unwrap();
65+ //let lmdb: &NostrLMDB = (database as &dyn Any).downcast_ref::<NostrLMDB>().unwrap();
66+
67+ // Database downcasting to access to specific APIs
68+ if let Some ( _lmdb) = client. database ( ) . downcast_ref :: < NostrLMDB > ( ) {
69+ // Access specific APIs here
70+ }
6071
6172 Ok ( ( ) )
6273}
0 commit comments