Upgrade to Rust 2018, update deps.

This commit is contained in:
Andreas Fackler 2018-12-13 12:26:15 +01:00 committed by Andreas Fackler
parent 056738b7ac
commit 744c5bda28
9 changed files with 485 additions and 569 deletions

View File

@ -5,7 +5,7 @@ dist: trusty
language: rust language: rust
services: docker services: docker
sudo: required sudo: required
rust: 1.29.0 rust: 1.31.0
cache: cargo cache: cargo
env: env:

966
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -3,17 +3,17 @@ name = "poa-ballot-stats"
version = "0.4.0" version = "0.4.0"
authors = ["Andreas Fackler <AndreasFackler@gmx.de>"] authors = ["Andreas Fackler <AndreasFackler@gmx.de>"]
description = "Read POA voting records and rank voters by how many ballots they missed." description = "Read POA voting records and rank voters by how many ballots they missed."
edition = "2018"
[dependencies] [dependencies]
clap = "2.31.2" clap = "2.31.2"
colored = "1.6.0" colored = "1.6.0"
error-chain = { version = "0.12", default-features = false } error-chain = { version = "0.12", default-features = false }
ethabi = "6.0.1" ethabi = "6.1.0"
ethabi-contract = "6.0.0" ethabi-contract = "6.0.0"
ethabi-derive = "6.0.2" ethabi-derive = "6.0.2"
parse_duration = "1.0.1" parse_duration = "1.0.1"
serde = "1.0.36" serde = "1.0.82"
serde_derive = "1.0.36" serde_derive = "1.0.82"
serde_json = "1.0.13" serde_json = "1.0.33"
# TODO: Remove ws once https://github.com/tomusdrw/rust-web3/issues/157 is fixed. web3 = { version = "0.5.1", default-features = false, features = ["http", "tls"] }
web3 = { version = "0.4.0", default-features = false, features = ["http", "tls", "ws"] }

View File

@ -15,29 +15,34 @@ pub fn get_matches() -> ArgMatches<'static> {
.value_name("URL") .value_name("URL")
.help("The JSON-RPC endpoint") .help("The JSON-RPC endpoint")
.takes_value(true), .takes_value(true),
).arg( )
.arg(
Arg::with_name("verbose") Arg::with_name("verbose")
.short("v") .short("v")
.long("verbose") .long("verbose")
.help("More detailed output") .help("More detailed output")
.takes_value(false), .takes_value(false),
).arg( )
.arg(
Arg::with_name("contracts") Arg::with_name("contracts")
.short("c") .short("c")
.long("contracts") .long("contracts")
.help("JSON file with the contract addresses") .help("JSON file with the contract addresses")
.takes_value(true), .takes_value(true),
).arg( )
.arg(
Arg::with_name("period") Arg::with_name("period")
.short("p") .short("p")
.long("period") .long("period")
.help("The period in which votes should be counted, e.g. '5 days', '2 months'.") .help("The period in which votes should be counted, e.g. '5 days', '2 months'.")
.takes_value(true), .takes_value(true),
).arg( )
.arg(
Arg::with_name("block") Arg::with_name("block")
.short("b") .short("b")
.long("block") .long("block")
.help("The earliest block in which votes should be counted.") .help("The earliest block in which votes should be counted.")
.takes_value(true), .takes_value(true),
).get_matches() )
.get_matches()
} }

View File

@ -1,9 +1,11 @@
use ethabi::Address; use ethabi::Address;
use serde_derive::Deserialize;
// The `use_contract!` macro triggers several Clippy warnings. // The `use_contract!` macro triggers several Clippy warnings.
#[cfg_attr( #[allow(
feature = "cargo-clippy", clippy::too_many_arguments,
allow(too_many_arguments, redundant_closure, needless_update) clippy::redundant_closure,
clippy::needless_update
)] )]
pub mod v2 { pub mod v2 {
use_contract!(key_mgr, "abi/v2/KeysManager.abi.json"); use_contract!(key_mgr, "abi/v2/KeysManager.abi.json");
@ -12,10 +14,7 @@ pub mod v2 {
} }
// The `use_contract!` macro triggers several Clippy warnings. // The `use_contract!` macro triggers several Clippy warnings.
#[cfg_attr( #[allow(clippy::redundant_closure, clippy::needless_update)]
feature = "cargo-clippy",
allow(too_many_arguments, redundant_closure, needless_update)
)]
pub mod v1 { pub mod v1 {
use_contract!(voting, "abi/v1/VotingToChangeKeys.abi.json"); use_contract!(voting, "abi/v1/VotingToChangeKeys.abi.json");
} }

View File

@ -1,17 +1,17 @@
use crate::contracts::v1::voting::events::{ballot_created as ballot_created_v1, vote as vote_v1};
use crate::contracts::v2::key_mgr::events::voting_key_changed;
use crate::contracts::v2::key_mgr::functions::get_mining_key_by_voting;
use crate::contracts::v2::val_meta::functions::validators as validators_fn;
use crate::contracts::v2::voting::events::{ballot_created, vote};
use crate::contracts::ContractAddresses;
use crate::error::{Error, ErrorKind};
use crate::stats::Stats;
use crate::util::{self, HexList, IntoBallot, TopicFilterExt, Web3LogExt};
use colored::{Color, Colorize}; use colored::{Color, Colorize};
use contracts::v1::voting::events::{ballot_created as ballot_created_v1, vote as vote_v1};
use contracts::v2::key_mgr::events::voting_key_changed;
use contracts::v2::key_mgr::functions::get_mining_key_by_voting;
use contracts::v2::val_meta::functions::validators as validators_fn;
use contracts::v2::voting::events::{ballot_created, vote};
use contracts::ContractAddresses;
use error::{Error, ErrorKind};
use ethabi::{Address, Bytes, FunctionOutputDecoder, Uint}; use ethabi::{Address, Bytes, FunctionOutputDecoder, Uint};
use stats::Stats;
use std::collections::BTreeSet; use std::collections::BTreeSet;
use std::default::Default; use std::default::Default;
use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::time::{Duration, SystemTime, UNIX_EPOCH};
use util::{self, HexList, IntoBallot, TopicFilterExt, Web3LogExt};
use web3; use web3;
use web3::futures::Future; use web3::futures::Future;
@ -104,7 +104,8 @@ impl Counter {
} else if let Ok(ballot) = } else if let Ok(ballot) =
ballot_created::parse_log(log.clone().into_raw()).or_else(|_| { ballot_created::parse_log(log.clone().into_raw()).or_else(|_| {
ballot_created_v1::parse_log(log.clone().into_raw()).map(IntoBallot::into) ballot_created_v1::parse_log(log.clone().into_raw()).map(IntoBallot::into)
}) { })
{
if !self.addrs.is_voting(&log.address) { if !self.addrs.is_voting(&log.address) {
continue; // Event from another contract instance. continue; // Event from another contract instance.
} }
@ -207,7 +208,8 @@ impl Counter {
.map(|vote| vote.voter) .map(|vote| vote.voter)
.or_else(|_| vote_v1::parse_log(vote_log.into_raw()).map(|vote| vote.voter)) .or_else(|_| vote_v1::parse_log(vote_log.into_raw()).map(|vote| vote.voter))
.map_err(Error::from) .map_err(Error::from)
}).collect() })
.collect()
} }
/// Returns `true` if the block with the given number is older than `start_time`. /// Returns `true` if the block with the given number is older than `start_time`.

View File

@ -1,18 +1,9 @@
extern crate clap;
extern crate colored;
#[macro_use] #[macro_use]
extern crate error_chain; extern crate error_chain;
extern crate ethabi;
#[macro_use(EthabiContract)]
extern crate ethabi_derive;
#[macro_use(use_contract)] #[macro_use(use_contract)]
extern crate ethabi_contract; extern crate ethabi_contract;
extern crate parse_duration; #[macro_use(EthabiContract)]
extern crate serde; extern crate ethabi_derive;
#[macro_use(Deserialize)]
extern crate serde_derive;
extern crate serde_json;
extern crate web3;
mod cli; mod cli;
mod contracts; mod contracts;

View File

@ -1,8 +1,8 @@
use crate::validator::Validator;
use colored::{Color, Colorize}; use colored::{Color, Colorize};
use ethabi::Address; use ethabi::Address;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
use validator::Validator;
/// The count of ballots and cast votes, as well as metadata for a particular voter. /// The count of ballots and cast votes, as well as metadata for a particular voter.
#[derive(Clone, Default)] #[derive(Clone, Default)]

View File

@ -1,6 +1,6 @@
use crate::contracts::v1::voting::logs::BallotCreated as BallotCreatedV1;
use crate::contracts::v2::voting::logs::BallotCreated;
use colored::{Color, Colorize}; use colored::{Color, Colorize};
use contracts::v1::voting::logs::BallotCreated as BallotCreatedV1;
use contracts::v2::voting::logs::BallotCreated;
use ethabi::{self, Address, Bytes, FunctionOutputDecoder}; use ethabi::{self, Address, Bytes, FunctionOutputDecoder};
use std::{fmt, u8}; use std::{fmt, u8};
use web3; use web3;
@ -89,7 +89,8 @@ impl TopicFilterExt for ethabi::TopicFilter {
self.topic1.to_opt_vec(), self.topic1.to_opt_vec(),
self.topic2.to_opt_vec(), self.topic2.to_opt_vec(),
self.topic3.to_opt_vec(), self.topic3.to_opt_vec(),
).from_block(web3::types::BlockNumber::Earliest) )
.from_block(web3::types::BlockNumber::Earliest)
.to_block(web3::types::BlockNumber::Latest) .to_block(web3::types::BlockNumber::Latest)
} }