diff --git a/Cargo.toml b/Cargo.toml index 2c76990..cfef1ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "poagov" version = "1.0.0" authors = ["DrPeterVanNostrand "] -# edition = "2018" +edition = "2018" readme = "README.md" license = "GPL-3.0" repository = "https://github.com/poanetwork/poa-governance-notifications" diff --git a/README.md b/README.md index e039771..811d275 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ To build the `poagov` CLI tool, run the following: $ cd poa-governance-notifications $ cargo build --release -`poagov` can be built with Rust 1.29.1-stable or later and requires `libssl`; +`poagov` can be built with Rust 1.31.0-stable or later and requires `libssl`; see the following "Requires libssl" section for more information. ### Testing diff --git a/src/blockchain.rs b/src/blockchain.rs index caa721f..13d5601 100644 --- a/src/blockchain.rs +++ b/src/blockchain.rs @@ -5,9 +5,9 @@ use std::time::Duration; use web3::types::BlockNumber; -use client::RpcClient; -use config::{Config, StartBlock}; -use error::{Error, Result}; +use crate::client::RpcClient; +use crate::config::{Config, StartBlock}; +use crate::error::{Error, Result}; fn sleep_or_ctrlc(n_secs: u64, running: Arc) -> Option<()> { let done_sleeping = Arc::new(AtomicBool::new(false)); diff --git a/src/cli.rs b/src/cli.rs index 458721a..97c227e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,3 +1,4 @@ +// Some of `Cli`'s methods are not currently being used. #![allow(dead_code)] use clap::{ArgMatches, App}; diff --git a/src/client.rs b/src/client.rs index d6fe448..b3cefa1 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,17 +1,13 @@ use std::u64; -use ethabi; -use hex; use jsonrpc_core as json_rpc; -use reqwest; use serde_json as json; -use web3; use web3::types::{Address, BlockNumber, Filter, FilterBuilder, U256}; -use config::{ContractType, PoaContract}; -use error::{Error, Result}; -use response::{v1, v2}; -use response::common::BallotCreatedLog; +use crate::config::{ContractType, PoaContract}; +use crate::error::{Error, Result}; +use crate::response::{v1, v2}; +use crate::response::common::BallotCreatedLog; #[derive(Debug)] pub enum RpcMethod { @@ -212,9 +208,9 @@ mod tests { use web3::types::BlockNumber; - use super::super::tests::setup; + use crate::tests::setup; + use crate::config::{ContractType, ContractVersion, Network, PoaContract}; use super::RpcClient; - use config::{ContractType, ContractVersion, Network, PoaContract}; #[test] fn test_get_last_mined_block() { diff --git a/src/config.rs b/src/config.rs index e8c2704..d02ce5c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,13 +1,13 @@ use std::env; use std::fmt::{self, Debug, Formatter}; use std::fs::File; -use std::str::FromStr; +use std::str::FromStr as _FromStr; use ethabi::{Address, Contract, Event, Function}; -use cli::Cli; -use error::{Error, Result}; -use response::common::BallotType; +use crate::cli::Cli; +use crate::error::{Error, Result}; +use crate::response::common::BallotType; const DEFAULT_BLOCK_TIME_SECS: u64 = 30; diff --git a/src/error.rs b/src/error.rs index 5b09c32..5a1eac6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,11 +1,3 @@ -use ctrlc; -use jsonrpc_core; -use ethabi; -use failure; -use lettre; -use native_tls; -use reqwest; - pub type Result = ::std::result::Result; #[derive(Debug)] diff --git a/src/logger.rs b/src/logger.rs index 4d5b2b2..6e45d8a 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,23 +1,26 @@ -use std::fs::{self, create_dir, File, read_dir, remove_file}; +use std::fs::{self, create_dir, read_dir, remove_file, File}; use std::io::stderr; use std::path::Path; -use chrono::{DateTime, TimeZone, Utc}; -use slog::{self, Drain}; +use chrono::{DateTime, TimeZone as _TimeZone, Utc}; +use slog::{info, o, warn, Drain as _Drain}; use slog_term::{FullFormat, PlainSyncDecorator}; use web3::types::BlockNumber; -use config::Config; -use error::Error; -use notify::Notification; +use crate::config::Config; +use crate::error::Error; +use crate::notify::Notification; // The date format used to name log files; e.g. "Oct-08-2018-14:09:00". const FILE_NAME_DATE_FORMAT: &str = "%b-%d-%Y-%H:%M:%S"; + // The directory (relative to Cargo.toml) to store logs. const LOGS_DIR: &str = "logs"; + const MAX_NUMBER_OF_LOG_FILES: usize = 3; const MAX_LOG_FILE_SIZE_MB: usize = 4; const MAX_LOG_FILE_SIZE_BYTES: usize = MAX_LOG_FILE_SIZE_MB * 1024 * 1024; + // We dont want to check the log file's size after every log that is written, this constant states // "after this many logs have been written, check the log file's size". This value assumes an // average log is around 100 ASCII characters (bytes) long. diff --git a/src/main.rs b/src/main.rs index 6f5248a..6b929dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,24 +1,3 @@ -extern crate chrono; -extern crate clap; -extern crate ctrlc; -extern crate dotenv; -extern crate ethabi; -extern crate ethereum_types; -extern crate failure; -extern crate hex; -extern crate jsonrpc_core; -#[macro_use] -extern crate lazy_static; -extern crate lettre; -extern crate lettre_email; -extern crate native_tls; -extern crate reqwest; -extern crate serde_json; -#[macro_use] -extern crate slog; -extern crate slog_term; -extern crate web3; - mod blockchain; mod cli; mod client; @@ -31,13 +10,15 @@ mod response; use std::sync::{Arc, Mutex}; use std::sync::atomic::{AtomicBool, Ordering}; -use blockchain::BlockchainIter; -use cli::parse_cli; -use client::RpcClient; -use config::{Config, ContractVersion}; -use error::{Error, Result}; -use logger::Logger; -use notify::{Notification, Notifier}; +use lazy_static::lazy_static; + +use crate::blockchain::BlockchainIter; +use crate::cli::parse_cli; +use crate::client::RpcClient; +use crate::config::{Config, ContractVersion}; +use crate::error::{Error, Result}; +use crate::logger::Logger; +use crate::notify::{Notification, Notifier}; lazy_static! { // Tracks whether or not the environment variables have been loaded from the .env file. diff --git a/src/notify.rs b/src/notify.rs index 193070a..5d68ca0 100644 --- a/src/notify.rs +++ b/src/notify.rs @@ -1,18 +1,18 @@ use std::sync::{Arc, Mutex}; -use lettre::{SendableEmail, Transport}; +use lettre::{SendableEmail, Transport as _Transport}; use lettre::smtp::{ClientSecurity, ConnectionReuseParameters, SmtpClient, SmtpTransport}; use lettre::smtp::authentication::{Credentials, Mechanism}; use lettre::smtp::client::net::ClientTlsParameters; use lettre_email::{Email, EmailBuilder}; use native_tls::TlsConnector; -use config::Config; -use error::{Error, Result}; -use logger::Logger; -use response::common::BallotCreatedLog; -use response::v1::VotingState; -use response::v2::BallotInfo; +use crate::config::Config; +use crate::error::{Error, Result}; +use crate::logger::Logger; +use crate::response::common::BallotCreatedLog; +use crate::response::v1::VotingState; +use crate::response::v2::BallotInfo; #[derive(Clone, Debug)] pub enum Notification<'a> { @@ -37,7 +37,7 @@ impl<'a> Notification<'a> { { Notification::VotingState { config, log, voting_state } } - + pub fn from_ballot_info( config: &'a Config, log: BallotCreatedLog, @@ -79,7 +79,7 @@ impl<'a> Notification<'a> { Notification::BallotInfo { log, .. } => log, } } - + fn contract_name(&self) -> String { match self { Notification::VotingState { voting_state, .. } => voting_state.contract_name(), diff --git a/src/response/common.rs b/src/response/common.rs index 286647d..d8f3b37 100644 --- a/src/response/common.rs +++ b/src/response/common.rs @@ -5,7 +5,7 @@ use chrono::{DateTime, NaiveDateTime, Utc}; use ethabi; use web3::types::{Address, H256, U256}; -use error::{Error, Result}; +use crate::error::{Error, Result}; /// Converts a `U256` timestamp to a UTC `DateTime`. pub fn u256_to_datetime(uint: U256) -> DateTime { diff --git a/src/response/v1.rs b/src/response/v1.rs index 571b746..3fa528e 100644 --- a/src/response/v1.rs +++ b/src/response/v1.rs @@ -2,7 +2,7 @@ use chrono::{DateTime, Utc}; use ethabi; use web3::types::{Address, U256}; -use response::common::{u256_to_datetime, BallotType, KeyType}; +use crate::response::common::{u256_to_datetime, BallotType, KeyType}; /// Describes the current state of a given ballot. /// diff --git a/src/response/v2.rs b/src/response/v2.rs index 53fff58..e0b6957 100644 --- a/src/response/v2.rs +++ b/src/response/v2.rs @@ -2,7 +2,7 @@ use chrono::{DateTime, Utc}; use ethabi; use web3::types::{Address, U256}; -use response::common::{u256_to_datetime, BallotType, KeyType}; +use crate::response::common::{u256_to_datetime, BallotType, KeyType}; #[derive(Clone, Debug)] pub enum BallotInfo {