Check https://rust-nostr.org
rust-nostr / hello-nostr Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://rust-nostr.org
Home Page: https://rust-nostr.org
Check https://rust-nostr.org
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
https://ndkit.com/hello-nostr/ is broken.
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.
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);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.