Skip to content

Commit

Permalink
Fix error when connecting to other relays
Browse files Browse the repository at this point in the history
Basically it was because if some field from a `Filter` is not
being used, it should not be serialized and sent to the relay.

Before it was being sent as null, therefore for some fields like
`ids` that would expect an array, it would incur on an error.
  • Loading branch information
Guilospanck committed Jun 12, 2023
1 parent 2ef51e3 commit b3e7bcf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ It is working. The problem was with sending the message as BINARY to the client.
- [x] [CLIENT] Should save its own filters in order to request data from different relays.
- [x] [CLIENT] Must validate signature.
- [ ] [CLIENT] Disconnect from relay.
- [ ] [CLIENT] Add reply/comment function.
- [ ] [CLIENT] Add retweet function.
- [ ] [CLIENT/RELAY] Finish the implementation of all the required NIPs (just `NIP01`)
- [-] [CLIENT] ~~Should have a way of handling duplicated events, since a client can be connected to multiple relays~~ To be used when calling from a frontend or whatnot.

Expand Down
10 changes: 6 additions & 4 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ async fn main() {
let mut client = client::Client::new();
client.connect().await;
client.get_notifications().await;
// client.follow_author(String::from("82341f882b6eabcd2ba7f1ef90aad961cf074af15b9ef44a09f9d2a8fbfbe6a2")).await; // jack's pubkey
client.follow_myself().await;
client.follow_author(String::from("82341f882b6eabcd2ba7f1ef90aad961cf074af15b9ef44a09f9d2a8fbfbe6a2")).await; // jack's pubkey
// client.follow_myself().await;
client
.name("Nostr Client")
.about("This is a nostr client")
.picture("someurl.image.com")
.send_updated_metadata().await;
client.add_relay(String::from("wss://relay.damus.io")).await;
client.subscribe_to_all_stored_requests().await;
// client.add_relay(String::from("wss://nostr.wine")).await;
client.add_relay(String::from("wss://pow.nostrati.com")).await;
// client.subscribe_to_all_stored_requests().await;
// client.unsubscribe("d8e67092-c17f-4934-8b7d-6c97cb697cc1").await;
// client.publish_text_note("hello, potato".to_string()).await;
// client.publish_text_note("TESTING!!!".to_string()).await;

let ctrl_c = async {
tokio::signal::ctrl_c().await.unwrap();
Expand Down
10 changes: 8 additions & 2 deletions nostr-sdk/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ use crate::event::{id::EventId, kind::EventKind, PubKey, Timestamp};
///
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq)]
pub struct Filter {
#[serde(skip_serializing_if="Option::is_none")]
pub ids: Option<Vec<EventId>>,
#[serde(skip_serializing_if="Option::is_none")]
pub authors: Option<Vec<PubKey>>,
#[serde(skip_serializing_if="Option::is_none")]
pub kinds: Option<Vec<EventKind>>,
#[serde(alias = "#e", rename(serialize = "#e"))]
#[serde(alias = "#e", rename(serialize = "#e"), skip_serializing_if="Option::is_none")]
pub e: Option<Vec<String>>,
#[serde(alias = "#p", rename(serialize = "#p"))]
#[serde(alias = "#p", rename(serialize = "#p"), skip_serializing_if="Option::is_none")]
pub p: Option<Vec<String>>,
#[serde(skip_serializing_if="Option::is_none")]
pub since: Option<Timestamp>,
#[serde(skip_serializing_if="Option::is_none")]
pub until: Option<Timestamp>,
#[serde(skip_serializing_if="Option::is_none")]
pub limit: Option<Timestamp>,
}

Expand Down

0 comments on commit b3e7bcf

Please sign in to comment.