diff --git a/src/close.rs b/src/close.rs index 825524c..d4cee36 100644 --- 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 index 3deefe3..743fa02 100644 --- 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 index 8ca0054..cbcb077 100644 --- a/src/db.rs +++ b/src/db.rs @@ -364,7 +364,7 @@ pub fn write_event(conn: &mut PooledConnection, e: &Event) -> Result { } /// 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>) { // encapsulate subqueries into select statements let subqueries_selects: Vec = 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 index 829f33d..64913ac 100644 --- 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 index 275343e..65cb28b 100644 --- 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), diff --git a/src/main.rs b/src/main.rs index f8b3ad3..a808149 100644 --- 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) -> Option { 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 index ecfb187..d95131a 100644 --- 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 { - 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 index b8a70b2..080911c 100644 --- 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 index 4415097..9fe4dba 100644 --- 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, @@ -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>, @@ -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 index 914a6aa..ea05d3b 100644 --- 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 { 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 { - 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 index aff89c1..58ad3f9 100644 --- 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;