diff --git a/Cargo.lock b/Cargo.lock index 451f53eb..9d663fa1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2240,7 +2240,7 @@ dependencies = [ [[package]] name = "gossip-relay-picker" version = "0.2.0-unstable" -source = "git+https://github.com/mikedilger/gossip-relay-picker?rev=7fa49bdab37c042a839bc2f1cf17cf30120c36f9#7fa49bdab37c042a839bc2f1cf17cf30120c36f9" +source = "git+https://github.com/mikedilger/gossip-relay-picker?rev=c04ed85ef3ca95cd4083d8f2b7eac497a332b9f6#c04ed85ef3ca95cd4083d8f2b7eac497a332b9f6" dependencies = [ "async-trait", "dashmap", @@ -3233,7 +3233,7 @@ dependencies = [ [[package]] name = "nostr-types" version = "0.8.0-unstable" -source = "git+https://github.com/mikedilger/nostr-types?rev=9589c9223c7e775891d314849c5359c3d4f327b0#9589c9223c7e775891d314849c5359c3d4f327b0" +source = "git+https://github.com/mikedilger/nostr-types?rev=45fde646b9f8d8e4c330ba52120b445535fc1dfd#45fde646b9f8d8e4c330ba52120b445535fc1dfd" dependencies = [ "aes", "base64 0.22.1", diff --git a/gossip-bin/Cargo.toml b/gossip-bin/Cargo.toml index c12d0023..cd59e963 100644 --- a/gossip-bin/Cargo.toml +++ b/gossip-bin/Cargo.toml @@ -25,13 +25,13 @@ egui-winit = { git = "https://github.com/bu5hm4nn/egui", rev = "63dde4c9b311da0c egui_extras = { git = "https://github.com/bu5hm4nn/egui", rev = "63dde4c9b311da0cae0cb9f9465bf7273227be6c", features = [ "syntect" ] } #egui = { git = "https://github.com/bu5hm4nn/egui", rev = "63dde4c9b311da0cae0cb9f9465bf7273227be6c", features = [ "deadlock_detection" ] } egui-video = { git = "https://github.com/mikedilger/egui-video", rev = "97f58f88dfe912697393567830d0751676492a89", features = [ "from_bytes" ], optional = true } -gossip-relay-picker = { git = "https://github.com/mikedilger/gossip-relay-picker", rev = "7fa49bdab37c042a839bc2f1cf17cf30120c36f9" } +gossip-relay-picker = { git = "https://github.com/mikedilger/gossip-relay-picker", rev = "c04ed85ef3ca95cd4083d8f2b7eac497a332b9f6" } gossip-lib = { path = "../gossip-lib" } humansize = "2.1" image = { version = "0.24.6", features = [ "png", "jpeg" ] } lazy_static = "1.4" memoize = "0.4" -nostr-types = { git = "https://github.com/mikedilger/nostr-types", rev = "9589c9223c7e775891d314849c5359c3d4f327b0", features = [ "speedy" ] } +nostr-types = { git = "https://github.com/mikedilger/nostr-types", rev = "45fde646b9f8d8e4c330ba52120b445535fc1dfd", features = [ "speedy" ] } paste = "1.0" qrcode = { git = "https://github.com/mikedilger/qrcode-rust", rev = "519b77b3efa3f84961169b47d3de08c5ddd86548" } resvg = "0.35.0" diff --git a/gossip-bin/src/commands.rs b/gossip-bin/src/commands.rs index 1aeec029..b69e01a5 100644 --- a/gossip-bin/src/commands.rs +++ b/gossip-bin/src/commands.rs @@ -313,7 +313,7 @@ pub fn add_person_list(cmd: Command, mut args: env::Args) -> Result<(), Error> { } pub fn backdate_eose() -> Result<(), Error> { - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let ago = (now.0 - 60 * 60 * 24) as u64; GLOBALS.storage.modify_all_relays( @@ -573,7 +573,7 @@ pub fn delete_spam_by_content( let public_key = GLOBALS.identity.public_key().unwrap(); let pre_event = PreEvent { pubkey: public_key, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::EventDeletion, tags, content: "spam".to_owned(), @@ -917,7 +917,7 @@ pub fn reprocess_recent(_cmd: Command, runtime: &Runtime) -> Result<(), Error> { login()?; let job = tokio::task::spawn(async move { - let mut ago = Unixtime::now().unwrap(); + let mut ago = Unixtime::now(); ago.0 -= 86400; let mut filter = Filter::new(); diff --git a/gossip-bin/src/date_ago.rs b/gossip-bin/src/date_ago.rs index fd26af9d..f392764d 100644 --- a/gossip-bin/src/date_ago.rs +++ b/gossip-bin/src/date_ago.rs @@ -1,7 +1,7 @@ use nostr_types::Unixtime; pub fn date_ago(then: Unixtime) -> String { - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let seconds = now.0 - then.0; let minutes: f32 = seconds as f32 / 60.0; let hours: f32 = minutes / 60.0; diff --git a/gossip-bin/src/ui/people/list.rs b/gossip-bin/src/ui/people/list.rs index 6b90be64..08af6cd9 100644 --- a/gossip-bin/src/ui/people/list.rs +++ b/gossip-bin/src/ui/people/list.rs @@ -654,7 +654,7 @@ pub(super) fn render_create_list_dialog(ui: &mut Ui, app: &mut GossipUi) { { app.new_list_name = app.new_list_name.trim().into(); if !app.new_list_name.is_empty() { - let dtag = format!("pl{}", Unixtime::now().unwrap().0); + let dtag = format!("pl{}", Unixtime::now().0); let metadata = PersonListMetadata { dtag, title: app.new_list_name.to_owned(), diff --git a/gossip-bin/src/ui/widgets/relay_entry.rs b/gossip-bin/src/ui/widgets/relay_entry.rs index 2143d538..b9e203f3 100644 --- a/gossip-bin/src/ui/widgets/relay_entry.rs +++ b/gossip-bin/src/ui/widgets/relay_entry.rs @@ -313,13 +313,9 @@ impl RelayEntry { // show remaining time on timeout if let Some(timeout) = self.timeout_until { let color = egui::Color32::from_rgb(0xf4, 0xbf, 0x4f); // orange - if let Ok(now) = Unixtime::now() { - let remain = timeout - now.0; - let text = format!("Timeout, retry in {} seconds", remain); - (color, text) - } else { - (color, "Timeout, retry soon".to_string()) - } + let remain = timeout - Unixtime::now().0; + let text = format!("Timeout, retry in {} seconds", remain); + (color, text) } else { (egui::Color32::GRAY, "Not connected".to_string()) } diff --git a/gossip-lib/Cargo.toml b/gossip-lib/Cargo.toml index 268bf029..0bd75353 100644 --- a/gossip-lib/Cargo.toml +++ b/gossip-lib/Cargo.toml @@ -50,7 +50,7 @@ fallible-iterator = "0.2" filetime = "0.2" futures = "0.3" futures-util = "0.3" -gossip-relay-picker = { git = "https://github.com/mikedilger/gossip-relay-picker", rev = "7fa49bdab37c042a839bc2f1cf17cf30120c36f9" } +gossip-relay-picker = { git = "https://github.com/mikedilger/gossip-relay-picker", rev = "c04ed85ef3ca95cd4083d8f2b7eac497a332b9f6" } heed = "0.20" hex = "0.4" http = "1.0" @@ -59,7 +59,7 @@ kamadak-exif = "0.5" lazy_static = "1.4" linkify = "0.10" mime = "0.3" -nostr-types = { git = "https://github.com/mikedilger/nostr-types", rev = "9589c9223c7e775891d314849c5359c3d4f327b0", features = [ "speedy" ] } +nostr-types = { git = "https://github.com/mikedilger/nostr-types", rev = "45fde646b9f8d8e4c330ba52120b445535fc1dfd", features = [ "speedy" ] } parking_lot = "0.12" paste = "1.0" rand = "0.8" diff --git a/gossip-lib/src/bookmarks.rs b/gossip-lib/src/bookmarks.rs index 8c93e926..5f5367a9 100644 --- a/gossip-lib/src/bookmarks.rs +++ b/gossip-lib/src/bookmarks.rs @@ -147,7 +147,7 @@ impl BookmarkList { let pre_event = PreEvent { pubkey: public_key, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::BookmarkList, tags, content, diff --git a/gossip-lib/src/feed/mod.rs b/gossip-lib/src/feed/mod.rs index b1b27b3b..93e722d8 100644 --- a/gossip-lib/src/feed/mod.rs +++ b/gossip-lib/src/feed/mod.rs @@ -79,7 +79,7 @@ impl Feed { let anchor_key = self.current_feed_kind.read().anchor_key(); match self.feed_anchors.get(&anchor_key) { Some(r) => *r, - None => Unixtime::now().unwrap(), + None => Unixtime::now(), } } @@ -124,7 +124,7 @@ impl Feed { Some(refanchor) => *refanchor, None => { // Start the feed anchor if it was not yet set - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); self.feed_anchors.insert(anchor_key, now); now } @@ -390,7 +390,7 @@ impl Feed { where F: Fn(&Event) -> bool, { - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let limit = GLOBALS.storage.read_setting_load_more_count() as usize; let dismissed = GLOBALS.dismissed.read().await.clone(); @@ -424,7 +424,7 @@ impl Feed { #[inline] fn basic_screen(e: &Event, include_replies: bool, include_dms: bool, dismissed: &[Id]) -> bool { - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); e.created_at <= now && (include_replies || e.replies_to().is_none()) diff --git a/gossip-lib/src/fetcher.rs b/gossip-lib/src/fetcher.rs index 1d5ef16a..e22bdad0 100644 --- a/gossip-lib/src/fetcher.rs +++ b/gossip-lib/src/fetcher.rs @@ -104,7 +104,7 @@ impl Fetcher { } } - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let mut count = 0; @@ -512,7 +512,7 @@ impl Fetcher { } fn sinbin(&self, url: &Url, duration: Duration) { - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let later = now + duration; let host = match self.host(url) { Some(h) => h, diff --git a/gossip-lib/src/nip05.rs b/gossip-lib/src/nip05.rs index 188a0013..b303a664 100644 --- a/gossip-lib/src/nip05.rs +++ b/gossip-lib/src/nip05.rs @@ -11,7 +11,7 @@ pub async fn validate_nip05(person: Person) -> Result<(), Error> { return Ok(()); } - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); // invalid if their nip-05 is not set if person.metadata().is_none() @@ -113,12 +113,7 @@ pub async fn get_and_follow_nip05( // Save person GLOBALS .people - .upsert_nip05_validity( - &pubkey, - Some(nip05.clone()), - true, - Unixtime::now().unwrap().0 as u64, - ) + .upsert_nip05_validity(&pubkey, Some(nip05.clone()), true, Unixtime::now().0 as u64) .await?; update_relays(&nip05, nip05file, &pubkey).await?; diff --git a/gossip-lib/src/nip46.rs b/gossip-lib/src/nip46.rs index ab965b79..27d6e7cb 100644 --- a/gossip-lib/src/nip46.rs +++ b/gossip-lib/src/nip46.rs @@ -76,7 +76,7 @@ impl Approval { true } Approval::Until(time) => { - let approved = Unixtime::now().unwrap() < *time; + let approved = Unixtime::now() < *time; if !approved { *self = Approval::None; } @@ -221,7 +221,7 @@ impl Nip46Server { let pre_event: PreEvent = PreEvent { pubkey: public_key, - created_at: created_at.unwrap_or(Unixtime::now().unwrap()), + created_at: created_at.unwrap_or(Unixtime::now()), kind, tags, content, @@ -310,7 +310,7 @@ pub struct Nip46PreEvent { } fn default_now() -> Option { - Some(Unixtime::now().unwrap()) + Some(Unixtime::now()) } #[derive(Debug, Clone, Hash, PartialEq)] @@ -405,7 +405,7 @@ fn send_response( let pre_event = PreEvent { pubkey: public_key, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::NostrConnect, tags: vec![Tag::new_pubkey(peer_pubkey, None, None)], content: e, diff --git a/gossip-lib/src/overlord/minion/handle_websocket.rs b/gossip-lib/src/overlord/minion/handle_websocket.rs index a47c9bd8..857dd98d 100644 --- a/gossip-lib/src/overlord/minion/handle_websocket.rs +++ b/gossip-lib/src/overlord/minion/handle_websocket.rs @@ -123,7 +123,7 @@ impl Minion { } if handle == "general_feed" { // Update last general EOSE - let now = Unixtime::now().unwrap().0 as u64; + let now = Unixtime::now().0 as u64; self.dbrelay.last_general_eose_at = Some(match self.dbrelay.last_general_eose_at { Some(old) => old.max(now), @@ -180,7 +180,7 @@ impl Minion { GLOBALS.storage.add_event_seen_on_relay( id, &self.url, - Unixtime::now().unwrap(), + Unixtime::now(), None, )?; } else { @@ -309,7 +309,7 @@ impl Minion { // cork and retry once auth completes self.subscriptions_waiting_for_auth - .insert(handle, Unixtime::now().unwrap()); + .insert(handle, Unixtime::now()); // return now, don't remove sub from map return Ok(()); @@ -317,7 +317,7 @@ impl Minion { AuthState::Waiting(_) => { // cork and retry once auth completes self.subscriptions_waiting_for_auth - .insert(handle, Unixtime::now().unwrap()); + .insert(handle, Unixtime::now()); // return now, don't remove sub from map return Ok(()); diff --git a/gossip-lib/src/overlord/minion/mod.rs b/gossip-lib/src/overlord/minion/mod.rs index 026dc52a..a192a0e1 100644 --- a/gossip-lib/src/overlord/minion/mod.rs +++ b/gossip-lib/src/overlord/minion/mod.rs @@ -190,7 +190,7 @@ impl Minion { let websocket_stream = { // Fetch NIP-11 data (if not fetched recently) if let Some(last_nip11) = self.dbrelay.last_attempt_nip11 { - if last_nip11 as i64 + 3600 < Unixtime::now().unwrap().0 { + if last_nip11 as i64 + 3600 < Unixtime::now().0 { if let Err(e) = self.fetch_nip11(fetcher_timeout).await { if matches!(e.kind, ErrorKind::ShuttingDown) { return Ok(MinionExitReason::GotShutdownMessage); @@ -393,7 +393,7 @@ impl Minion { } } - self.dbrelay.last_attempt_nip11 = Some(Unixtime::now().unwrap().0 as u64); + self.dbrelay.last_attempt_nip11 = Some(Unixtime::now().0 as u64); let status = response.status(); match Self::text_with_charset(response, "utf-8").await { Ok(text) => { @@ -514,7 +514,7 @@ impl Minion { && self.subscriptions_waiting_for_metadata.is_empty() && self.posting_jobs.is_empty() { - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); if let Some(when) = self.subscriptions_empty_asof { if now - when > Duration::from_secs(10) { // Exit as we have been idle 30 seconds without subscriptions @@ -817,7 +817,7 @@ impl Minion { // Subscribe to the user's config (config, DMs, etc) which is on their own write relays async fn subscribe_config(&mut self, job_id: u64) -> Result<(), Error> { - let since = Unixtime::now().unwrap() - Duration::from_secs(60 * 60 * 24 * 15); + let since = Unixtime::now() - Duration::from_secs(60 * 60 * 24 * 15); let filters = filter_fns::config(since); @@ -1075,7 +1075,7 @@ impl Minion { if self.auth_state == AuthState::Authenticated { // Apply subscriptions that were waiting for auth let mut handles = std::mem::take(&mut self.subscriptions_waiting_for_auth); - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); for (handle, when) in handles.drain() { // Do not try if we just inserted it within the last second if when - now < Duration::from_secs(1) { @@ -1199,7 +1199,7 @@ impl Minion { // our fault the subscription is getting cut off. This way we will pick up // where we left off instead of potentially loading a bunch of events // yet again. - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); // Update last general EOSE self.dbrelay.last_general_eose_at = Some(match self.dbrelay.last_general_eose_at { @@ -1234,7 +1234,7 @@ impl Minion { if matches!(self.auth_state, AuthState::Waiting(_)) { // Save this, subscribe after AUTH completes self.subscriptions_waiting_for_auth - .insert(handle.to_owned(), Unixtime::now().unwrap()); + .insert(handle.to_owned(), Unixtime::now()); return Ok(()); } @@ -1311,7 +1311,7 @@ impl Minion { }; let pre_event = PreEvent { pubkey, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::Auth, tags: vec![ Tag::new(&["relay", self.url.as_str()]), @@ -1372,7 +1372,7 @@ impl Minion { } async fn bump_success_count(&mut self, also_bump_last_connected: bool) { - let now = Unixtime::now().unwrap().0 as u64; + let now = Unixtime::now().0 as u64; // Update in self self.dbrelay.success_count += 1; diff --git a/gossip-lib/src/overlord/mod.rs b/gossip-lib/src/overlord/mod.rs index 35d679f1..75e4f839 100644 --- a/gossip-lib/src/overlord/mod.rs +++ b/gossip-lib/src/overlord/mod.rs @@ -560,7 +560,7 @@ impl Overlord { // Record the exclusion in the relay record if let Ok(Some(mut relay)) = GLOBALS.storage.read_relay(&url, None) { - let until = Unixtime::now().unwrap() + Duration::from_secs(exclusion); + let until = Unixtime::now() + Duration::from_secs(exclusion); relay.avoid_until = Some(until); let _ = GLOBALS.storage.write_relay(&relay, None); } @@ -861,7 +861,7 @@ impl Overlord { let pre_event = PreEvent { pubkey: public_key, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::RelayList, tags, content: "".to_string(), @@ -881,7 +881,7 @@ impl Overlord { let pre_event = PreEvent { pubkey: public_key, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::DmRelayList, tags, content: "".to_string(), @@ -1215,7 +1215,7 @@ impl Overlord { let pre_event = PreEvent { pubkey: public_key, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::EventDeletion, tags, content: "Deleting person list".to_owned(), @@ -1293,7 +1293,7 @@ impl Overlord { let pre_event = PreEvent { pubkey: public_key, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::EventDeletion, tags, content: "".to_owned(), // FIXME, option to supply a delete reason @@ -1476,7 +1476,7 @@ impl Overlord { nprofile.pubkey, &relay_url, |pr| { - pr.last_suggested = Some(Unixtime::now().unwrap().0 as u64); + pr.last_suggested = Some(Unixtime::now().0 as u64); }, None, )? @@ -1595,7 +1595,7 @@ impl Overlord { let pre_event = PreEvent { pubkey: public_key, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::Reaction, tags, content: "+".to_owned(), @@ -1913,7 +1913,7 @@ impl Overlord { .write() .write("Pruning database, please be patient..".to_owned()); - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let then = now - Duration::new( GLOBALS.storage.read_setting_prune_period_days() * 60 * 60 * 24, @@ -1972,7 +1972,7 @@ impl Overlord { let pre_event = PreEvent { pubkey: public_key, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::Metadata, tags: vec![], content: serde_json::to_string(&metadata)?, @@ -2121,7 +2121,7 @@ impl Overlord { let pre_event = PreEvent { pubkey: public_key, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind, tags, content: serde_json::to_string(&reposted_event)?, @@ -2656,7 +2656,7 @@ impl Overlord { // Mark for each person that we are seeking their relay list // so that we don't repeat this for a while - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let mut txn = GLOBALS.storage.get_write_txn()?; for pk in pubkeys.iter() { PersonTable::modify(*pk, |p| p.relay_list_last_sought = now.0, Some(&mut txn))?; @@ -2687,7 +2687,7 @@ impl Overlord { /// Subscribe to the user's configuration events from the given relay pub async fn subscribe_inbox(&mut self, relays: Option>) -> Result<(), Error> { - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let mention_relays: Vec = match relays { Some(r) => r, None => Relay::choose_relay_urls(Relay::READ, |_| true)?, @@ -2716,7 +2716,7 @@ impl Overlord { .filter_relays(|r| r.has_usage_bits(Relay::DM) || r.has_usage_bits(Relay::INBOX))?; // 30 days worth (FIXME make this a setting?) - let after = Unixtime::now().unwrap() - Duration::new(3600 * 24 * 30, 0); + let after = Unixtime::now() - Duration::new(3600 * 24 * 30, 0); for relay in relays.iter() { self.engage_minion( @@ -2879,7 +2879,7 @@ impl Overlord { } }; - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let mut txn = GLOBALS.storage.get_write_txn()?; @@ -3356,7 +3356,7 @@ impl Overlord { // Generate the zap request event let pre_event = PreEvent { pubkey: user_pubkey, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::ZapRequest, tags: vec![ Tag::new_event(id, None, None), diff --git a/gossip-lib/src/pending.rs b/gossip-lib/src/pending.rs index 6c564844..b9de3813 100644 --- a/gossip-lib/src/pending.rs +++ b/gossip-lib/src/pending.rs @@ -223,7 +223,7 @@ impl Pending { None => return Ok(()), // nothing pending if no identity }; - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let t30days = 60 * 60 * 24 * 30; let t90days = 60 * 60 * 24 * 90; diff --git a/gossip-lib/src/people.rs b/gossip-lib/src/people.rs index 27ccb175..7926944c 100644 --- a/gossip-lib/src/people.rs +++ b/gossip-lib/src/people.rs @@ -108,7 +108,7 @@ impl People { /// Get all the pubkeys that need relay lists (from the given set) pub fn get_subscribed_pubkeys_needing_relay_lists(&self) -> Vec { - let stale = Unixtime::now().unwrap().0 + let stale = Unixtime::now().0 - 60 * GLOBALS .storage .read_setting_relay_list_becomes_stale_minutes() as i64; @@ -125,7 +125,7 @@ impl People { /// Get if a person needs a relay list pub fn person_needs_relay_list(pubkey: PublicKey) -> Freshness { - let staletime = Unixtime::now().unwrap().0 + let staletime = Unixtime::now().0 - 60 * GLOBALS .storage .read_setting_relay_list_becomes_stale_minutes() as i64; @@ -175,7 +175,7 @@ impl People { /// The overlord calls this to indicate that it is fetching metadata /// for this person from relays pub fn metadata_fetch_initiated(&self, pubkeys: &[PublicKey]) { - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); for pubkey in pubkeys { self.fetching_metadata.insert(*pubkey, now); } @@ -199,7 +199,7 @@ impl People { ); } - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let stale = Duration::from_secs( 60 * GLOBALS .storage @@ -274,7 +274,7 @@ impl People { // Sync in from database first self.create_all_if_missing(&[*pubkey])?; - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); // Copy the person let mut person = @@ -335,7 +335,7 @@ impl People { .read_setting_nip05_becomes_stale_if_invalid_minutes(), ) }; - Unixtime::now().unwrap() - Unixtime(last as i64) > recheck_duration + Unixtime::now() - Unixtime(last as i64) > recheck_duration } else { true } @@ -701,7 +701,7 @@ impl People { let pre_event = PreEvent { pubkey: my_pubkey, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind, tags: public_tags, content, @@ -789,7 +789,7 @@ impl People { .storage .get_person_list_metadata(PersonList::Muted)? { - metadata.last_edit_time = Unixtime::now().unwrap(); + metadata.last_edit_time = Unixtime::now(); GLOBALS.storage.set_person_list_metadata( PersonList::Muted, &metadata, @@ -833,7 +833,7 @@ impl People { } pub(crate) async fn update_nip05_last_checked(&self, pubkey: PublicKey) -> Result<(), Error> { - let now = Unixtime::now().unwrap().0; + let now = Unixtime::now().0; PersonTable::modify( pubkey, diff --git a/gossip-lib/src/post.rs b/gossip-lib/src/post.rs index 0d1d2cc7..61185fc2 100644 --- a/gossip-lib/src/post.rs +++ b/gossip-lib/src/post.rs @@ -29,7 +29,7 @@ pub fn prepare_post_normal( let pre_event = PreEvent { pubkey: author, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::TextNote, tags, content, @@ -95,7 +95,7 @@ pub fn prepare_post_nip04( let pre_event = PreEvent { pubkey: author, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::EncryptedDirectMessage, tags, content, @@ -156,7 +156,7 @@ pub fn prepare_post_nip17( let pre_event = PreEvent { pubkey: author, - created_at: Unixtime::now().unwrap(), + created_at: Unixtime::now(), kind: EventKind::DmChat, tags, content, diff --git a/gossip-lib/src/process.rs b/gossip-lib/src/process.rs index 0845e2e3..3eabf6d3 100644 --- a/gossip-lib/src/process.rs +++ b/gossip-lib/src/process.rs @@ -26,7 +26,7 @@ pub async fn process_new_event( verify: bool, process_even_if_duplicate: bool, ) -> Result<(), Error> { - let now = Unixtime::now()?; + let now = Unixtime::now(); // Bump count GLOBALS.events_processed.fetch_add(1, Ordering::SeqCst); diff --git a/gossip-lib/src/seeker.rs b/gossip-lib/src/seeker.rs index 22607d1c..54ff9173 100644 --- a/gossip-lib/src/seeker.rs +++ b/gossip-lib/src/seeker.rs @@ -29,7 +29,7 @@ pub struct SeekData { impl SeekData { fn new_event(climb: bool) -> SeekData { SeekData { - start: Unixtime::now().unwrap(), + start: Unixtime::now(), state: SeekState::WaitingEvent, climb, } @@ -37,7 +37,7 @@ impl SeekData { fn new_relay_list(pubkey: PublicKey, climb: bool) -> SeekData { SeekData { - start: Unixtime::now().unwrap(), + start: Unixtime::now(), state: SeekState::WaitingRelayList(pubkey), climb, } @@ -236,7 +236,7 @@ impl Seeker { // we save updates here and apply when the iterator is finished. let mut updates: Vec<(Id, Option)> = Vec::new(); - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); for refmulti in self.events.iter() { let id = *refmulti.key(); diff --git a/gossip-lib/src/storage/event_akci_index.rs b/gossip-lib/src/storage/event_akci_index.rs index 08a240a8..d8284edd 100644 --- a/gossip-lib/src/storage/event_akci_index.rs +++ b/gossip-lib/src/storage/event_akci_index.rs @@ -84,7 +84,7 @@ mod test { fn test_event_akci_key() { let pubkey = PrivateKey::generate().public_key(); let kind = EventKind::TextNote; - let created_at = Unixtime::now().unwrap(); + let created_at = Unixtime::now(); let id = Id::try_from_hex_string( "77f7653c67147a125cc624f695029d0557e3ab402e714680eb23dd2499f439a0", ) diff --git a/gossip-lib/src/storage/event_kci_index.rs b/gossip-lib/src/storage/event_kci_index.rs index eb3a9c02..d4e10edf 100644 --- a/gossip-lib/src/storage/event_kci_index.rs +++ b/gossip-lib/src/storage/event_kci_index.rs @@ -88,7 +88,7 @@ mod test { #[test] fn test_event_kci_key() { let kind = EventKind::TextNote; - let created_at = Unixtime::now().unwrap(); + let created_at = Unixtime::now(); let id = Id::try_from_hex_string( "77f7653c67147a125cc624f695029d0557e3ab402e714680eb23dd2499f439a0", ) diff --git a/gossip-lib/src/storage/migrations/m19.rs b/gossip-lib/src/storage/migrations/m19.rs index d8e100b8..73f43cc8 100644 --- a/gossip-lib/src/storage/migrations/m19.rs +++ b/gossip-lib/src/storage/migrations/m19.rs @@ -57,7 +57,7 @@ impl Storage { last_edit_times .get(&list) .copied() - .unwrap_or(Unixtime::now().unwrap().0), + .unwrap_or(Unixtime::now().0), ), ..Default::default() }; diff --git a/gossip-lib/src/storage/migrations/m20.rs b/gossip-lib/src/storage/migrations/m20.rs index ef687088..c7c6d690 100644 --- a/gossip-lib/src/storage/migrations/m20.rs +++ b/gossip-lib/src/storage/migrations/m20.rs @@ -221,7 +221,7 @@ impl Storage { .into()); } - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); let mut ids: HashSet = HashSet::new(); let txn = self.env.read_txn()?; diff --git a/gossip-lib/src/storage/mod.rs b/gossip-lib/src/storage/mod.rs index 604687e1..16c83fb4 100644 --- a/gossip-lib/src/storage/mod.rs +++ b/gossip-lib/src/storage/mod.rs @@ -833,7 +833,7 @@ impl Storage { None => return Err(ErrorKind::ListNotFound.into()), }; md.title = newname; - md.last_edit_time = Unixtime::now().unwrap(); + md.last_edit_time = Unixtime::now(); self.set_person_list_metadata(list, &md, rw_txn)?; Ok(()) } @@ -2112,7 +2112,7 @@ impl Storage { write: bool, min: usize, ) -> Result, Error> { - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); // Load person relays, filtering out banned URLs let mut person_relays: Vec = self @@ -2499,7 +2499,7 @@ impl Storage { ) -> Result<(), Error> { let f = |txn: &mut RwTxn<'a>| -> Result<(), Error> { self.clear_person_list2(list, Some(txn))?; - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); if let Some(mut metadata) = self.get_person_list_metadata(list)? { metadata.last_edit_time = now; metadata.len = 0; @@ -2553,7 +2553,7 @@ impl Storage { let had = map.contains_key(&list); map.insert(list, private); self.write_person_lists(pubkey, map, Some(txn))?; - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); if let Some(mut metadata) = self.get_person_list_metadata(list)? { if !had { metadata.len += 1; @@ -2580,7 +2580,7 @@ impl Storage { let had = map.contains_key(&list); map.remove(&list); self.write_person_lists(pubkey, map, Some(txn))?; - let now = Unixtime::now().unwrap(); + let now = Unixtime::now(); if let Some(mut metadata) = self.get_person_list_metadata(list)? { if had && metadata.len > 0 { metadata.len -= 1; diff --git a/gossip-lib/src/storage/types/person_list_metadata1.rs b/gossip-lib/src/storage/types/person_list_metadata1.rs index 69ae99e4..a041ff87 100644 --- a/gossip-lib/src/storage/types/person_list_metadata1.rs +++ b/gossip-lib/src/storage/types/person_list_metadata1.rs @@ -16,7 +16,7 @@ impl Default for PersonListMetadata1 { PersonListMetadata1 { dtag: "".to_owned(), title: "".to_owned(), - last_edit_time: Unixtime::now().unwrap(), + last_edit_time: Unixtime::now(), event_created_at: Unixtime(0), event_public_len: 0, event_private_len: None, diff --git a/gossip-lib/src/storage/types/person_list_metadata2.rs b/gossip-lib/src/storage/types/person_list_metadata2.rs index 169ea2da..851bc351 100644 --- a/gossip-lib/src/storage/types/person_list_metadata2.rs +++ b/gossip-lib/src/storage/types/person_list_metadata2.rs @@ -19,7 +19,7 @@ impl Default for PersonListMetadata2 { PersonListMetadata2 { dtag: "".to_owned(), title: "".to_owned(), - last_edit_time: Unixtime::now().unwrap(), + last_edit_time: Unixtime::now(), event_created_at: Unixtime(0), event_public_len: 0, event_private_len: None, diff --git a/gossip-lib/src/storage/types/person_list_metadata3.rs b/gossip-lib/src/storage/types/person_list_metadata3.rs index 2b83891e..f68164d7 100644 --- a/gossip-lib/src/storage/types/person_list_metadata3.rs +++ b/gossip-lib/src/storage/types/person_list_metadata3.rs @@ -21,7 +21,7 @@ impl Default for PersonListMetadata3 { PersonListMetadata3 { dtag: "".to_owned(), title: "".to_owned(), - last_edit_time: Unixtime::now().unwrap(), + last_edit_time: Unixtime::now(), event_created_at: Unixtime(0), event_public_len: 0, event_private_len: None, diff --git a/gossip-lib/src/storage/types/person_relay1.rs b/gossip-lib/src/storage/types/person_relay1.rs index 160c192a..569564d1 100644 --- a/gossip-lib/src/storage/types/person_relay1.rs +++ b/gossip-lib/src/storage/types/person_relay1.rs @@ -58,7 +58,7 @@ impl PersonRelay1 { // This ranks the relays that a person writes to, but does not consider local // factors such as our relay rank or the success rate of the relay. pub fn write_rank(mut dbprs: Vec) -> Vec<(RelayUrl, u64)> { - let now = Unixtime::now().unwrap().0 as u64; + let now = Unixtime::now().0 as u64; let mut output: Vec<(RelayUrl, u64)> = Vec::new(); let scorefn = |when: u64, fade_period: u64, base: u64| -> u64 { @@ -110,7 +110,7 @@ impl PersonRelay1 { // This ranks the relays that a person reads from, but does not consider local // factors such as our relay rank or the success rate of the relay. pub fn read_rank(mut dbprs: Vec) -> Vec<(RelayUrl, u64)> { - let now = Unixtime::now().unwrap().0 as u64; + let now = Unixtime::now().0 as u64; let mut output: Vec<(RelayUrl, u64)> = Vec::new(); let scorefn = |when: u64, fade_period: u64, base: u64| -> u64 { diff --git a/gossip-lib/src/storage/types/relay3.rs b/gossip-lib/src/storage/types/relay3.rs index 0702dea4..ee35759a 100644 --- a/gossip-lib/src/storage/types/relay3.rs +++ b/gossip-lib/src/storage/types/relay3.rs @@ -163,7 +163,7 @@ impl Relay3 { pub fn should_avoid(&self) -> bool { if let Some(when) = self.avoid_until { - when >= Unixtime::now().unwrap() + when >= Unixtime::now() } else { false }