mirror of
https://github.com/damus-io/notedeck.git
synced 2024-09-18 21:03:31 +00:00
fix clippy warnings
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
973a7c780f
commit
1f149aec3b
@ -47,7 +47,7 @@ impl ClientMessage {
|
||||
format!("[\"REQ\",\"{}\",{}]", sub_id, filters_json_str)
|
||||
} else {
|
||||
let filters_json_str: Result<Vec<String>, Error> = filters
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|f| f.json().map_err(Into::<Error>::into))
|
||||
.collect();
|
||||
format!("[\"REQ\",\"{}\",{}]", sub_id, filters_json_str?.join(","))
|
||||
|
@ -1,5 +1,4 @@
|
||||
//use nostr::prelude::secp256k1;
|
||||
use serde_json;
|
||||
use std::array::TryFromSliceError;
|
||||
use std::fmt;
|
||||
|
||||
|
@ -62,7 +62,7 @@ impl FullKeypair {
|
||||
let secret_key = nostr::SecretKey::from(*secret_key);
|
||||
FullKeypair {
|
||||
pubkey: Pubkey::new(&xopk.serialize()),
|
||||
secret_key: SecretKey::from(secret_key),
|
||||
secret_key,
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,11 +90,7 @@ impl std::fmt::Display for Keypair {
|
||||
|
||||
impl std::fmt::Display for FullKeypair {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Keypair:\n\tpublic: {}\n\tsecret: {}",
|
||||
self.pubkey, "<hidden>"
|
||||
)
|
||||
write!(f, "Keypair:\n\tpublic: {}\n\tsecret: <hidden>", self.pubkey)
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,14 +104,9 @@ impl SerializableKeypair {
|
||||
pub fn from_keypair(kp: &Keypair, pass: &str, log_n: u8) -> Self {
|
||||
Self {
|
||||
pubkey: kp.pubkey.clone(),
|
||||
encrypted_secret_key: kp
|
||||
.secret_key
|
||||
.clone()
|
||||
.map(|s| {
|
||||
EncryptedSecretKey::new(&s, pass, log_n, nostr::nips::nip49::KeySecurity::Weak)
|
||||
.ok()
|
||||
})
|
||||
.flatten(),
|
||||
encrypted_secret_key: kp.secret_key.clone().and_then(|s| {
|
||||
EncryptedSecretKey::new(&s, pass, log_n, nostr::nips::nip49::KeySecurity::Weak).ok()
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,8 +114,7 @@ impl SerializableKeypair {
|
||||
Keypair::new(
|
||||
self.pubkey.clone(),
|
||||
self.encrypted_secret_key
|
||||
.map(|e| e.to_secret_key(pass).ok())
|
||||
.flatten(),
|
||||
.and_then(|e| e.to_secret_key(pass).ok()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ impl Note {
|
||||
}
|
||||
|
||||
pub fn verify(&self) -> Result<Self, Error> {
|
||||
return Err(Error::InvalidSignature);
|
||||
Err(Error::InvalidSignature)
|
||||
}
|
||||
|
||||
/// This is just for serde sanity checking
|
||||
|
@ -39,7 +39,7 @@ impl<'a> From<&'a WsEvent> for RelayEvent<'a> {
|
||||
impl<'a> From<&'a WsMessage> for RelayEvent<'a> {
|
||||
fn from(wsmsg: &'a WsMessage) -> RelayEvent<'a> {
|
||||
match wsmsg {
|
||||
WsMessage::Text(ref s) => match RelayMessage::from_json(&s).map(RelayEvent::Message) {
|
||||
WsMessage::Text(s) => match RelayMessage::from_json(s).map(RelayEvent::Message) {
|
||||
Ok(msg) => msg,
|
||||
Err(err) => RelayEvent::Error(err),
|
||||
},
|
||||
@ -59,9 +59,9 @@ impl<'a> RelayMessage<'a> {
|
||||
|
||||
pub fn ok(event_id: &'a str, status: bool, message: &'a str) -> Self {
|
||||
RelayMessage::OK(CommandResult {
|
||||
event_id: event_id,
|
||||
event_id,
|
||||
status,
|
||||
message: message,
|
||||
message,
|
||||
})
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ impl<'a> RelayMessage<'a> {
|
||||
// Relay response format: ["NOTICE", <message>]
|
||||
if &msg[0..=9] == "[\"NOTICE\"," {
|
||||
// TODO: there could be more than one space, whatever
|
||||
let start = if msg.bytes().nth(10) == Some(b' ') {
|
||||
let start = if msg.as_bytes().get(10).copied() == Some(b' ') {
|
||||
12
|
||||
} else {
|
||||
11
|
||||
@ -96,7 +96,7 @@ impl<'a> RelayMessage<'a> {
|
||||
// EOSE (NIP-15)
|
||||
// Relay response format: ["EOSE", <subscription_id>]
|
||||
if &msg[0..=7] == "[\"EOSE\"," {
|
||||
let start = if msg.bytes().nth(8) == Some(b' ') {
|
||||
let start = if msg.as_bytes().get(8).copied() == Some(b' ') {
|
||||
10
|
||||
} else {
|
||||
9
|
||||
|
@ -26,7 +26,7 @@ pub struct PoolRelay {
|
||||
impl PoolRelay {
|
||||
pub fn new(relay: Relay) -> PoolRelay {
|
||||
PoolRelay {
|
||||
relay: relay,
|
||||
relay,
|
||||
last_ping: Instant::now(),
|
||||
last_connect_attempt: Instant::now(),
|
||||
retry_connect_after: Self::initial_reconnect_duration(),
|
||||
@ -43,6 +43,12 @@ pub struct RelayPool {
|
||||
pub ping_rate: Duration,
|
||||
}
|
||||
|
||||
impl Default for RelayPool {
|
||||
fn default() -> Self {
|
||||
RelayPool::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl RelayPool {
|
||||
// Constructs a new, empty RelayPool.
|
||||
pub fn new() -> RelayPool {
|
||||
@ -59,11 +65,12 @@ impl RelayPool {
|
||||
|
||||
pub fn has(&self, url: &str) -> bool {
|
||||
for relay in &self.relays {
|
||||
if &relay.relay.url == url {
|
||||
if relay.relay.url == url {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub fn send(&mut self, cmd: &ClientMessage) {
|
||||
@ -157,7 +164,7 @@ impl RelayPool {
|
||||
/// function searches each relay in the list in order, attempting to
|
||||
/// receive a message from each. If a message is received, return it.
|
||||
/// If no message is received from any relays, None is returned.
|
||||
pub fn try_recv<'a>(&'a mut self) -> Option<PoolEvent<'a>> {
|
||||
pub fn try_recv(&mut self) -> Option<PoolEvent<'_>> {
|
||||
for relay in &mut self.relays {
|
||||
let relay = &mut relay.relay;
|
||||
if let Some(event) = relay.receiver.try_recv() {
|
||||
@ -176,13 +183,10 @@ impl RelayPool {
|
||||
// let's just handle pongs here.
|
||||
// We only need to do this natively.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
match &ev {
|
||||
WsMessage::Ping(ref bs) => {
|
||||
if let WsMessage::Ping(ref bs) = ev {
|
||||
debug!("pong {}", &relay.url);
|
||||
relay.sender.send(WsMessage::Pong(bs.to_owned()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Some(PoolEvent {
|
||||
|
@ -45,7 +45,7 @@ fn mention_ui(
|
||||
pk: &[u8; 32],
|
||||
ui: &mut egui::Ui,
|
||||
size: f32,
|
||||
selectable: bool
|
||||
selectable: bool,
|
||||
) -> egui::Response {
|
||||
#[cfg(feature = "profiling")]
|
||||
puffin::profile_function!();
|
||||
|
Loading…
Reference in New Issue
Block a user