Skip to content

Commit

Permalink
Updates for nostr types (filter fn params)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Oct 8, 2024
1 parent dc43be2 commit 6d3184a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
4 changes: 2 additions & 2 deletions gossip-bin/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ pub fn events_of_pubkey(cmd: Command, mut args: env::Args) -> Result<(), Error>
};

let mut filter = Filter::new();
filter.add_author(&pubkey.into());
filter.add_author(pubkey);
let events = GLOBALS.db().find_events_by_filter(&filter, |_| true)?;

for event in &events {
Expand All @@ -916,7 +916,7 @@ pub fn events_of_pubkey_and_kind(cmd: Command, mut args: env::Args) -> Result<()

let mut filter = Filter::new();
filter.add_event_kind(kind);
filter.add_author(&pubkey.into());
filter.add_author(pubkey);
let events = GLOBALS.db().find_events_by_filter(&filter, |_| true)?;

for event in &events {
Expand Down
5 changes: 2 additions & 3 deletions gossip-bin/src/ui/wizard/wizard_state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gossip_lib::{Person, PersonList, Relay, GLOBALS};
use nostr_types::{Event, EventKind, Filter, PublicKey, PublicKeyHex, RelayUrl};
use nostr_types::{Event, EventKind, Filter, PublicKey, RelayUrl};
use std::{cell::RefCell, collections::HashSet, rc::Rc};

#[derive(PartialEq, Clone, Copy, Debug)]
Expand Down Expand Up @@ -90,9 +90,8 @@ impl WizardState {
self.has_private_key = GLOBALS.identity.is_unlocked();

if let Some(pk) = self.pubkey {
let pkh: PublicKeyHex = pk.into();
let mut filter = Filter::new();
filter.add_author(&pkh);
filter.add_author(pk);

filter.kinds = vec![EventKind::Metadata];
self.metadata_events = GLOBALS
Expand Down
12 changes: 5 additions & 7 deletions gossip-lib/src/overlord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use http::StatusCode;
use nostr_types::{
EncryptedPrivateKey, Event, EventKind, EventReference, Filter, Id, IdHex, Metadata,
MilliSatoshi, NAddr, NostrBech32, PayRequestData, PreEvent, PrivateKey, Profile, PublicKey,
PublicKeyHex, RelayUrl, Tag, UncheckedUrl, Unixtime,
RelayUrl, Tag, UncheckedUrl, Unixtime,
};
use std::collections::HashMap;
use std::sync::atomic::Ordering;
Expand Down Expand Up @@ -1161,7 +1161,7 @@ impl Overlord {

let mut filter = Filter::new();
filter.add_event_kind(EventKind::FollowSets);
filter.add_author(&public_key.into());
filter.add_author(public_key);

// Find all local-storage events that define the list
let bad_events = GLOBALS.db().find_events_by_filter(&filter, |event| {
Expand Down Expand Up @@ -2206,7 +2206,7 @@ impl Overlord {
NostrBech32::NAddr(ea) => {
let mut filter = Filter::new();
filter.add_event_kind(ea.kind);
filter.add_author(&ea.author.into());
filter.add_author(ea.author);

if let Some(event) = GLOBALS
.db()
Expand Down Expand Up @@ -2916,8 +2916,7 @@ impl Overlord {
if posted_outbox == RelayTestResult::Pass {
let mut filter = Filter::new();
filter.add_event_kind(outbox_event.kind);
let pkh: PublicKeyHex = outbox_event.pubkey.into();
filter.add_author(&pkh);
filter.add_author(outbox_event.pubkey);
filter.since = Some(outbox_event.created_at);

let fetch_result = conn
Expand All @@ -2943,8 +2942,7 @@ impl Overlord {

let mut inbox_filter = Filter::new();
inbox_filter.add_event_kind(inbox_event.kind);
let pkh: PublicKeyHex = inbox_event.pubkey.into();
inbox_filter.add_author(&pkh);
inbox_filter.add_author(inbox_event.pubkey);
inbox_filter.since = Some(inbox_event.created_at);

// 4. anon_fetched_inbox
Expand Down
6 changes: 2 additions & 4 deletions gossip-lib/src/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::nostr_connect_server::ParsedCommand;
use crate::people::PersonList;
use crate::relay::Relay;
use crate::storage::Storage;
use nostr_types::{EventKind, Filter, PublicKey, PublicKeyHex, RelayList, RelayUrl, Unixtime};
use nostr_types::{EventKind, Filter, PublicKey, RelayList, RelayUrl, Unixtime};
use parking_lot::RwLock as PRwLock;
use parking_lot::RwLockReadGuard as PRwLockReadGuard;
use std::collections::hash_map::DefaultHasher;
Expand Down Expand Up @@ -227,10 +227,8 @@ impl Pending {
let t30days = 60 * 60 * 24 * 30;
let t90days = 60 * 60 * 24 * 90;

let pkh: PublicKeyHex = mypubkey.into();

let mut filter = Filter::new();
filter.add_author(&pkh);
filter.add_author(mypubkey);
filter.kinds = vec![EventKind::RelayList];
let relay_lists = GLOBALS.db().find_events_by_filter(&filter, |_| true)?;
filter.kinds = vec![EventKind::DmRelayList];
Expand Down
5 changes: 2 additions & 3 deletions gossip-lib/src/storage/fof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::storage::{FollowingsTable, RawDatabase, Storage, Table};
use crate::PersonList;
use heed::types::Bytes;
use heed::RwTxn;
use nostr_types::{EventKind, Filter, PublicKey, PublicKeyHex};
use nostr_types::{EventKind, Filter, PublicKey};
use std::sync::Mutex;

// Pubkey -> u64
Expand Down Expand Up @@ -137,8 +137,7 @@ impl Storage {
.iter()
.map(|(pk, _private)| pk)
{
let pkh: PublicKeyHex = pubkey.into();
filter.add_author(&pkh);
filter.add_author(*pubkey);
}
let contact_lists = self.find_events_by_filter(&filter, |_| true)?;

Expand Down
4 changes: 2 additions & 2 deletions gossip-lib/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ impl Storage {

let mut filter = Filter::new();
filter.add_event_kind(event.kind);
filter.add_author(&event.pubkey.into());
filter.add_author(event.pubkey);
let existing = self.find_events_by_filter(&filter, |e| {
if event.kind.is_parameterized_replaceable() {
e.parameter() == event.parameter()
Expand Down Expand Up @@ -1433,7 +1433,7 @@ impl Storage {

let mut filter = Filter::new();
filter.add_event_kind(kind);
filter.add_author(&pubkey.into());
filter.add_author(pubkey);

Ok(self
.find_events_by_filter(&filter, |e| {
Expand Down

0 comments on commit 6d3184a

Please sign in to comment.