Unverified Commit ef54e452 authored by Roman Zeyde's avatar Roman Zeyde
Browse files

Fix more Clippy warnings

parent 807a2005
......@@ -12,7 +12,7 @@ use electrs::{
use error_chain::ChainedError;
fn run() -> Result<()> {
let signal = Waiter::new();
let signal = Waiter::start();
let config = Config::from_args();
let metrics = Metrics::new(config.monitoring_addr);
metrics.start();
......
......@@ -23,7 +23,7 @@ use electrs::{
};
fn run_server(config: &Config) -> Result<()> {
let signal = Waiter::new();
let signal = Waiter::start();
let metrics = Metrics::new(config.monitoring_addr);
metrics.start();
......
......@@ -8,7 +8,7 @@ use bitcoin_hashes::hex::{FromHex, ToHex};
use bitcoin_hashes::sha256d::Hash as Sha256dHash;
use glob;
use hex;
use serde_json::{from_str, from_value, Value};
use serde_json::{from_str, from_value, Map, Value};
use std::collections::{HashMap, HashSet};
use std::io::{BufRead, BufReader, Lines, Write};
use std::net::{SocketAddr, TcpStream};
......@@ -55,23 +55,28 @@ fn tx_from_value(value: Value) -> Result<Transaction> {
/// Parse JSONRPC error code, if exists.
fn parse_error_code(err: &Value) -> Option<i64> {
if err.is_null() {
return None;
}
err.as_object()?.get("code")?.as_i64()
}
fn parse_jsonrpc_reply(mut reply: Value, method: &str, expected_id: u64) -> Result<Value> {
if let Some(reply_obj) = reply.as_object_mut() {
if let Some(err) = reply_obj.get("error") {
if !err.is_null() {
if let Some(code) = parse_error_code(&err) {
match code {
// RPC_IN_WARMUP -> retry by later reconnection
-28 => bail!(ErrorKind::Connection(err.to_string())),
_ => (),
}
}
bail!("{} RPC error: {}", method, err);
fn check_error_code(reply_obj: &Map<String, Value>, method: &str) -> Result<()> {
if let Some(err) = reply_obj.get("error") {
if let Some(code) = parse_error_code(&err) {
match code {
// RPC_IN_WARMUP -> retry by later reconnection
-28 => bail!(ErrorKind::Connection(err.to_string())),
_ => bail!("{} RPC error: {}", method, err),
}
}
}
Ok(())
}
fn parse_jsonrpc_reply(mut reply: Value, method: &str, expected_id: u64) -> Result<Value> {
if let Some(reply_obj) = reply.as_object_mut() {
check_error_code(reply_obj, method)?;
let id = reply_obj
.get("id")
.chain_err(|| format!("no id in reply: {:?}", reply_obj))?
......@@ -612,7 +617,7 @@ impl Daemon {
bestblockhash: &Sha256dHash,
) -> Result<Vec<BlockHeader>> {
// Iterate back over headers until known blockash is found:
if indexed_headers.len() == 0 {
if indexed_headers.is_empty() {
return self.get_all_headers(bestblockhash);
}
debug!(
......
......@@ -133,7 +133,7 @@ impl TxRow {
}
}
pub fn filter_prefix(txid_prefix: &HashPrefix) -> Bytes {
pub fn filter_prefix(txid_prefix: HashPrefix) -> Bytes {
[b"T", &txid_prefix[..]].concat()
}
......
......@@ -149,9 +149,9 @@ fn txrow_by_txid(store: &ReadStore, txid: &Sha256dHash) -> Option<TxRow> {
Some(TxRow::from_row(&Row { key, value }))
}
fn txrows_by_prefix(store: &ReadStore, txid_prefix: &HashPrefix) -> Vec<TxRow> {
fn txrows_by_prefix(store: &ReadStore, txid_prefix: HashPrefix) -> Vec<TxRow> {
store
.scan(&TxRow::filter_prefix(&txid_prefix))
.scan(&TxRow::filter_prefix(txid_prefix))
.iter()
.map(|row| TxRow::from_row(row))
.collect()
......@@ -230,7 +230,7 @@ impl Query {
) -> Result<Vec<TxnHeight>> {
let mut txns = vec![];
for txid_prefix in prefixes {
for tx_row in txrows_by_prefix(store, &txid_prefix) {
for tx_row in txrows_by_prefix(store, txid_prefix) {
let txid: Sha256dHash = deserialize(&tx_row.key.txid).unwrap();
let txn = self
.tx_cache
......
......@@ -503,7 +503,7 @@ impl RPC {
}
fn start_acceptor(addr: SocketAddr) -> Channel<Option<(TcpStream, SocketAddr)>> {
let chan = Channel::new();
let chan = Channel::unbounded();
let acceptor = chan.sender();
spawn_thread("acceptor", move || {
let listener =
......@@ -531,7 +531,7 @@ impl RPC {
"# of Electrum subscriptions",
)),
});
let notification = Channel::new();
let notification = Channel::unbounded();
RPC {
notification: notification.sender(),
server: Some(spawn_thread("rpc", move || {
......
......@@ -10,7 +10,7 @@ pub struct Waiter {
}
impl Waiter {
pub fn new() -> Waiter {
pub fn start() -> Waiter {
Waiter {
signal: chan_signal::notify(&[chan_signal::Signal::INT, chan_signal::Signal::TERM]),
}
......
......@@ -187,6 +187,10 @@ impl HeaderList {
self.headers.len()
}
pub fn is_empty(&self) -> bool {
self.headers.is_empty()
}
pub fn iter(&self) -> slice::Iter<HeaderEntry> {
self.headers.iter()
}
......@@ -222,7 +226,7 @@ pub struct Channel<T> {
}
impl<T> Channel<T> {
pub fn new() -> Channel<T> {
pub fn unbounded() -> Self {
let (tx, rx) = channel();
Channel { tx, rx }
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment