upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-10-28 15:41:14 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-10-28 15:41:14 +0000
commitae87aedae9696f4c855ac3dc47e61faec9d07c15 (patch)
tree0309be588a4e3d3a510e7510300629cb2ec3a68a /src/lib
parent5979e13cdc65ea78894dbcab3acde11b246889a7 (diff)
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
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/client.rs36
-rw-r--r--src/lib/git/mod.rs14
-rw-r--r--src/lib/repo_ref.rs4
-rw-r--r--src/lib/repo_state.rs3
4 files changed, 32 insertions, 25 deletions
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 {
179 179
180 let relay = self.client.relay(relay_url).await?; 180 let relay = self.client.relay(relay_url).await?;
181 181
182 if !relay.is_connected().await { 182 if !relay.is_connected() {
183 #[allow(clippy::large_futures)] 183 #[allow(clippy::large_futures)]
184 relay 184 relay
185 .connect(Some(std::time::Duration::from_secs(CONNECTION_TIMEOUT))) 185 .connect(Some(std::time::Duration::from_secs(CONNECTION_TIMEOUT)))
186 .await; 186 .await;
187 } 187 }
188 188
189 if !relay.is_connected().await { 189 if !relay.is_connected() {
190 bail!("connection timeout"); 190 bail!("connection timeout");
191 } 191 }
192 Ok(()) 192 Ok(())
@@ -615,26 +615,27 @@ async fn get_events_of(
615) -> Result<Vec<Event>> { 615) -> Result<Vec<Event>> {
616 // relay.reconcile(filter, opts).await?; 616 // relay.reconcile(filter, opts).await?;
617 617
618 if !relay.is_connected().await { 618 if !relay.is_connected() {
619 #[allow(clippy::large_futures)] 619 #[allow(clippy::large_futures)]
620 relay 620 relay
621 .connect(Some(std::time::Duration::from_secs(CONNECTION_TIMEOUT))) 621 .connect(Some(std::time::Duration::from_secs(CONNECTION_TIMEOUT)))
622 .await; 622 .await;
623 } 623 }
624 624
625 if !relay.is_connected().await { 625 if !relay.is_connected() {
626 bail!("connection timeout"); 626 bail!("connection timeout");
627 } else if let Some(pb) = pb { 627 } else if let Some(pb) = pb {
628 pb.set_prefix(format!("connected {}", relay.url())); 628 pb.set_prefix(format!("connected {}", relay.url()));
629 } 629 }
630 let events = relay 630 let events = relay
631 .get_events_of( 631 .fetch_events(
632 filters, 632 filters,
633 // 20 is nostr_sdk default 633 // 20 is nostr_sdk default
634 std::time::Duration::from_secs(GET_EVENTS_TIMEOUT), 634 std::time::Duration::from_secs(GET_EVENTS_TIMEOUT),
635 nostr_sdk::FilterOptions::ExitOnEOSE, 635 nostr_sdk::FilterOptions::ExitOnEOSE,
636 ) 636 )
637 .await?; 637 .await?
638 .to_vec();
638 Ok(events) 639 Ok(events)
639} 640}
640 641
@@ -754,24 +755,26 @@ pub async fn get_events_from_cache(
754 git_repo_path: &Path, 755 git_repo_path: &Path,
755 filters: Vec<nostr::Filter>, 756 filters: Vec<nostr::Filter>,
756) -> Result<Vec<nostr::Event>> { 757) -> Result<Vec<nostr::Event>> {
757 get_local_cache_database(git_repo_path) 758 Ok(get_local_cache_database(git_repo_path)
758 .await? 759 .await?
759 .query(filters.clone()) 760 .query(filters.clone())
760 .await 761 .await
761 .context( 762 .context(
762 "cannot execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", 763 "cannot execute query on opened git repo nostr cache database .git/nostr-cache.lmdb",
763 ) 764 )?
765 .to_vec())
764} 766}
765 767
766pub async fn get_event_from_global_cache( 768pub async fn get_event_from_global_cache(
767 git_repo_path: &Path, 769 git_repo_path: &Path,
768 filters: Vec<nostr::Filter>, 770 filters: Vec<nostr::Filter>,
769) -> Result<Vec<nostr::Event>> { 771) -> Result<Vec<nostr::Event>> {
770 get_global_cache_database(git_repo_path) 772 Ok(get_global_cache_database(git_repo_path)
771 .await? 773 .await?
772 .query(filters.clone()) 774 .query(filters.clone())
773 .await 775 .await
774 .context("cannot execute query on opened ngit nostr cache database") 776 .context("cannot execute query on opened ngit nostr cache database")?
777 .to_vec())
775} 778}
776 779
777pub async fn save_event_in_cache(git_repo_path: &Path, event: &nostr::Event) -> Result<bool> { 780pub async fn save_event_in_cache(git_repo_path: &Path, event: &nostr::Event) -> Result<bool> {
@@ -841,7 +844,7 @@ pub async fn get_repo_ref_from_cache(
841 events.insert( 844 events.insert(
842 Coordinate { 845 Coordinate {
843 kind: e.kind, 846 kind: e.kind,
844 identifier: e.identifier().unwrap().to_string(), 847 identifier: e.tags.identifier().unwrap().to_string(),
845 public_key: e.pubkey, 848 public_key: e.pubkey,
846 relays: vec![], 849 relays: vec![],
847 }, 850 },
@@ -1114,7 +1117,7 @@ async fn process_fetched_events(
1114 .iter() 1117 .iter()
1115 .map(|(c, _)| c.clone()) 1118 .map(|(c, _)| c.clone())
1116 .any(|c| { 1119 .any(|c| {
1117 c.identifier.eq(event.identifier().unwrap()) 1120 c.identifier.eq(event.tags.identifier().unwrap())
1118 && c.public_key.eq(&event.pubkey) 1121 && c.public_key.eq(&event.pubkey)
1119 }); 1122 });
1120 let update_to_existing = !new_coordinate 1123 let update_to_existing = !new_coordinate
@@ -1122,7 +1125,7 @@ async fn process_fetched_events(
1122 .repo_coordinates_without_relays 1125 .repo_coordinates_without_relays
1123 .iter() 1126 .iter()
1124 .any(|(c, t)| { 1127 .any(|(c, t)| {
1125 c.identifier.eq(event.identifier().unwrap()) 1128 c.identifier.eq(event.tags.identifier().unwrap())
1126 && c.public_key.eq(&event.pubkey) 1129 && c.public_key.eq(&event.pubkey)
1127 && if let Some(t) = t { 1130 && if let Some(t) = t {
1128 event.created_at.gt(t) 1131 event.created_at.gt(t)
@@ -1135,7 +1138,7 @@ async fn process_fetched_events(
1135 Coordinate { 1138 Coordinate {
1136 kind: event.kind, 1139 kind: event.kind,
1137 public_key: event.pubkey, 1140 public_key: event.pubkey,
1138 identifier: event.identifier().unwrap().to_owned(), 1141 identifier: event.tags.identifier().unwrap().to_owned(),
1139 relays: vec![], 1142 relays: vec![],
1140 }, 1143 },
1141 event.created_at, 1144 event.created_at,
@@ -1216,7 +1219,10 @@ async fn process_fetched_events(
1216 } 1219 }
1217 for event in &events { 1220 for event in &events {
1218 if !request.existing_events.contains(&event.id) 1221 if !request.existing_events.contains(&event.id)
1219 && !event.event_ids().any(|id| report.proposals.contains(id)) 1222 && !event
1223 .tags
1224 .event_ids()
1225 .any(|id| report.proposals.contains(id))
1220 { 1226 {
1221 if event.kind.eq(&Kind::GitPatch) && !event_is_patch_set_root(event) { 1227 if event.kind.eq(&Kind::GitPatch) && !event_is_patch_set_root(event) {
1222 report.commits.insert(event.id); 1228 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::{
6use anyhow::{bail, Context, Result}; 6use anyhow::{bail, Context, Result};
7use git2::{DiffOptions, Oid, Revwalk}; 7use git2::{DiffOptions, Oid, Revwalk};
8pub use identify_ahead_behind::identify_ahead_behind; 8pub use identify_ahead_behind::identify_ahead_behind;
9use nostr_sdk::hashes::{sha1::Hash as Sha1Hash, Hash}; 9use nostr_sdk::{
10 hashes::{sha1::Hash as Sha1Hash, Hash},
11 Tags,
12};
10 13
11use crate::git_events::{get_commit_id_from_patch, tag_value}; 14use crate::git_events::{get_commit_id_from_patch, tag_value};
12pub mod identify_ahead_behind; 15pub mod identify_ahead_behind;
@@ -836,10 +839,7 @@ fn git_sig_to_tag_vec(sig: &git2::Signature) -> Vec<String> {
836 ] 839 ]
837} 840}
838 841
839fn extract_sig_from_patch_tags<'a>( 842fn extract_sig_from_patch_tags<'a>(tags: &'a Tags, tag_name: &str) -> Result<git2::Signature<'a>> {
840 tags: &'a [nostr::Tag],
841 tag_name: &str,
842) -> Result<git2::Signature<'a>> {
843 let v = tags 843 let v = tags
844 .iter() 844 .iter()
845 .find(|t| t.as_slice()[0].eq(tag_name)) 845 .find(|t| t.as_slice()[0].eq(tag_name))
@@ -1092,10 +1092,10 @@ mod tests {
1092 fn test(time: git2::Time) -> Result<()> { 1092 fn test(time: git2::Time) -> Result<()> {
1093 assert_eq!( 1093 assert_eq!(
1094 extract_sig_from_patch_tags( 1094 extract_sig_from_patch_tags(
1095 &[nostr::Tag::custom( 1095 &Tags::new(vec![nostr::Tag::custom(
1096 nostr::TagKind::Custom("author".to_string().into()), 1096 nostr::TagKind::Custom("author".to_string().into()),
1097 prep(&time)?, 1097 prep(&time)?,
1098 )], 1098 )]),
1099 "author", 1099 "author",
1100 )? 1100 )?
1101 .to_string(), 1101 .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<nostr::Event> for RepoRef {
105 r.events.insert( 105 r.events.insert(
106 Coordinate { 106 Coordinate {
107 kind: event.kind, 107 kind: event.kind,
108 identifier: event.identifier().unwrap().to_string(), 108 identifier: event.tags.identifier().unwrap().to_string(),
109 public_key: event.pubkey, 109 public_key: event.pubkey,
110 relays: vec![], 110 relays: vec![],
111 }, 111 },
@@ -343,7 +343,7 @@ async fn get_repo_coordinates_from_maintainers_yaml(
343 .await?; 343 .await?;
344 } 344 }
345 if let Some(e) = events.first() { 345 if let Some(e) = events.first() {
346 if let Some(identifier) = e.identifier() { 346 if let Some(identifier) = e.tags.identifier() {
347 for m in &repo_config.maintainers { 347 for m in &repo_config.maintainers {
348 if let Ok(maintainer) = PublicKey::parse(m) { 348 if let Ok(maintainer) = PublicKey::parse(m) {
349 repo_coordinates.insert(Coordinate { 349 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 {
14 state_events.sort_by_key(|e| e.created_at); 14 state_events.sort_by_key(|e| e.created_at);
15 let event = state_events.first().context("no state events")?; 15 let event = state_events.first().context("no state events")?;
16 let mut state = HashMap::new(); 16 let mut state = HashMap::new();
17 for tag in &event.tags { 17 for tag in event.tags.iter() {
18 if let Some(name) = tag.as_slice().first() { 18 if let Some(name) = tag.as_slice().first() {
19 if ["refs/heads/", "refs/tags", "HEAD"] 19 if ["refs/heads/", "refs/tags", "HEAD"]
20 .iter() 20 .iter()
@@ -30,6 +30,7 @@ impl RepoState {
30 } 30 }
31 Ok(RepoState { 31 Ok(RepoState {
32 identifier: event 32 identifier: event
33 .tags
33 .identifier() 34 .identifier()
34 .context("existing event must have an identifier")? 35 .context("existing event must have an identifier")?
35 .to_string(), 36 .to_string(),