1
0
mirror of https://github.com/scsibug/nostr-rs-relay.git synced 2025-07-28 15:38:28 -04:00

refactor: clippy suggestions

This commit is contained in:
Greg Heartsfield
2025-02-23 11:22:12 -06:00
parent d73cde2844
commit b4234eae25
6 changed files with 33 additions and 36 deletions

@@ -15,7 +15,6 @@ use tracing::info;
/// Bulk load JSONL data from STDIN to the database specified in config.toml (or ./nostr.db as a default). /// Bulk load JSONL data from STDIN to the database specified in config.toml (or ./nostr.db as a default).
/// The database must already exist, this will not create a new one. /// The database must already exist, this will not create a new one.
/// Tested against schema v13. /// Tested against schema v13.
pub fn main() -> Result<()> { pub fn main() -> Result<()> {
let _trace_sub = tracing_subscriber::fmt::try_init(); let _trace_sub = tracing_subscriber::fmt::try_init();
println!("Nostr-rs-relay Bulk Loader"); println!("Nostr-rs-relay Bulk Loader");

@@ -121,7 +121,7 @@ fn body_contains_user(username: &str, address: &str, bytes: &hyper::body::Bytes)
// get the pubkey for the requested user // get the pubkey for the requested user
let check_name = names_map.get(username).and_then(serde_json::Value::as_str); let check_name = names_map.get(username).and_then(serde_json::Value::as_str);
// ensure the address is a match // ensure the address is a match
Ok(check_name.map_or(false, |x| x == address)) Ok(check_name == Some(address))
} }
impl Verifier { impl Verifier {
@@ -243,7 +243,11 @@ impl Verifier {
let response_content_length = match response.body().size_hint().upper() { let response_content_length = match response.body().size_hint().upper() {
Some(v) => v, Some(v) => v,
None => { None => {
info!("missing content length header for account {:?} at URL: {}", nip.to_string(), url); info!(
"missing content length header for account {:?} at URL: {}",
nip.to_string(),
url
);
return Ok(UserWebVerificationStatus::Unknown); return Ok(UserWebVerificationStatus::Unknown);
} }
}; };

@@ -38,7 +38,7 @@ impl ClnRestPaymentProcessor {
.ok_or(ConfigError::NotFound("rune_path".to_string()))?; .ok_or(ConfigError::NotFound("rune_path".to_string()))?;
let rune = String::from_utf8(fs::read(rune_path)?) let rune = String::from_utf8(fs::read(rune_path)?)
.map_err(|_| ConfigError::Message("Rune should be UTF8".to_string()))?; .map_err(|_| ConfigError::Message("Rune should be UTF8".to_string()))?;
let mut rune_header = HeaderValue::from_str(&rune.trim()) let mut rune_header = HeaderValue::from_str(rune.trim())
.map_err(|_| ConfigError::Message("Invalid Rune header".to_string()))?; .map_err(|_| ConfigError::Message("Invalid Rune header".to_string()))?;
rune_header.set_sensitive(true); rune_header.set_sensitive(true);

@@ -55,12 +55,12 @@ pub enum InvoiceStatus {
Expired, Expired,
} }
impl ToString for InvoiceStatus { impl std::fmt::Display for InvoiceStatus {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
InvoiceStatus::Paid => "Paid".to_string(), InvoiceStatus::Paid => write!(f, "Paid"),
InvoiceStatus::Unpaid => "Unpaid".to_string(), InvoiceStatus::Unpaid => write!(f, "Unpaid"),
InvoiceStatus::Expired => "Expired".to_string(), InvoiceStatus::Expired => write!(f, "Expired"),
} }
} }
} }

@@ -177,28 +177,25 @@ ON CONFLICT (id) DO NOTHING"#,
let tag_val = &tag[1]; let tag_val = &tag[1];
// only single-char tags are searchable // only single-char tags are searchable
let tag_char_opt = single_char_tagname(tag_name); let tag_char_opt = single_char_tagname(tag_name);
match &tag_char_opt { if tag_char_opt.is_some() {
Some(_) => { // if tag value is lowercase hex;
// if tag value is lowercase hex; if is_lower_hex(tag_val) && (tag_val.len() % 2 == 0) {
if is_lower_hex(tag_val) && (tag_val.len() % 2 == 0) { sqlx::query("INSERT INTO tag (event_id, \"name\", value, value_hex) VALUES($1, $2, NULL, $3) \
sqlx::query("INSERT INTO tag (event_id, \"name\", value, value_hex) VALUES($1, $2, NULL, $3) \ ON CONFLICT (event_id, \"name\", value, value_hex) DO NOTHING")
ON CONFLICT (event_id, \"name\", value, value_hex) DO NOTHING")
.bind(&id_blob) .bind(&id_blob)
.bind(tag_name) .bind(tag_name)
.bind(hex::decode(tag_val).ok()) .bind(hex::decode(tag_val).ok())
.execute(&mut tx) .execute(&mut tx)
.await?; .await?;
} else { } else {
sqlx::query("INSERT INTO tag (event_id, \"name\", value, value_hex) VALUES($1, $2, $3, NULL) \ sqlx::query("INSERT INTO tag (event_id, \"name\", value, value_hex) VALUES($1, $2, $3, NULL) \
ON CONFLICT (event_id, \"name\", value, value_hex) DO NOTHING") ON CONFLICT (event_id, \"name\", value, value_hex) DO NOTHING")
.bind(&id_blob) .bind(&id_blob)
.bind(tag_name) .bind(tag_name)
.bind(tag_val.as_bytes()) .bind(tag_val.as_bytes())
.execute(&mut tx) .execute(&mut tx)
.await?; .await?;
}
} }
None => {}
} }
} }
} }

@@ -156,14 +156,11 @@ impl SqliteRepo {
let tagval = &tag[1]; let tagval = &tag[1];
// only single-char tags are searchable // only single-char tags are searchable
let tagchar_opt = single_char_tagname(tagname); let tagchar_opt = single_char_tagname(tagname);
match &tagchar_opt { if tagchar_opt.is_some() {
Some(_) => { tx.execute(
tx.execute( "INSERT OR IGNORE INTO tag (event_id, name, value, kind, created_at) VALUES (?1, ?2, ?3, ?4, ?5)",
"INSERT OR IGNORE INTO tag (event_id, name, value, kind, created_at) VALUES (?1, ?2, ?3, ?4, ?5)", params![ev_id, &tagname, &tagval, e.kind, e.created_at],
params![ev_id, &tagname, &tagval, e.kind, e.created_at], )?;
)?;
}
None => {}
} }
} }
} }