Switch to Rust 2018 edition.

This commit is contained in:
DrPeterVanNostrand 2018-12-12 22:58:09 +00:00
parent 2c93f26af5
commit 0150df2f8e
13 changed files with 46 additions and 73 deletions

View File

@ -2,7 +2,7 @@
name = "poagov" name = "poagov"
version = "1.0.0" version = "1.0.0"
authors = ["DrPeterVanNostrand <jnz@riseup.net>"] authors = ["DrPeterVanNostrand <jnz@riseup.net>"]
# edition = "2018" edition = "2018"
readme = "README.md" readme = "README.md"
license = "GPL-3.0" license = "GPL-3.0"
repository = "https://github.com/poanetwork/poa-governance-notifications" repository = "https://github.com/poanetwork/poa-governance-notifications"

View File

@ -49,7 +49,7 @@ To build the `poagov` CLI tool, run the following:
$ cd poa-governance-notifications $ cd poa-governance-notifications
$ cargo build --release $ 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. see the following "Requires libssl" section for more information.
### Testing ### Testing

View File

@ -5,9 +5,9 @@ use std::time::Duration;
use web3::types::BlockNumber; use web3::types::BlockNumber;
use client::RpcClient; use crate::client::RpcClient;
use config::{Config, StartBlock}; use crate::config::{Config, StartBlock};
use error::{Error, Result}; use crate::error::{Error, Result};
fn sleep_or_ctrlc(n_secs: u64, running: Arc<AtomicBool>) -> Option<()> { fn sleep_or_ctrlc(n_secs: u64, running: Arc<AtomicBool>) -> Option<()> {
let done_sleeping = Arc::new(AtomicBool::new(false)); let done_sleeping = Arc::new(AtomicBool::new(false));

View File

@ -1,3 +1,4 @@
// Some of `Cli`'s methods are not currently being used.
#![allow(dead_code)] #![allow(dead_code)]
use clap::{ArgMatches, App}; use clap::{ArgMatches, App};

View File

@ -1,17 +1,13 @@
use std::u64; use std::u64;
use ethabi;
use hex;
use jsonrpc_core as json_rpc; use jsonrpc_core as json_rpc;
use reqwest;
use serde_json as json; use serde_json as json;
use web3;
use web3::types::{Address, BlockNumber, Filter, FilterBuilder, U256}; use web3::types::{Address, BlockNumber, Filter, FilterBuilder, U256};
use config::{ContractType, PoaContract}; use crate::config::{ContractType, PoaContract};
use error::{Error, Result}; use crate::error::{Error, Result};
use response::{v1, v2}; use crate::response::{v1, v2};
use response::common::BallotCreatedLog; use crate::response::common::BallotCreatedLog;
#[derive(Debug)] #[derive(Debug)]
pub enum RpcMethod { pub enum RpcMethod {
@ -212,9 +208,9 @@ mod tests {
use web3::types::BlockNumber; use web3::types::BlockNumber;
use super::super::tests::setup; use crate::tests::setup;
use crate::config::{ContractType, ContractVersion, Network, PoaContract};
use super::RpcClient; use super::RpcClient;
use config::{ContractType, ContractVersion, Network, PoaContract};
#[test] #[test]
fn test_get_last_mined_block() { fn test_get_last_mined_block() {

View File

@ -1,13 +1,13 @@
use std::env; use std::env;
use std::fmt::{self, Debug, Formatter}; use std::fmt::{self, Debug, Formatter};
use std::fs::File; use std::fs::File;
use std::str::FromStr; use std::str::FromStr as _FromStr;
use ethabi::{Address, Contract, Event, Function}; use ethabi::{Address, Contract, Event, Function};
use cli::Cli; use crate::cli::Cli;
use error::{Error, Result}; use crate::error::{Error, Result};
use response::common::BallotType; use crate::response::common::BallotType;
const DEFAULT_BLOCK_TIME_SECS: u64 = 30; const DEFAULT_BLOCK_TIME_SECS: u64 = 30;

View File

@ -1,11 +1,3 @@
use ctrlc;
use jsonrpc_core;
use ethabi;
use failure;
use lettre;
use native_tls;
use reqwest;
pub type Result<T> = ::std::result::Result<T, Error>; pub type Result<T> = ::std::result::Result<T, Error>;
#[derive(Debug)] #[derive(Debug)]

View File

@ -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::io::stderr;
use std::path::Path; use std::path::Path;
use chrono::{DateTime, TimeZone, Utc}; use chrono::{DateTime, TimeZone as _TimeZone, Utc};
use slog::{self, Drain}; use slog::{info, o, warn, Drain as _Drain};
use slog_term::{FullFormat, PlainSyncDecorator}; use slog_term::{FullFormat, PlainSyncDecorator};
use web3::types::BlockNumber; use web3::types::BlockNumber;
use config::Config; use crate::config::Config;
use error::Error; use crate::error::Error;
use notify::Notification; use crate::notify::Notification;
// The date format used to name log files; e.g. "Oct-08-2018-14:09:00". // 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"; const FILE_NAME_DATE_FORMAT: &str = "%b-%d-%Y-%H:%M:%S";
// The directory (relative to Cargo.toml) to store logs. // The directory (relative to Cargo.toml) to store logs.
const LOGS_DIR: &str = "logs"; const LOGS_DIR: &str = "logs";
const MAX_NUMBER_OF_LOG_FILES: usize = 3; const MAX_NUMBER_OF_LOG_FILES: usize = 3;
const MAX_LOG_FILE_SIZE_MB: usize = 4; const MAX_LOG_FILE_SIZE_MB: usize = 4;
const MAX_LOG_FILE_SIZE_BYTES: usize = MAX_LOG_FILE_SIZE_MB * 1024 * 1024; 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 // 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 // "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. // average log is around 100 ASCII characters (bytes) long.

View File

@ -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 blockchain;
mod cli; mod cli;
mod client; mod client;
@ -31,13 +10,15 @@ mod response;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use blockchain::BlockchainIter; use lazy_static::lazy_static;
use cli::parse_cli;
use client::RpcClient; use crate::blockchain::BlockchainIter;
use config::{Config, ContractVersion}; use crate::cli::parse_cli;
use error::{Error, Result}; use crate::client::RpcClient;
use logger::Logger; use crate::config::{Config, ContractVersion};
use notify::{Notification, Notifier}; use crate::error::{Error, Result};
use crate::logger::Logger;
use crate::notify::{Notification, Notifier};
lazy_static! { lazy_static! {
// Tracks whether or not the environment variables have been loaded from the .env file. // Tracks whether or not the environment variables have been loaded from the .env file.

View File

@ -1,18 +1,18 @@
use std::sync::{Arc, Mutex}; 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::{ClientSecurity, ConnectionReuseParameters, SmtpClient, SmtpTransport};
use lettre::smtp::authentication::{Credentials, Mechanism}; use lettre::smtp::authentication::{Credentials, Mechanism};
use lettre::smtp::client::net::ClientTlsParameters; use lettre::smtp::client::net::ClientTlsParameters;
use lettre_email::{Email, EmailBuilder}; use lettre_email::{Email, EmailBuilder};
use native_tls::TlsConnector; use native_tls::TlsConnector;
use config::Config; use crate::config::Config;
use error::{Error, Result}; use crate::error::{Error, Result};
use logger::Logger; use crate::logger::Logger;
use response::common::BallotCreatedLog; use crate::response::common::BallotCreatedLog;
use response::v1::VotingState; use crate::response::v1::VotingState;
use response::v2::BallotInfo; use crate::response::v2::BallotInfo;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Notification<'a> { pub enum Notification<'a> {
@ -37,7 +37,7 @@ impl<'a> Notification<'a> {
{ {
Notification::VotingState { config, log, voting_state } Notification::VotingState { config, log, voting_state }
} }
pub fn from_ballot_info( pub fn from_ballot_info(
config: &'a Config, config: &'a Config,
log: BallotCreatedLog, log: BallotCreatedLog,
@ -79,7 +79,7 @@ impl<'a> Notification<'a> {
Notification::BallotInfo { log, .. } => log, Notification::BallotInfo { log, .. } => log,
} }
} }
fn contract_name(&self) -> String { fn contract_name(&self) -> String {
match self { match self {
Notification::VotingState { voting_state, .. } => voting_state.contract_name(), Notification::VotingState { voting_state, .. } => voting_state.contract_name(),

View File

@ -5,7 +5,7 @@ use chrono::{DateTime, NaiveDateTime, Utc};
use ethabi; use ethabi;
use web3::types::{Address, H256, U256}; use web3::types::{Address, H256, U256};
use error::{Error, Result}; use crate::error::{Error, Result};
/// Converts a `U256` timestamp to a UTC `DateTime`. /// Converts a `U256` timestamp to a UTC `DateTime`.
pub fn u256_to_datetime(uint: U256) -> DateTime<Utc> { pub fn u256_to_datetime(uint: U256) -> DateTime<Utc> {

View File

@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use ethabi; use ethabi;
use web3::types::{Address, U256}; 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. /// Describes the current state of a given ballot.
/// ///

View File

@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use ethabi; use ethabi;
use web3::types::{Address, U256}; 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)] #[derive(Clone, Debug)]
pub enum BallotInfo { pub enum BallotInfo {