refactor: clippy suggestions

This commit is contained in:
Greg Heartsfield 2022-09-24 08:30:22 -05:00
parent 480c5e4e58
commit 8fa58de49a
11 changed files with 24 additions and 28 deletions

View File

@ -5,7 +5,7 @@ use crate::error::{Error, Result};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Close command in network format /// Close command in network format
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct CloseCmd { pub struct CloseCmd {
/// Protocol command, expected to always be "CLOSE". /// Protocol command, expected to always be "CLOSE".
cmd: String, cmd: String,
@ -14,7 +14,7 @@ pub struct CloseCmd {
} }
/// Identifier of the subscription to be closed. /// Identifier of the subscription to be closed.
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct Close { pub struct Close {
/// The subscription identifier being closed. /// The subscription identifier being closed.
pub id: String, pub id: String,

View File

@ -70,7 +70,7 @@ pub struct Diagnostics {
pub tracing: bool, // enables tokio console-subscriber 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")] #[serde(rename_all = "lowercase")]
pub enum VerifiedUsersMode { pub enum VerifiedUsersMode {
Enabled, Enabled,

View File

@ -364,7 +364,7 @@ pub fn write_event(conn: &mut PooledConnection, e: &Event) -> Result<usize> {
} }
/// Serialized event associated with a specific subscription request. /// Serialized event associated with a specific subscription request.
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Eq, Debug, Clone)]
pub struct QueryResult { pub struct QueryResult {
/// Subscription identifier /// Subscription identifier
pub sub_id: String, pub sub_id: String,
@ -537,9 +537,7 @@ fn query_from_sub(sub: &Subscription) -> (String, Vec<Box<dyn ToSql>>) {
// encapsulate subqueries into select statements // encapsulate subqueries into select statements
let subqueries_selects: Vec<String> = subqueries let subqueries_selects: Vec<String> = subqueries
.iter() .iter()
.map(|s| { .map(|s| format!("SELECT content, created_at FROM ({})", s))
return format!("SELECT content, created_at FROM ({})", s);
})
.collect(); .collect();
let query: String = subqueries_selects.join(" UNION "); let query: String = subqueries_selects.join(" UNION ");
debug!("final query string: {}", query); debug!("final query string: {}", query);

View File

@ -20,14 +20,14 @@ lazy_static! {
} }
/// Event command in network format. /// Event command in network format.
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct EventCmd { pub struct EventCmd {
cmd: String, // expecting static "EVENT" cmd: String, // expecting static "EVENT"
event: Event, event: Event,
} }
/// Parsed nostr event. /// Parsed nostr event.
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct Event { pub struct Event {
pub id: String, pub id: String,
pub(crate) pubkey: String, pub(crate) pubkey: String,

View File

@ -3,7 +3,7 @@ use crate::utils::is_hex;
use hex; use hex;
/// Types of hexadecimal queries. /// Types of hexadecimal queries.
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Eq, Debug, Clone)]
pub enum HexSearch { pub enum HexSearch {
// when no range is needed, exact 32-byte // when no range is needed, exact 32-byte
Exact(Vec<u8>), Exact(Vec<u8>),

View File

@ -1,5 +1,5 @@
//! Server process //! Server process
use log::*; use log::info;
use nostr_rs_relay::config; use nostr_rs_relay::config;
use nostr_rs_relay::error::{Error, Result}; use nostr_rs_relay::error::{Error, Result};
use nostr_rs_relay::server::start_server; use nostr_rs_relay::server::start_server;
@ -13,7 +13,7 @@ use console_subscriber::ConsoleLayer;
/// Return a requested DB name from command line arguments. /// Return a requested DB name from command line arguments.
fn db_from_args(args: Vec<String>) -> Option<String> { fn db_from_args(args: Vec<String>) -> Option<String> {
if args.len() == 3 && args.get(1) == Some(&"--db".to_owned()) { 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 None
} }

View File

@ -44,7 +44,7 @@ pub struct Verifier {
} }
/// A NIP-05 identifier is a local part and domain. /// A NIP-05 identifier is a local part and domain.
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Eq, Debug, Clone)]
pub struct Nip05Name { pub struct Nip05Name {
local: String, local: String,
domain: String, domain: String,
@ -540,7 +540,7 @@ impl Verifier {
} }
/// Result of checking user's verification status against DNS/HTTP. /// Result of checking user's verification status against DNS/HTTP.
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Eq, Debug, Clone)]
pub enum UserWebVerificationStatus { pub enum UserWebVerificationStatus {
Verified, // user is verified, as of now. Verified, // user is verified, as of now.
DomainNotAllowed, // domain blacklist or whitelist denied us from attempting a verification DomainNotAllowed, // domain blacklist or whitelist denied us from attempting a verification
@ -549,7 +549,7 @@ pub enum UserWebVerificationStatus {
} }
/// A NIP-05 verification record. /// 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. // Basic information for a verification event. Gives us all we need to assert a NIP-05 address is good.
pub struct VerificationRecord { pub struct VerificationRecord {
pub rowid: u64, // database row for this verification event pub rowid: u64, // database row for this verification event
@ -714,9 +714,7 @@ pub async fn get_oldest_user_verification(
conn: db::PooledConnection, conn: db::PooledConnection,
earliest: u64, earliest: u64,
) -> Result<VerificationRecord> { ) -> Result<VerificationRecord> {
let res = tokio::task::spawn_blocking(move || query_oldest_user_verification(conn, earliest)).await?
tokio::task::spawn_blocking(move || query_oldest_user_verification(conn, earliest)).await?;
res
} }
pub fn query_oldest_user_verification( pub fn query_oldest_user_verification(

View File

@ -336,7 +336,7 @@ pub fn start_server(settings: Settings, shutdown_rx: MpscReceiver<()>) -> Result
} }
/// Nostr protocol messages from a client /// Nostr protocol messages from a client
#[derive(Deserialize, Serialize, Clone, PartialEq, Debug)] #[derive(Deserialize, Serialize, Clone, PartialEq, Eq, Debug)]
#[serde(untagged)] #[serde(untagged)]
pub enum NostrMessage { pub enum NostrMessage {
/// An `EVENT` message /// An `EVENT` message

View File

@ -8,7 +8,7 @@ use std::collections::HashMap;
use std::collections::HashSet; use std::collections::HashSet;
/// Subscription identifier and set of request filters /// Subscription identifier and set of request filters
#[derive(Serialize, PartialEq, Debug, Clone)] #[derive(Serialize, PartialEq, Eq, Debug, Clone)]
pub struct Subscription { pub struct Subscription {
pub id: String, pub id: String,
pub filters: Vec<ReqFilter>, pub filters: Vec<ReqFilter>,
@ -19,7 +19,7 @@ pub struct Subscription {
/// Corresponds to client-provided subscription request elements. Any /// Corresponds to client-provided subscription request elements. Any
/// element can be present if it should be used in filtering, or /// element can be present if it should be used in filtering, or
/// absent ([`None`]) if it should be ignored. /// absent ([`None`]) if it should be ignored.
#[derive(Serialize, PartialEq, Debug, Clone)] #[derive(Serialize, PartialEq, Eq, Debug, Clone)]
pub struct ReqFilter { pub struct ReqFilter {
/// Event hashes /// Event hashes
pub ids: Option<Vec<String>>, pub ids: Option<Vec<String>>,
@ -471,8 +471,8 @@ mod tests {
assert!(s.interested_in_event(&e)); assert!(s.interested_in_event(&e));
Ok(()) Ok(())
} }
#[test]
#[test]
fn authors_multi_pubkey() -> Result<()> { fn authors_multi_pubkey() -> Result<()> {
// check for any of a set of authors, against the pubkey // check for any of a set of authors, against the pubkey
let s: Subscription = serde_json::from_str(r#"["REQ","xyz",{"authors":["abc", "bcd"]}]"#)?; let s: Subscription = serde_json::from_str(r#"["REQ","xyz",{"authors":["abc", "bcd"]}]"#)?;

View File

@ -1,5 +1,5 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use log::*; use log::{debug, info};
use nostr_rs_relay::config; use nostr_rs_relay::config;
use nostr_rs_relay::server::start_server; use nostr_rs_relay::server::start_server;
//use http::{Request, Response}; //use http::{Request, Response};
@ -39,16 +39,16 @@ pub fn start_relay() -> Result<Relay> {
let _ = start_server(settings, shutdown_rx); let _ = start_server(settings, shutdown_rx);
}); });
// how do we know the relay has finished starting up? // how do we know the relay has finished starting up?
return Ok(Relay { Ok(Relay {
port, port,
handle, handle,
shutdown_tx, shutdown_tx,
}); })
} }
// check if the server is healthy via HTTP request // check if the server is healthy via HTTP request
async fn server_ready(relay: &Relay) -> Result<bool> { 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 client = Client::new();
let uri: Uri = uri.parse().unwrap(); let uri: Uri = uri.parse().unwrap();
let res = client.get(uri).await?; 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 // give it a little time to start up before we start polling
tokio::time::sleep(Duration::from_millis(10)).await; tokio::time::sleep(Duration::from_millis(10)).await;
loop { loop {
let server_check = server_ready(&relay).await; let server_check = server_ready(relay).await;
match server_check { match server_check {
Ok(true) => { Ok(true) => {
// server responded with 200-OK. // server responded with 200-OK.

View File

@ -1,5 +1,5 @@
use anyhow::Result; use anyhow::Result;
use log::*;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;