From ae87aedae9696f4c855ac3dc47e61faec9d07c15 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 28 Oct 2024 15:41:14 +0000 Subject: chore: bump rust-nostr to patch near v0.36.0 bump all rust-nostr packages refactoring code based on breaking changes upgrading to patched version to address signer issue: nostr:nevent1qvzqqqqqqypzq6xcz9jerqgqkldy8lpg7lglcyj4g3nwzy2cs6u70wejdaj7csnjqy88wumn8ghj7mn0wvhxcmmv9uqzpsw5ph8le2n2kh6uchftawt74hddazk9tp7wjmz967y2l0uva5rc7hsstq --- src/lib/client.rs | 36 +++++++++++++++++++++--------------- src/lib/git/mod.rs | 14 +++++++------- src/lib/repo_ref.rs | 4 ++-- src/lib/repo_state.rs | 3 ++- 4 files changed, 32 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/lib/client.rs b/src/lib/client.rs index 8a381ab..d9ba351 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs @@ -179,14 +179,14 @@ impl Connect for Client { let relay = self.client.relay(relay_url).await?; - if !relay.is_connected().await { + if !relay.is_connected() { #[allow(clippy::large_futures)] relay .connect(Some(std::time::Duration::from_secs(CONNECTION_TIMEOUT))) .await; } - if !relay.is_connected().await { + if !relay.is_connected() { bail!("connection timeout"); } Ok(()) @@ -615,26 +615,27 @@ async fn get_events_of( ) -> Result> { // relay.reconcile(filter, opts).await?; - if !relay.is_connected().await { + if !relay.is_connected() { #[allow(clippy::large_futures)] relay .connect(Some(std::time::Duration::from_secs(CONNECTION_TIMEOUT))) .await; } - if !relay.is_connected().await { + if !relay.is_connected() { bail!("connection timeout"); } else if let Some(pb) = pb { pb.set_prefix(format!("connected {}", relay.url())); } let events = relay - .get_events_of( + .fetch_events( filters, // 20 is nostr_sdk default std::time::Duration::from_secs(GET_EVENTS_TIMEOUT), nostr_sdk::FilterOptions::ExitOnEOSE, ) - .await?; + .await? + .to_vec(); Ok(events) } @@ -754,24 +755,26 @@ pub async fn get_events_from_cache( git_repo_path: &Path, filters: Vec, ) -> Result> { - get_local_cache_database(git_repo_path) + Ok(get_local_cache_database(git_repo_path) .await? .query(filters.clone()) .await .context( "cannot execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", - ) + )? + .to_vec()) } pub async fn get_event_from_global_cache( git_repo_path: &Path, filters: Vec, ) -> Result> { - get_global_cache_database(git_repo_path) + Ok(get_global_cache_database(git_repo_path) .await? .query(filters.clone()) .await - .context("cannot execute query on opened ngit nostr cache database") + .context("cannot execute query on opened ngit nostr cache database")? + .to_vec()) } pub async fn save_event_in_cache(git_repo_path: &Path, event: &nostr::Event) -> Result { @@ -841,7 +844,7 @@ pub async fn get_repo_ref_from_cache( events.insert( Coordinate { kind: e.kind, - identifier: e.identifier().unwrap().to_string(), + identifier: e.tags.identifier().unwrap().to_string(), public_key: e.pubkey, relays: vec![], }, @@ -1114,7 +1117,7 @@ async fn process_fetched_events( .iter() .map(|(c, _)| c.clone()) .any(|c| { - c.identifier.eq(event.identifier().unwrap()) + c.identifier.eq(event.tags.identifier().unwrap()) && c.public_key.eq(&event.pubkey) }); let update_to_existing = !new_coordinate @@ -1122,7 +1125,7 @@ async fn process_fetched_events( .repo_coordinates_without_relays .iter() .any(|(c, t)| { - c.identifier.eq(event.identifier().unwrap()) + c.identifier.eq(event.tags.identifier().unwrap()) && c.public_key.eq(&event.pubkey) && if let Some(t) = t { event.created_at.gt(t) @@ -1135,7 +1138,7 @@ async fn process_fetched_events( Coordinate { kind: event.kind, public_key: event.pubkey, - identifier: event.identifier().unwrap().to_owned(), + identifier: event.tags.identifier().unwrap().to_owned(), relays: vec![], }, event.created_at, @@ -1216,7 +1219,10 @@ async fn process_fetched_events( } for event in &events { if !request.existing_events.contains(&event.id) - && !event.event_ids().any(|id| report.proposals.contains(id)) + && !event + .tags + .event_ids() + .any(|id| report.proposals.contains(id)) { if event.kind.eq(&Kind::GitPatch) && !event_is_patch_set_root(event) { report.commits.insert(event.id); diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs index 875a336..5d14ce3 100644 --- a/src/lib/git/mod.rs +++ b/src/lib/git/mod.rs @@ -6,7 +6,10 @@ use std::{ use anyhow::{bail, Context, Result}; use git2::{DiffOptions, Oid, Revwalk}; pub use identify_ahead_behind::identify_ahead_behind; -use nostr_sdk::hashes::{sha1::Hash as Sha1Hash, Hash}; +use nostr_sdk::{ + hashes::{sha1::Hash as Sha1Hash, Hash}, + Tags, +}; use crate::git_events::{get_commit_id_from_patch, tag_value}; pub mod identify_ahead_behind; @@ -836,10 +839,7 @@ fn git_sig_to_tag_vec(sig: &git2::Signature) -> Vec { ] } -fn extract_sig_from_patch_tags<'a>( - tags: &'a [nostr::Tag], - tag_name: &str, -) -> Result> { +fn extract_sig_from_patch_tags<'a>(tags: &'a Tags, tag_name: &str) -> Result> { let v = tags .iter() .find(|t| t.as_slice()[0].eq(tag_name)) @@ -1092,10 +1092,10 @@ mod tests { fn test(time: git2::Time) -> Result<()> { assert_eq!( extract_sig_from_patch_tags( - &[nostr::Tag::custom( + &Tags::new(vec![nostr::Tag::custom( nostr::TagKind::Custom("author".to_string().into()), prep(&time)?, - )], + )]), "author", )? .to_string(), diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 2468d4d..9bee641 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs @@ -105,7 +105,7 @@ impl TryFrom for RepoRef { r.events.insert( Coordinate { kind: event.kind, - identifier: event.identifier().unwrap().to_string(), + identifier: event.tags.identifier().unwrap().to_string(), public_key: event.pubkey, relays: vec![], }, @@ -343,7 +343,7 @@ async fn get_repo_coordinates_from_maintainers_yaml( .await?; } if let Some(e) = events.first() { - if let Some(identifier) = e.identifier() { + if let Some(identifier) = e.tags.identifier() { for m in &repo_config.maintainers { if let Ok(maintainer) = PublicKey::parse(m) { repo_coordinates.insert(Coordinate { diff --git a/src/lib/repo_state.rs b/src/lib/repo_state.rs index c39db34..c3a7606 100644 --- a/src/lib/repo_state.rs +++ b/src/lib/repo_state.rs @@ -14,7 +14,7 @@ impl RepoState { state_events.sort_by_key(|e| e.created_at); let event = state_events.first().context("no state events")?; let mut state = HashMap::new(); - for tag in &event.tags { + for tag in event.tags.iter() { if let Some(name) = tag.as_slice().first() { if ["refs/heads/", "refs/tags", "HEAD"] .iter() @@ -30,6 +30,7 @@ impl RepoState { } Ok(RepoState { identifier: event + .tags .identifier() .context("existing event must have an identifier")? .to_string(), -- cgit v1.2.3