From 5f2d4289dcb98ef283725b3d12f8733a7b9e832b Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sat, 22 Sep 2018 12:42:56 +0300 Subject: [PATCH] Support Rust 2018 edition Builds on Rust 1.31 --- Cargo.toml | 1 + src/app.rs | 4 +--- src/bulk.rs | 13 ++++++------- src/config.rs | 5 ++--- src/daemon.rs | 9 ++++----- src/fake.rs | 8 ++++---- src/index.rs | 15 ++++++++------- src/lib.rs | 20 -------------------- src/mempool.rs | 15 ++++++++------- src/metrics.rs | 5 ++--- src/notify.rs | 2 +- src/query.rs | 17 ++++++++--------- src/rpc.rs | 11 +++++------ src/signal.rs | 2 +- src/store.rs | 3 +-- 15 files changed, 52 insertions(+), 78 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 11cb0d7..3da96be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ repository = "https://github.com/romanz/electrs" keywords = ["bitcoin", "electrum", "server", "index", "database"] documentation = "https://docs.rs/electrs/" readme = "README.md" +edition = "2018" [dependencies] arrayref = "0.3" diff --git a/src/app.rs b/src/app.rs index 7999236..bac1598 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,9 +1,7 @@ use bitcoin::util::hash::Sha256dHash; use std::sync::{Arc, Mutex}; -use {daemon, index, signal::Waiter, store}; - -use errors::*; +use crate::{daemon, errors::*, index, signal::Waiter, store}; pub struct App { store: store::DBStore, diff --git a/src/bulk.rs b/src/bulk.rs index 4edf664..55aef17 100644 --- a/src/bulk.rs +++ b/src/bulk.rs @@ -12,13 +12,12 @@ use std::sync::{ }; use std::thread; -use daemon::Daemon; -use index::{index_block, last_indexed_block, read_indexed_blockhashes}; -use metrics::{CounterVec, Histogram, HistogramOpts, HistogramVec, MetricOpts, Metrics}; -use store::{DBStore, Row, WriteStore}; -use util::{spawn_thread, HeaderList, SyncChannel}; - -use errors::*; +use crate::daemon::Daemon; +use crate::errors::*; +use crate::index::{index_block, last_indexed_block, read_indexed_blockhashes}; +use crate::metrics::{CounterVec, Histogram, HistogramOpts, HistogramVec, MetricOpts, Metrics}; +use crate::store::{DBStore, Row, WriteStore}; +use crate::util::{spawn_thread, HeaderList, SyncChannel}; struct Parser { magic: u32, diff --git a/src/config.rs b/src/config.rs index 9fbd2af..c3d599e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,9 +8,8 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use stderrlog; -use daemon::CookieGetter; - -use errors::*; +use crate::daemon::CookieGetter; +use crate::errors::*; #[derive(Debug)] pub struct Config { diff --git a/src/daemon.rs b/src/daemon.rs index bb6b671..221a91b 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -15,11 +15,10 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex}; use std::time::Duration; -use metrics::{HistogramOpts, HistogramVec, Metrics}; -use signal::Waiter; -use util::HeaderList; - -use errors::*; +use crate::errors::*; +use crate::metrics::{HistogramOpts, HistogramVec, Metrics}; +use crate::signal::Waiter; +use crate::util::HeaderList; fn parse_hash(value: &Value) -> Result { Ok(Sha256dHash::from_hex( diff --git a/src/fake.rs b/src/fake.rs index 2f42475..ac9ec33 100644 --- a/src/fake.rs +++ b/src/fake.rs @@ -1,5 +1,5 @@ -use store::{ReadStore, Row, WriteStore}; -use util::Bytes; +use crate::store::{ReadStore, Row, WriteStore}; +use crate::util::Bytes; pub struct FakeStore; @@ -21,8 +21,8 @@ impl WriteStore for FakeStore { mod tests { #[test] fn test_fakestore() { - use fake; - use store::{ReadStore, Row, WriteStore}; + use crate::fake; + use crate::store::{ReadStore, Row, WriteStore}; let store = fake::FakeStore {}; store.write(vec![Row { diff --git a/src/index.rs b/src/index.rs index 176a479..860c25d 100644 --- a/src/index.rs +++ b/src/index.rs @@ -10,17 +10,18 @@ use std::collections::{HashMap, HashSet}; use std::iter::FromIterator; use std::sync::RwLock; -use daemon::Daemon; -use metrics::{Counter, Gauge, HistogramOpts, HistogramTimer, HistogramVec, MetricOpts, Metrics}; -use signal::Waiter; -use store::{ReadStore, Row, WriteStore}; -use util::{ +use crate::daemon::Daemon; +use crate::errors::*; +use crate::metrics::{ + Counter, Gauge, HistogramOpts, HistogramTimer, HistogramVec, MetricOpts, Metrics, +}; +use crate::signal::Waiter; +use crate::store::{ReadStore, Row, WriteStore}; +use crate::util::{ full_hash, hash_prefix, spawn_thread, Bytes, FullHash, HashPrefix, HeaderEntry, HeaderList, HeaderMap, SyncChannel, HASH_PREFIX_LEN, }; -use errors::*; - #[derive(Serialize, Deserialize)] pub struct TxInKey { pub code: u8, diff --git a/src/lib.rs b/src/lib.rs index 0a4902b..5e89e30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,25 +1,5 @@ #![recursion_limit = "1024"] -extern crate base64; -extern crate bincode; -extern crate bitcoin; -extern crate chan_signal; -extern crate crypto; -extern crate dirs; -extern crate glob; -extern crate hex; -extern crate libc; -extern crate lru; -extern crate num_cpus; -extern crate page_size; -extern crate prometheus; -extern crate rocksdb; -extern crate serde; -extern crate stderrlog; -extern crate sysconf; -extern crate time; -extern crate tiny_http; - #[macro_use] extern crate chan; #[macro_use] diff --git a/src/mempool.rs b/src/mempool.rs index ad09b28..38d8293 100644 --- a/src/mempool.rs +++ b/src/mempool.rs @@ -6,13 +6,14 @@ use std::iter::FromIterator; use std::ops::Bound; use std::sync::Mutex; -use daemon::{Daemon, MempoolEntry}; -use index::index_transaction; -use metrics::{Gauge, GaugeVec, HistogramOpts, HistogramTimer, HistogramVec, MetricOpts, Metrics}; -use store::{ReadStore, Row}; -use util::Bytes; - -use errors::*; +use crate::daemon::{Daemon, MempoolEntry}; +use crate::errors::*; +use crate::index::index_transaction; +use crate::metrics::{ + Gauge, GaugeVec, HistogramOpts, HistogramTimer, HistogramVec, MetricOpts, Metrics, +}; +use crate::store::{ReadStore, Row}; +use crate::util::Bytes; const VSIZE_BIN_WIDTH: u32 = 100_000; // in vbytes diff --git a/src/metrics.rs b/src/metrics.rs index c5332b5..5e24b38 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -13,9 +13,8 @@ pub use prometheus::{ IntCounterVec as CounterVec, IntGauge as Gauge, Opts as MetricOpts, }; -use util::spawn_thread; - -use errors::*; +use crate::errors::*; +use crate::util::spawn_thread; pub struct Metrics { reg: prometheus::Registry, diff --git a/src/notify.rs b/src/notify.rs index 057d3c5..710aea7 100644 --- a/src/notify.rs +++ b/src/notify.rs @@ -11,7 +11,7 @@ use std::sync::mpsc::Sender; use std::thread; use std::time::Duration; -use util; +use crate::util; fn connect() -> Result { let mut sock = Socket::new(Network::Bitcoin); diff --git a/src/query.rs b/src/query.rs index 9ae5cd4..d38cab7 100644 --- a/src/query.rs +++ b/src/query.rs @@ -4,18 +4,17 @@ use bitcoin::util::hash::Sha256dHash; use crypto::digest::Digest; use crypto::sha2::Sha256; use lru::LruCache; +use serde_json::Value; use std::collections::HashMap; use std::sync::{Arc, Mutex, RwLock}; -use app::App; -use index::{compute_script_hash, TxInRow, TxOutRow, TxRow}; -use mempool::Tracker; -use metrics::Metrics; -use serde_json::Value; -use store::{ReadStore, Row}; -use util::{FullHash, HashPrefix, HeaderEntry}; - -use errors::*; +use crate::app::App; +use crate::errors::*; +use crate::index::{compute_script_hash, TxInRow, TxOutRow, TxRow}; +use crate::mempool::Tracker; +use crate::metrics::Metrics; +use crate::store::{ReadStore, Row}; +use crate::util::{FullHash, HashPrefix, HeaderEntry}; pub struct FundingOutput { pub txn_id: Sha256dHash, diff --git a/src/rpc.rs b/src/rpc.rs index d27765b..8da32b5 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -13,12 +13,11 @@ use std::sync::mpsc::{Sender, SyncSender, TrySendError}; use std::sync::{Arc, Mutex}; use std::thread; -use index::compute_script_hash; -use metrics::{Gauge, HistogramOpts, HistogramVec, MetricOpts, Metrics}; -use query::{Query, Status}; -use util::{spawn_thread, Channel, HeaderEntry, SyncChannel}; - -use errors::*; +use crate::errors::*; +use crate::index::compute_script_hash; +use crate::metrics::{Gauge, HistogramOpts, HistogramVec, MetricOpts, Metrics}; +use crate::query::{Query, Status}; +use crate::util::{spawn_thread, Channel, HeaderEntry, SyncChannel}; // TODO: Sha256dHash should be a generic hash-container (since script hash is single SHA256) fn hash_from_value(val: Option<&Value>) -> Result { diff --git a/src/signal.rs b/src/signal.rs index b878706..75929ad 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -2,7 +2,7 @@ use chan; use chan_signal; use std::time::Duration; -use errors::*; +use crate::errors::*; #[derive(Clone)] // so multiple threads could wait on signals pub struct Waiter { diff --git a/src/store.rs b/src/store.rs index 23824f6..9dde71e 100644 --- a/src/store.rs +++ b/src/store.rs @@ -1,8 +1,7 @@ use rocksdb; - use std::path::{Path, PathBuf}; -use util::Bytes; +use crate::util::Bytes; #[derive(Clone)] pub struct Row {