mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-12-23 00:45:52 -05:00
refactor: clippy suggestions
This commit is contained in:
parent
480c5e4e58
commit
8fa58de49a
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>),
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
10
src/nip05.rs
10
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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"]}]"#)?;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::Result;
|
||||
use log::*;
|
||||
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user