nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

commit 8fa58de49a871eecae4a2ef60f4452286d315d2f
parent 480c5e4e5824e280c2c3acf41edf09065cb999fe
Author: Greg Heartsfield <scsibug@imap.cc>
Date:   Sat, 24 Sep 2022 08:30:22 -0500

refactor: clippy suggestions

Diffstat:
Msrc/close.rs | 4++--
Msrc/config.rs | 2+-
Msrc/db.rs | 6++----
Msrc/event.rs | 4++--
Msrc/hexrange.rs | 2+-
Msrc/main.rs | 4++--
Msrc/nip05.rs | 10++++------
Msrc/server.rs | 2+-
Msrc/subscription.rs | 6+++---
Mtests/common/mod.rs | 10+++++-----
Mtests/integration_test.rs | 2+-
11 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/src/close.rs b/src/close.rs @@ -5,7 +5,7 @@ use crate::error::{Error, Result}; use serde::{Deserialize, Serialize}; /// Close command in network format -#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] pub struct CloseCmd { /// Protocol command, expected to always be "CLOSE". cmd: String, @@ -14,7 +14,7 @@ pub struct CloseCmd { } /// Identifier of the subscription to be closed. -#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] pub struct Close { /// The subscription identifier being closed. pub id: String, diff --git a/src/config.rs b/src/config.rs @@ -70,7 +70,7 @@ pub struct Diagnostics { pub tracing: bool, // enables tokio console-subscriber } -#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Copy)] +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Copy)] #[serde(rename_all = "lowercase")] pub enum VerifiedUsersMode { Enabled, diff --git a/src/db.rs b/src/db.rs @@ -364,7 +364,7 @@ pub fn write_event(conn: &mut PooledConnection, e: &Event) -> Result<usize> { } /// Serialized event associated with a specific subscription request. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone)] pub struct QueryResult { /// Subscription identifier pub sub_id: String, @@ -537,9 +537,7 @@ fn query_from_sub(sub: &Subscription) -> (String, Vec<Box<dyn ToSql>>) { // encapsulate subqueries into select statements let subqueries_selects: Vec<String> = subqueries .iter() - .map(|s| { - return format!("SELECT content, created_at FROM ({})", s); - }) + .map(|s| format!("SELECT content, created_at FROM ({})", s)) .collect(); let query: String = subqueries_selects.join(" UNION "); debug!("final query string: {}", query); diff --git a/src/event.rs b/src/event.rs @@ -20,14 +20,14 @@ lazy_static! { } /// Event command in network format. -#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] pub struct EventCmd { cmd: String, // expecting static "EVENT" event: Event, } /// Parsed nostr event. -#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] pub struct Event { pub id: String, pub(crate) pubkey: String, diff --git a/src/hexrange.rs b/src/hexrange.rs @@ -3,7 +3,7 @@ use crate::utils::is_hex; use hex; /// Types of hexadecimal queries. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone)] pub enum HexSearch { // when no range is needed, exact 32-byte Exact(Vec<u8>), diff --git a/src/main.rs b/src/main.rs @@ -1,5 +1,5 @@ //! Server process -use log::*; +use log::info; use nostr_rs_relay::config; use nostr_rs_relay::error::{Error, Result}; use nostr_rs_relay::server::start_server; @@ -13,7 +13,7 @@ use console_subscriber::ConsoleLayer; /// Return a requested DB name from command line arguments. fn db_from_args(args: Vec<String>) -> Option<String> { if args.len() == 3 && args.get(1) == Some(&"--db".to_owned()) { - return args.get(2).map(|x| x.to_owned()); + return args.get(2).map(std::clone::Clone::clone); } None } diff --git a/src/nip05.rs b/src/nip05.rs @@ -44,7 +44,7 @@ pub struct Verifier { } /// A NIP-05 identifier is a local part and domain. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone)] pub struct Nip05Name { local: String, domain: String, @@ -540,7 +540,7 @@ impl Verifier { } /// Result of checking user's verification status against DNS/HTTP. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone)] pub enum UserWebVerificationStatus { Verified, // user is verified, as of now. DomainNotAllowed, // domain blacklist or whitelist denied us from attempting a verification @@ -549,7 +549,7 @@ pub enum UserWebVerificationStatus { } /// A NIP-05 verification record. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone)] // Basic information for a verification event. Gives us all we need to assert a NIP-05 address is good. pub struct VerificationRecord { pub rowid: u64, // database row for this verification event @@ -714,9 +714,7 @@ pub async fn get_oldest_user_verification( conn: db::PooledConnection, earliest: u64, ) -> Result<VerificationRecord> { - let res = - tokio::task::spawn_blocking(move || query_oldest_user_verification(conn, earliest)).await?; - res + tokio::task::spawn_blocking(move || query_oldest_user_verification(conn, earliest)).await? } pub fn query_oldest_user_verification( diff --git a/src/server.rs b/src/server.rs @@ -336,7 +336,7 @@ pub fn start_server(settings: Settings, shutdown_rx: MpscReceiver<()>) -> Result } /// Nostr protocol messages from a client -#[derive(Deserialize, Serialize, Clone, PartialEq, Debug)] +#[derive(Deserialize, Serialize, Clone, PartialEq, Eq, Debug)] #[serde(untagged)] pub enum NostrMessage { /// An `EVENT` message diff --git a/src/subscription.rs b/src/subscription.rs @@ -8,7 +8,7 @@ use std::collections::HashMap; use std::collections::HashSet; /// Subscription identifier and set of request filters -#[derive(Serialize, PartialEq, Debug, Clone)] +#[derive(Serialize, PartialEq, Eq, Debug, Clone)] pub struct Subscription { pub id: String, pub filters: Vec<ReqFilter>, @@ -19,7 +19,7 @@ pub struct Subscription { /// Corresponds to client-provided subscription request elements. Any /// element can be present if it should be used in filtering, or /// absent ([`None`]) if it should be ignored. -#[derive(Serialize, PartialEq, Debug, Clone)] +#[derive(Serialize, PartialEq, Eq, Debug, Clone)] pub struct ReqFilter { /// Event hashes pub ids: Option<Vec<String>>, @@ -471,8 +471,8 @@ mod tests { assert!(s.interested_in_event(&e)); Ok(()) } - #[test] + #[test] fn authors_multi_pubkey() -> Result<()> { // check for any of a set of authors, against the pubkey let s: Subscription = serde_json::from_str(r#"["REQ","xyz",{"authors":["abc", "bcd"]}]"#)?; diff --git a/tests/common/mod.rs b/tests/common/mod.rs @@ -1,5 +1,5 @@ use anyhow::{anyhow, Result}; -use log::*; +use log::{debug, info}; use nostr_rs_relay::config; use nostr_rs_relay::server::start_server; //use http::{Request, Response}; @@ -39,16 +39,16 @@ pub fn start_relay() -> Result<Relay> { let _ = start_server(settings, shutdown_rx); }); // how do we know the relay has finished starting up? - return Ok(Relay { + Ok(Relay { port, handle, shutdown_tx, - }); + }) } // check if the server is healthy via HTTP request async fn server_ready(relay: &Relay) -> Result<bool> { - let uri: String = format!("http://127.0.0.1:{}/", relay.port.to_string()); + let uri: String = format!("http://127.0.0.1:{}/", relay.port); let client = Client::new(); let uri: Uri = uri.parse().unwrap(); let res = client.get(uri).await?; @@ -60,7 +60,7 @@ pub async fn wait_for_healthy_relay(relay: &Relay) -> Result<()> { // give it a little time to start up before we start polling tokio::time::sleep(Duration::from_millis(10)).await; loop { - let server_check = server_ready(&relay).await; + let server_check = server_ready(relay).await; match server_check { Ok(true) => { // server responded with 200-OK. diff --git a/tests/integration_test.rs b/tests/integration_test.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use log::*; + use std::thread; use std::time::Duration;