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"
version = "1.0.0"
authors = ["DrPeterVanNostrand <jnz@riseup.net>"]
# edition = "2018"
edition = "2018"
readme = "README.md"
license = "GPL-3.0"
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
$ 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

View File

@ -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<AtomicBool>) -> Option<()> {
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)]
use clap::{ArgMatches, App};

View File

@ -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() {

View File

@ -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;

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>;
#[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::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.

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 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.

View File

@ -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(),

View File

@ -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<Utc> {

View File

@ -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.
///

View File

@ -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 {