Giter Site home page Giter Site logo

hello-nostr's People

Contributors

mgravitt avatar yukibtc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

hello-nostr's Issues

`get_events_of` does not return event

When publishing an event and immediately trying to retrieve it, I do not get any results. I believe it just sits on the get_events_of line.

How do I changed it (code is currently pushed to this repo) to retrieve the event that was just submitted and then exit?

 let event = client.publish_text_note(message, &[]).await?;
    println!("{:#?}", event);

    let filter = Filter {
        ids: Some(vec![event.to_string()]),
        authors: None,
        kinds: None,
        events: None,
        pubkeys: None,
        hashtags: None,
        references: None,
        search: None,
        since: None,
        until: None,
        limit: None,
    };

    let events = client.get_events_of(vec![filter], None).await?;
    println!("{:#?}", events);

The tutorial needs updating to match the latest SDK

Hello Nostr

This is what I finally got to work.

use std::{str::FromStr, time::Duration, collections::{HashSet, HashMap}};
use nostr_sdk::prelude::*;
use tokio::time;

const PRIVATE_KEY: &str = "PRIVATE KEY";

#[tokio::main]
async fn main() -> Result<()> {

    let secret_key = SecretKey::from_str(PRIVATE_KEY).unwrap();
    let my_keys = Keys::new(secret_key);

    let client = Client::new(&my_keys);
    client.add_relay("wss://relay.house", None).await?;
    client.add_relay("wss://relay.damus.io", None).await?;
    client.connect().await;

    let message = format!("Hello, nostr! My public key is: {}", my_keys.public_key().to_string());
    println!("{}", message);

    let event = client.publish_text_note(message, &[]).await?;
    println!("{:#?}", event);

    // Retrieve only our last event (from both relays)
    // let filter = Filter::new().id(event);

    // Retrieve all the events that we have posted
    let ids = HashSet::from([event]);
    let authors = HashSet::from([my_keys.public_key()]);
    let kinds = HashSet::new();
    let generic_tags: HashMap<Alphabet, HashSet<String>> = HashMap::new();

    let filter = Filter {
        ids,
        authors,
        kinds,
        generic_tags,
        search: None,
        since: None,
        until: None,
        limit: None,
    };        
    time::sleep(Duration::from_secs(1)).await;

    let events = client.get_events_of(vec![filter], None).await?;
    println!("{:#?}", events);

    Ok(())
}

The tutorial also needs to add the imports as it goes along.

error in code once i add #better filtering via tutorial

my code compiles just fine following the tutorial except when i get to #better filtering i receive the following compile errors:

error[E0308]: mismatched types
--> src/main.rs:30:28
|
30 | authors: Some(vec![my_keys.public_key()]),
| ^^^^^^^^^^^^^^^^^^^^- help: try using a conversion method: .to_string()
| |
| expected String, found XOnlyPublicKey

error[E0063]: missing fields custom and identifiers in initializer of nostr_sdk::Filter
--> src/main.rs:28:18
|
28 | let filter = Filter {
| ^^^^^^ missing custom and identifiers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.