Skip to content

Commit

Permalink
chore: upgrade rust-nostr v0.27.0
Browse files Browse the repository at this point in the history
this is a contribution from jk (sectore) that I rebased and squashed
into this commit.

the tests were broken in the last few commits to rush out some fixes.
this change may introduce more issues because of
Relay.respond_standard_req.
  • Loading branch information
DanConwayDev committed Jan 26, 2024
1 parent d96c8f6 commit fc3f22e
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 88 deletions.
96 changes: 57 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ futures = "0.3.28"
git2 = "0.18.1"
indicatif = "0.17.7"
keyring = "2.0.5"
nostr = "0.25.0"
nostr-sdk = "0.25.0"
nostr = "0.27.0"
nostr-sdk = "0.27.0"
passwords = "3.1.13"
scrypt = "0.11.0"
serde = { version = "1.0.181", features = ["derive"] }
Expand Down
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use futures::stream::{self, StreamExt};
#[cfg(test)]
use mockall::*;
use nostr::Event;
use nostr_sdk::ClientSigner;

#[allow(clippy::struct_field_names)]
pub struct Client {
client: nostr_sdk::Client,
fallback_relays: Vec<String>,
Expand Down Expand Up @@ -87,7 +89,9 @@ impl Connect for Client {
}

async fn set_keys(&mut self, keys: &nostr::Keys) {
self.client.set_keys(keys).await;
self.client
.set_signer(Some(ClientSigner::Keys(keys.clone())))
.await;
}

async fn disconnect(&self) -> Result<()> {
Expand All @@ -104,7 +108,7 @@ impl Connect for Client {
}

async fn send_event_to(&self, url: &str, event: Event) -> Result<nostr::EventId> {
self.client.add_relay(url, None).await?;
self.client.add_relay(url).await?;
self.client.connect_relay(url).await?;
Ok(self.client.send_event_to(url, event).await?)
}
Expand All @@ -117,7 +121,7 @@ impl Connect for Client {
// add relays
for relay in &relays {
self.client
.add_relay(relay.as_str(), None)
.add_relay(relay.as_str())
.await
.context("cannot add relay")?;
}
Expand All @@ -134,10 +138,6 @@ impl Connect for Client {
)
})
.map(|(relay, filters)| async {
if !relay.is_connected().await {
relay.connect(false).await;
}

match get_events_of(relay, filters).await {
Err(error) => {
println!("{} {}", error, relay.url());
Expand All @@ -159,7 +159,9 @@ async fn get_events_of(
filters: Vec<nostr::Filter>,
) -> Result<Vec<Event>> {
println!("fetching from {}", relay.url());

if !relay.is_connected().await {
relay.connect(None).await;
}
let events = relay
.get_events_of(
filters,
Expand Down
4 changes: 2 additions & 2 deletions src/key_handling/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ mod tests {
nostr::event::EventBuilder::new(
nostr::Kind::RelayList,
"",
&[
[
nostr::Tag::RelayMetadata(
"wss://fredswrite1.relay".into(),
Some(nostr::RelayMetadata::Write),
Expand All @@ -571,7 +571,7 @@ mod tests {
nostr::event::EventBuilder::new(
nostr::Kind::RelayList,
"",
&[
[
nostr::Tag::RelayMetadata(
"wss://carolswrite1.relay".into(),
Some(nostr::RelayMetadata::Write),
Expand Down
4 changes: 2 additions & 2 deletions src/repo_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl RepoRef {
nostr_sdk::EventBuilder::new(
nostr::event::Kind::Custom(REPO_REF_KIND),
"",
&[
[
vec![
Tag::Identifier(self.root_commit.to_string()),
Tag::Reference(format!("r-{}", self.root_commit)),
Expand All @@ -90,7 +90,7 @@ impl RepoRef {
self.relays.iter().map(|r| Tag::Relay(r.into())).collect(),
self.maintainers
.iter()
.map(|pk| Tag::PubKey(*pk, None))
.map(|pk| Tag::public_key(*pk))
.collect(),
// code languages and hashtags
]
Expand Down
14 changes: 7 additions & 7 deletions src/sub_commands/prs/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub fn generate_pr_and_patch_events(
let pr_event = EventBuilder::new(
nostr::event::Kind::Custom(PR_KIND),
format!("{title}\r\n\r\n{description}"),
&pr_tags,
pr_tags,
// TODO: add Repo event as root
// TODO: people tag maintainers
// TODO: add relay tags
Expand Down Expand Up @@ -364,15 +364,15 @@ pub fn generate_patch_event(
git_repo
.make_patch_from_commit(commit)
.context(format!("cannot make patch for commit {commit}"))?,
&[
[
Tag::Reference(format!("r-{root_commit}")),
Tag::Reference(commit.to_string()),
Tag::Reference(commit_parent.to_string()),
Tag::Event(
pr_event_id,
None, // TODO: add relay
Some(Marker::Root),
),
Tag::Event {
event_id: pr_event_id,
relay_url: None, // TODO: add relay
marker: Some(Marker::Root),
},
Tag::Generic(
TagKind::Custom("commit".to_string()),
vec![commit.to_string()],
Expand Down
2 changes: 1 addition & 1 deletion test_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ assert_cmd = "2.0.12"
dialoguer = "0.10.4"
directories = "5.0.1"
git2 = "0.18.1"
nostr = "0.25.0"
nostr = "0.27.0"
once_cell = "1.18.0"
rand = "0.8"
rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" }
Expand Down
Loading

0 comments on commit fc3f22e

Please sign in to comment.