mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 09:54:09 +01:00
Fix more Clippy warnings
This commit is contained in:
parent
807a200542
commit
ef54e452bf
@ -12,7 +12,7 @@ use electrs::{
|
|||||||
use error_chain::ChainedError;
|
use error_chain::ChainedError;
|
||||||
|
|
||||||
fn run() -> Result<()> {
|
fn run() -> Result<()> {
|
||||||
let signal = Waiter::new();
|
let signal = Waiter::start();
|
||||||
let config = Config::from_args();
|
let config = Config::from_args();
|
||||||
let metrics = Metrics::new(config.monitoring_addr);
|
let metrics = Metrics::new(config.monitoring_addr);
|
||||||
metrics.start();
|
metrics.start();
|
||||||
|
@ -23,7 +23,7 @@ use electrs::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
fn run_server(config: &Config) -> Result<()> {
|
fn run_server(config: &Config) -> Result<()> {
|
||||||
let signal = Waiter::new();
|
let signal = Waiter::start();
|
||||||
let metrics = Metrics::new(config.monitoring_addr);
|
let metrics = Metrics::new(config.monitoring_addr);
|
||||||
metrics.start();
|
metrics.start();
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use bitcoin_hashes::hex::{FromHex, ToHex};
|
|||||||
use bitcoin_hashes::sha256d::Hash as Sha256dHash;
|
use bitcoin_hashes::sha256d::Hash as Sha256dHash;
|
||||||
use glob;
|
use glob;
|
||||||
use hex;
|
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::collections::{HashMap, HashSet};
|
||||||
use std::io::{BufRead, BufReader, Lines, Write};
|
use std::io::{BufRead, BufReader, Lines, Write};
|
||||||
use std::net::{SocketAddr, TcpStream};
|
use std::net::{SocketAddr, TcpStream};
|
||||||
@ -55,23 +55,28 @@ fn tx_from_value(value: Value) -> Result<Transaction> {
|
|||||||
|
|
||||||
/// Parse JSONRPC error code, if exists.
|
/// Parse JSONRPC error code, if exists.
|
||||||
fn parse_error_code(err: &Value) -> Option<i64> {
|
fn parse_error_code(err: &Value) -> Option<i64> {
|
||||||
|
if err.is_null() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
err.as_object()?.get("code")?.as_i64()
|
err.as_object()?.get("code")?.as_i64()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_jsonrpc_reply(mut reply: Value, method: &str, expected_id: u64) -> Result<Value> {
|
fn check_error_code(reply_obj: &Map<String, Value>, method: &str) -> Result<()> {
|
||||||
if let Some(reply_obj) = reply.as_object_mut() {
|
|
||||||
if let Some(err) = reply_obj.get("error") {
|
if let Some(err) = reply_obj.get("error") {
|
||||||
if !err.is_null() {
|
|
||||||
if let Some(code) = parse_error_code(&err) {
|
if let Some(code) = parse_error_code(&err) {
|
||||||
match code {
|
match code {
|
||||||
// RPC_IN_WARMUP -> retry by later reconnection
|
// RPC_IN_WARMUP -> retry by later reconnection
|
||||||
-28 => bail!(ErrorKind::Connection(err.to_string())),
|
-28 => bail!(ErrorKind::Connection(err.to_string())),
|
||||||
_ => (),
|
_ => bail!("{} RPC error: {}", method, err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
let id = reply_obj
|
||||||
.get("id")
|
.get("id")
|
||||||
.chain_err(|| format!("no id in reply: {:?}", reply_obj))?
|
.chain_err(|| format!("no id in reply: {:?}", reply_obj))?
|
||||||
@ -612,7 +617,7 @@ impl Daemon {
|
|||||||
bestblockhash: &Sha256dHash,
|
bestblockhash: &Sha256dHash,
|
||||||
) -> Result<Vec<BlockHeader>> {
|
) -> Result<Vec<BlockHeader>> {
|
||||||
// Iterate back over headers until known blockash is found:
|
// 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);
|
return self.get_all_headers(bestblockhash);
|
||||||
}
|
}
|
||||||
debug!(
|
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()
|
[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 }))
|
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
|
store
|
||||||
.scan(&TxRow::filter_prefix(&txid_prefix))
|
.scan(&TxRow::filter_prefix(txid_prefix))
|
||||||
.iter()
|
.iter()
|
||||||
.map(|row| TxRow::from_row(row))
|
.map(|row| TxRow::from_row(row))
|
||||||
.collect()
|
.collect()
|
||||||
@ -230,7 +230,7 @@ impl Query {
|
|||||||
) -> Result<Vec<TxnHeight>> {
|
) -> Result<Vec<TxnHeight>> {
|
||||||
let mut txns = vec![];
|
let mut txns = vec![];
|
||||||
for txid_prefix in prefixes {
|
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 txid: Sha256dHash = deserialize(&tx_row.key.txid).unwrap();
|
||||||
let txn = self
|
let txn = self
|
||||||
.tx_cache
|
.tx_cache
|
||||||
|
@ -503,7 +503,7 @@ impl RPC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start_acceptor(addr: SocketAddr) -> Channel<Option<(TcpStream, SocketAddr)>> {
|
fn start_acceptor(addr: SocketAddr) -> Channel<Option<(TcpStream, SocketAddr)>> {
|
||||||
let chan = Channel::new();
|
let chan = Channel::unbounded();
|
||||||
let acceptor = chan.sender();
|
let acceptor = chan.sender();
|
||||||
spawn_thread("acceptor", move || {
|
spawn_thread("acceptor", move || {
|
||||||
let listener =
|
let listener =
|
||||||
@ -531,7 +531,7 @@ impl RPC {
|
|||||||
"# of Electrum subscriptions",
|
"# of Electrum subscriptions",
|
||||||
)),
|
)),
|
||||||
});
|
});
|
||||||
let notification = Channel::new();
|
let notification = Channel::unbounded();
|
||||||
RPC {
|
RPC {
|
||||||
notification: notification.sender(),
|
notification: notification.sender(),
|
||||||
server: Some(spawn_thread("rpc", move || {
|
server: Some(spawn_thread("rpc", move || {
|
||||||
|
@ -10,7 +10,7 @@ pub struct Waiter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Waiter {
|
impl Waiter {
|
||||||
pub fn new() -> Waiter {
|
pub fn start() -> Waiter {
|
||||||
Waiter {
|
Waiter {
|
||||||
signal: chan_signal::notify(&[chan_signal::Signal::INT, chan_signal::Signal::TERM]),
|
signal: chan_signal::notify(&[chan_signal::Signal::INT, chan_signal::Signal::TERM]),
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,10 @@ impl HeaderList {
|
|||||||
self.headers.len()
|
self.headers.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.headers.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn iter(&self) -> slice::Iter<HeaderEntry> {
|
pub fn iter(&self) -> slice::Iter<HeaderEntry> {
|
||||||
self.headers.iter()
|
self.headers.iter()
|
||||||
}
|
}
|
||||||
@ -222,7 +226,7 @@ pub struct Channel<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Channel<T> {
|
impl<T> Channel<T> {
|
||||||
pub fn new() -> Channel<T> {
|
pub fn unbounded() -> Self {
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
Channel { tx, rx }
|
Channel { tx, rx }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user