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 --- Cargo.lock | 16 ++++++++-------- Cargo.toml | 10 +++++----- src/lib/client.rs | 36 +++++++++++++++++++++--------------- src/lib/git/mod.rs | 14 +++++++------- src/lib/repo_ref.rs | 4 ++-- src/lib/repo_state.rs | 3 ++- test_utils/Cargo.toml | 8 ++++---- test_utils/src/git.rs | 2 +- test_utils/src/lib.rs | 31 +++++++++++++++++-------------- tests/git_remote_nostr/main.rs | 2 +- tests/git_remote_nostr/push.rs | 4 ++-- tests/ngit_list.rs | 2 +- tests/ngit_send.rs | 8 ++++---- 13 files changed, 75 insertions(+), 65 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f5c0227..b20b60a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1843,7 +1843,7 @@ checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" [[package]] name = "nostr" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=4dbfa94#4dbfa94876b136869e2feea75288f0c6a0beaa0e" +source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" dependencies = [ "aes", "base64", @@ -1873,7 +1873,7 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=4dbfa94#4dbfa94876b136869e2feea75288f0c6a0beaa0e" +source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" dependencies = [ "async-trait", "flatbuffers", @@ -1887,7 +1887,7 @@ dependencies = [ [[package]] name = "nostr-lmdb" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=4dbfa94#4dbfa94876b136869e2feea75288f0c6a0beaa0e" +source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" dependencies = [ "heed", "nostr", @@ -1900,7 +1900,7 @@ dependencies = [ [[package]] name = "nostr-relay-pool" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=4dbfa94#4dbfa94876b136869e2feea75288f0c6a0beaa0e" +source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" dependencies = [ "async-utility", "async-wsocket", @@ -1918,7 +1918,7 @@ dependencies = [ [[package]] name = "nostr-sdk" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=4dbfa94#4dbfa94876b136869e2feea75288f0c6a0beaa0e" +source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" dependencies = [ "async-utility", "atomic-destructor", @@ -1937,7 +1937,7 @@ dependencies = [ [[package]] name = "nostr-signer" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=4dbfa94#4dbfa94876b136869e2feea75288f0c6a0beaa0e" +source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" dependencies = [ "async-utility", "nostr", @@ -1950,7 +1950,7 @@ dependencies = [ [[package]] name = "nostr-zapper" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=4dbfa94#4dbfa94876b136869e2feea75288f0c6a0beaa0e" +source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" dependencies = [ "async-trait", "nostr", @@ -2039,7 +2039,7 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "nwc" version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=4dbfa94#4dbfa94876b136869e2feea75288f0c6a0beaa0e" +source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" dependencies = [ "async-utility", "nostr", diff --git a/Cargo.toml b/Cargo.toml index 79a9990..ed99aea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,11 +24,11 @@ futures = "0.3.28" git2 = "0.19.0" indicatif = "0.17.7" keyring = "2.0.5" -nostr = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } -nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } -nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } -nostr-signer = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } -nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } +nostr = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } +nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } +nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } +nostr-signer = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } +nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } passwords = "3.1.13" qrcode = { version = "0.14.1", default-features = false } scrypt = "0.11.0" 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(), diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index 403e478..f4e0c7e 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml @@ -10,10 +10,10 @@ dialoguer = "0.10.4" directories = "5.0.1" futures = "0.3.28" git2 = "0.19.0" -nostr = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } -nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } -nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } -nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } +nostr = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } +nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } +nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } +nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } once_cell = "1.18.0" rand = "0.8" rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } diff --git a/test_utils/src/git.rs b/test_utils/src/git.rs index 3c19a2c..470cd83 100644 --- a/test_utils/src/git.rs +++ b/test_utils/src/git.rs @@ -26,7 +26,7 @@ impl Default for GitTestRepo { let coordinate = Coordinate { kind: Kind::GitRepoAnnouncement, public_key: repo_event.pubkey, - identifier: repo_event.identifier().unwrap().to_string(), + identifier: repo_event.tags.identifier().unwrap().to_string(), relays: vec![ "ws://localhost:8055".to_string(), "ws://localhost:8056".to_string(), diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 57b0643..96558ef 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -142,7 +142,7 @@ pub fn make_event_old_or_change_user( &keys.public_key(), &unsigned.created_at, &unsigned.kind, - &unsigned.tags, + &unsigned.tags.clone().to_vec(), &unsigned.content, )); @@ -1061,13 +1061,14 @@ 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 fn get_proposal_branch_name( @@ -1360,17 +1361,19 @@ fn get_first_proposal_event_id() -> Result { let client = Client::default(); Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; Handle::current().block_on(client.connect_relay("ws://localhost:8055"))?; - let proposals = Handle::current().block_on(client.get_events_of( - vec![ - nostr::Filter::default() - .kind(nostr::Kind::GitPatch) - .custom_tag( - nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), - vec!["root"], - ), - ], - nostr_sdk::EventSource::relays(Some(Duration::from_millis(500))), - ))?; + let proposals = Handle::current() + .block_on(client.fetch_events( + vec![ + nostr::Filter::default() + .kind(nostr::Kind::GitPatch) + .custom_tag( + nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), + vec!["root"], + ), + ], + Some(Duration::from_millis(500)), + ))? + .to_vec(); Handle::current().block_on(client.disconnect())?; let proposal_1_id = proposals diff --git a/tests/git_remote_nostr/main.rs b/tests/git_remote_nostr/main.rs index 189d82d..f749c7f 100644 --- a/tests/git_remote_nostr/main.rs +++ b/tests/git_remote_nostr/main.rs @@ -21,7 +21,7 @@ fn get_nostr_remote_url() -> Result { let naddr = Coordinate { kind: Kind::GitRepoAnnouncement, public_key: repo_event.pubkey, - identifier: repo_event.identifier().unwrap().to_string(), + identifier: repo_event.tags.identifier().unwrap().to_string(), relays: vec![ "ws://localhost:8055".to_string(), "ws://localhost:8056".to_string(), diff --git a/tests/git_remote_nostr/push.rs b/tests/git_remote_nostr/push.rs index e0a4e93..b93475c 100644 --- a/tests/git_remote_nostr/push.rs +++ b/tests/git_remote_nostr/push.rs @@ -302,8 +302,8 @@ mod two_branches_in_batch_one_added_one_updated { .context("state event not created")?; assert_eq!( - state_event.identifier(), - generate_repo_ref_event().identifier(), + state_event.tags.identifier(), + generate_repo_ref_event().tags.identifier(), ); // println!("{:#?}", state_event); assert_eq!( diff --git a/tests/ngit_list.rs b/tests/ngit_list.rs index 26cf717..6382451 100644 --- a/tests/ngit_list.rs +++ b/tests/ngit_list.rs @@ -90,7 +90,7 @@ mod cannot_find_repo_event { &Coordinate { kind: nostr::Kind::GitRepoAnnouncement, public_key: TEST_KEY_1_KEYS.public_key(), - identifier: repo_event.identifier().unwrap().to_string(), + identifier: repo_event.tags.identifier().unwrap().to_string(), relays: vec!["ws://localhost:8056".to_string()], } .to_bech32()?, diff --git a/tests/ngit_send.rs b/tests/ngit_send.rs index 0fe7a86..620146e 100644 --- a/tests/ngit_send.rs +++ b/tests/ngit_send.rs @@ -400,7 +400,7 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ && t.as_slice()[1].eq(&format!( "{}:{TEST_KEY_1_PUBKEY_HEX}:{}", Kind::GitRepoAnnouncement, - generate_repo_ref_event().identifier().unwrap() + generate_repo_ref_event().tags.identifier().unwrap() ))) ); assert!( @@ -411,7 +411,7 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ && t.as_slice()[1].eq(&format!( "{}:{TEST_KEY_2_PUBKEY_HEX}:{}", Kind::GitRepoAnnouncement, - generate_repo_ref_event().identifier().unwrap() + generate_repo_ref_event().tags.identifier().unwrap() ))) ); } @@ -606,7 +606,7 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ && t.as_slice()[1].eq(&format!( "{}:{TEST_KEY_1_PUBKEY_HEX}:{}", Kind::GitRepoAnnouncement, - generate_repo_ref_event().identifier().unwrap() + generate_repo_ref_event().tags.identifier().unwrap() )) })); assert!(prep().await?.tags.iter().any(|t| { @@ -614,7 +614,7 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ && t.as_slice()[1].eq(&format!( "{}:{TEST_KEY_2_PUBKEY_HEX}:{}", Kind::GitRepoAnnouncement, - generate_repo_ref_event().identifier().unwrap() + generate_repo_ref_event().tags.identifier().unwrap() )) })); Ok(()) -- cgit v1.2.3