Removed trailing whitespace.
This commit is contained in:
parent
7d2f2ef8b9
commit
3e10c68293
|
@ -64,7 +64,7 @@ impl<'a> BlockchainIter<'a> {
|
||||||
impl<'a> Iterator for BlockchainIter<'a> {
|
impl<'a> Iterator for BlockchainIter<'a> {
|
||||||
type Item = Result<(BlockNumber, BlockNumber)>;
|
type Item = Result<(BlockNumber, BlockNumber)>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.on_first_iteration {
|
if self.on_first_iteration {
|
||||||
self.on_first_iteration = false;
|
self.on_first_iteration = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl Cli {
|
||||||
pub fn sokol(&self) -> bool {
|
pub fn sokol(&self) -> bool {
|
||||||
self.0.is_present("sokol")
|
self.0.is_present("sokol")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn keys(&self) -> bool {
|
pub fn keys(&self) -> bool {
|
||||||
self.0.is_present("keys")
|
self.0.is_present("keys")
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ impl Cli {
|
||||||
pub fn threshold(&self) -> bool {
|
pub fn threshold(&self) -> bool {
|
||||||
self.0.is_present("threshold")
|
self.0.is_present("threshold")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn proxy(&self) -> bool {
|
pub fn proxy(&self) -> bool {
|
||||||
self.0.is_present("proxy")
|
self.0.is_present("proxy")
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ impl Cli {
|
||||||
pub fn v2(&self) -> bool {
|
pub fn v2(&self) -> bool {
|
||||||
self.0.is_present("v2")
|
self.0.is_present("v2")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn earliest(&self) -> bool {
|
pub fn earliest(&self) -> bool {
|
||||||
self.0.is_present("earliest")
|
self.0.is_present("earliest")
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,8 +134,8 @@ impl RpcClient {
|
||||||
from: None,
|
from: None,
|
||||||
gas: None,
|
gas: None,
|
||||||
gas_price: None,
|
gas_price: None,
|
||||||
value: None,
|
value: None,
|
||||||
};
|
};
|
||||||
let rpc_method_params = vec![
|
let rpc_method_params = vec![
|
||||||
json::to_value(function_call_request).unwrap(),
|
json::to_value(function_call_request).unwrap(),
|
||||||
json::to_value(BlockNumber::Latest).unwrap(),
|
json::to_value(BlockNumber::Latest).unwrap(),
|
||||||
|
@ -183,8 +183,8 @@ impl RpcClient {
|
||||||
from: None,
|
from: None,
|
||||||
gas: None,
|
gas: None,
|
||||||
gas_price: None,
|
gas_price: None,
|
||||||
value: None,
|
value: None,
|
||||||
};
|
};
|
||||||
let rpc_method_params = vec![
|
let rpc_method_params = vec![
|
||||||
json::to_value(function_call_request).unwrap(),
|
json::to_value(function_call_request).unwrap(),
|
||||||
json::to_value(BlockNumber::Latest).unwrap(),
|
json::to_value(BlockNumber::Latest).unwrap(),
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl ContractType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn abi_file_name(&self) -> &str {
|
fn abi_file_name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
ContractType::Keys => "VotingToChangeKeys.abi.json",
|
ContractType::Keys => "VotingToChangeKeys.abi.json",
|
||||||
ContractType::Threshold => "VotingToChangeMinThreshold.abi.json",
|
ContractType::Threshold => "VotingToChangeMinThreshold.abi.json",
|
||||||
|
@ -112,7 +112,7 @@ impl PoaContract {
|
||||||
if contract_type == ContractType::Emission && version == ContractVersion::V1 {
|
if contract_type == ContractType::Emission && version == ContractVersion::V1 {
|
||||||
return Err(Error::EmissionFundsV1ContractDoesNotExist);
|
return Err(Error::EmissionFundsV1ContractDoesNotExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
let addr_env_var = format!(
|
let addr_env_var = format!(
|
||||||
"{}_CONTRACT_ADDRESS_{}_{:?}",
|
"{}_CONTRACT_ADDRESS_{}_{:?}",
|
||||||
contract_type.uppercase(),
|
contract_type.uppercase(),
|
||||||
|
@ -134,7 +134,7 @@ impl PoaContract {
|
||||||
version.lowercase(),
|
version.lowercase(),
|
||||||
contract_type.abi_file_name(),
|
contract_type.abi_file_name(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let abi_file = File::open(&abi_path)
|
let abi_file = File::open(&abi_path)
|
||||||
.map_err(|_| Error::MissingAbiFile(abi_path.clone()))?;
|
.map_err(|_| Error::MissingAbiFile(abi_path.clone()))?;
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ impl Config {
|
||||||
let endpoint_env_var = format!("{}_RPC_ENDPOINT", network.uppercase());
|
let endpoint_env_var = format!("{}_RPC_ENDPOINT", network.uppercase());
|
||||||
let endpoint = env::var(&endpoint_env_var)
|
let endpoint = env::var(&endpoint_env_var)
|
||||||
.map_err(|_| Error::MissingEnvVar(endpoint_env_var))?;
|
.map_err(|_| Error::MissingEnvVar(endpoint_env_var))?;
|
||||||
|
|
||||||
let version = if cli.v1() == cli.v2(){
|
let version = if cli.v1() == cli.v2(){
|
||||||
return Err(Error::MustSpecifyOneCliArgument("`--v1` or `--v2`".into()));
|
return Err(Error::MustSpecifyOneCliArgument("`--v1` or `--v2`".into()));
|
||||||
} else if cli.v1(){
|
} else if cli.v1(){
|
||||||
|
@ -203,7 +203,7 @@ impl Config {
|
||||||
} else {
|
} else {
|
||||||
ContractVersion::V2
|
ContractVersion::V2
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut contracts = vec![];
|
let mut contracts = vec![];
|
||||||
if cli.keys() {
|
if cli.keys() {
|
||||||
let keys = PoaContract::read(
|
let keys = PoaContract::read(
|
||||||
|
@ -243,7 +243,7 @@ impl Config {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let start_block = if cli.multiple_start_blocks_specified() {
|
let start_block = if cli.multiple_start_blocks_specified() {
|
||||||
return Err(Error::MustSpecifyOneCliArgument(
|
return Err(Error::MustSpecifyOneCliArgument(
|
||||||
"`--earliest` or `--latest` or `--start-block` or `--tail`".into()
|
"`--earliest` or `--latest` or `--start-block` or `--tail`".into()
|
||||||
));
|
));
|
||||||
|
@ -268,7 +268,7 @@ impl Config {
|
||||||
};
|
};
|
||||||
|
|
||||||
let email_notifications = cli.email();
|
let email_notifications = cli.email();
|
||||||
|
|
||||||
let email_recipients: Vec<String> = env::var("EMAIL_RECIPIENTS")
|
let email_recipients: Vec<String> = env::var("EMAIL_RECIPIENTS")
|
||||||
.map_err(|_| Error::MissingEnvVar("EMAIL_RECIPIENTS".into()))?
|
.map_err(|_| Error::MissingEnvVar("EMAIL_RECIPIENTS".into()))?
|
||||||
.split(',')
|
.split(',')
|
||||||
|
@ -363,7 +363,7 @@ mod tests {
|
||||||
use super::super::tests::setup;
|
use super::super::tests::setup;
|
||||||
use super::{ContractType, ContractVersion, PoaContract, Network};
|
use super::{ContractType, ContractVersion, PoaContract, Network};
|
||||||
|
|
||||||
const CONTRACT_TYPES: [ContractType; 4] = [
|
const CONTRACT_TYPES: [ContractType; 4] = [
|
||||||
ContractType::Keys,
|
ContractType::Keys,
|
||||||
ContractType::Threshold,
|
ContractType::Threshold,
|
||||||
ContractType::Proxy,
|
ContractType::Proxy,
|
||||||
|
|
|
@ -20,7 +20,7 @@ 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.
|
||||||
const INITIAL_CHECK_FILE_SIZE_AT: usize = MAX_LOG_FILE_SIZE_BYTES / 100;
|
const INITIAL_CHECK_FILE_SIZE_AT: usize = MAX_LOG_FILE_SIZE_BYTES / 100;
|
||||||
|
|
||||||
fn create_logs_dir() {
|
fn create_logs_dir() {
|
||||||
|
@ -84,7 +84,7 @@ impl LogFile {
|
||||||
fn now() -> Self {
|
fn now() -> Self {
|
||||||
LogFile(Utc::now())
|
LogFile(Utc::now())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_file_name(file_name: &str) -> Result<Self, ()> {
|
fn from_file_name(file_name: &str) -> Result<Self, ()> {
|
||||||
if let Ok(dt) = Utc.datetime_from_str(file_name, FILE_NAME_DATE_FORMAT) {
|
if let Ok(dt) = Utc.datetime_from_str(file_name, FILE_NAME_DATE_FORMAT) {
|
||||||
Ok(LogFile(dt))
|
Ok(LogFile(dt))
|
||||||
|
@ -140,7 +140,7 @@ impl Logger {
|
||||||
check_file_size_at: INITIAL_CHECK_FILE_SIZE_AT,
|
check_file_size_at: INITIAL_CHECK_FILE_SIZE_AT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn logging_to_file(&self) -> bool {
|
fn logging_to_file(&self) -> bool {
|
||||||
!self.log_files.is_empty()
|
!self.log_files.is_empty()
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ impl Logger {
|
||||||
let file_size = get_file_size_in_bytes(&path);
|
let file_size = get_file_size_in_bytes(&path);
|
||||||
if file_size >= MAX_LOG_FILE_SIZE_BYTES {
|
if file_size >= MAX_LOG_FILE_SIZE_BYTES {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let avg_bytes_per_log = file_size / self.log_count;
|
let avg_bytes_per_log = file_size / self.log_count;
|
||||||
let remaining_bytes = MAX_LOG_FILE_SIZE_BYTES - file_size;
|
let remaining_bytes = MAX_LOG_FILE_SIZE_BYTES - file_size;
|
||||||
let remaining_logs = remaining_bytes / avg_bytes_per_log;
|
let remaining_logs = remaining_bytes / avg_bytes_per_log;
|
||||||
|
@ -180,7 +180,7 @@ impl Logger {
|
||||||
info!(&self.logger, "starting poagov...");
|
info!(&self.logger, "starting poagov...");
|
||||||
self.increment_log_count();
|
self.increment_log_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_ctrlc(&mut self) {
|
pub fn log_ctrlc(&mut self) {
|
||||||
warn!(&self.logger, "recieved ctrl-c signal, gracefully shutting down...");
|
warn!(&self.logger, "recieved ctrl-c signal, gracefully shutting down...");
|
||||||
self.increment_log_count();
|
self.increment_log_count();
|
||||||
|
@ -195,7 +195,7 @@ impl Logger {
|
||||||
info!(&self.logger, "governance notification\n{}", notif.email_text());
|
info!(&self.logger, "governance notification\n{}", notif.email_text());
|
||||||
self.increment_log_count();
|
self.increment_log_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_notification(&mut self, notif: &Notification) {
|
pub fn log_notification(&mut self, notif: &Notification) {
|
||||||
let ballot_created_log = notif.log();
|
let ballot_created_log = notif.log();
|
||||||
info!(
|
info!(
|
||||||
|
@ -207,12 +207,12 @@ impl Logger {
|
||||||
);
|
);
|
||||||
self.increment_log_count();
|
self.increment_log_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_failed_to_build_email(&mut self, e: Error) {
|
pub fn log_failed_to_build_email(&mut self, e: Error) {
|
||||||
warn!(&self.logger, "failed to build email"; "error" => format!("{:?}", e));
|
warn!(&self.logger, "failed to build email"; "error" => format!("{:?}", e));
|
||||||
self.increment_log_count();
|
self.increment_log_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_failed_to_send_email(&mut self, recipient: &str, e: Error) {
|
pub fn log_failed_to_send_email(&mut self, recipient: &str, e: Error) {
|
||||||
warn!(
|
warn!(
|
||||||
&self.logger,
|
&self.logger,
|
||||||
|
@ -227,7 +227,7 @@ impl Logger {
|
||||||
info!(&self.logger, "email sent"; "to" => recipient);
|
info!(&self.logger, "email sent"; "to" => recipient);
|
||||||
self.increment_log_count();
|
self.increment_log_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_reached_notification_limit(&mut self, notification_limit: usize) {
|
pub fn log_reached_notification_limit(&mut self, notification_limit: usize) {
|
||||||
warn!(
|
warn!(
|
||||||
&self.logger,
|
&self.logger,
|
||||||
|
|
|
@ -48,7 +48,7 @@ fn load_env_file() {
|
||||||
|
|
||||||
fn set_ctrlc_handler(logger: Arc<Mutex<Logger>>) -> Result<Arc<AtomicBool>> {
|
fn set_ctrlc_handler(logger: Arc<Mutex<Logger>>) -> Result<Arc<AtomicBool>> {
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
let result = Ok(running.clone());
|
let result = Ok(running.clone());
|
||||||
ctrlc::set_handler(move || {
|
ctrlc::set_handler(move || {
|
||||||
logger.lock().unwrap().log_ctrlc();
|
logger.lock().unwrap().log_ctrlc();
|
||||||
running.store(false, Ordering::SeqCst);
|
running.store(false, Ordering::SeqCst);
|
||||||
|
@ -58,7 +58,7 @@ fn set_ctrlc_handler(logger: Arc<Mutex<Logger>>) -> Result<Arc<AtomicBool>> {
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
load_env_file();
|
load_env_file();
|
||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let config = Config::new(&cli)?;
|
let config = Config::new(&cli)?;
|
||||||
let logger = Arc::new(Mutex::new(Logger::new(&config)));
|
let logger = Arc::new(Mutex::new(Logger::new(&config)));
|
||||||
|
@ -79,7 +79,7 @@ fn main() -> Result<()> {
|
||||||
start_block,
|
start_block,
|
||||||
stop_block,
|
stop_block,
|
||||||
)?;
|
)?;
|
||||||
for log in ballot_created_logs.into_iter() {
|
for log in ballot_created_logs.into_iter() {
|
||||||
let notification = if contract.version == ContractVersion::V1 {
|
let notification = if contract.version == ContractVersion::V1 {
|
||||||
let voting_state = client.get_voting_state(contract, log.ballot_id)?;
|
let voting_state = client.get_voting_state(contract, log.ballot_id)?;
|
||||||
Notification::from_voting_state(&config, log, voting_state)
|
Notification::from_voting_state(&config, log, voting_state)
|
||||||
|
|
|
@ -62,14 +62,14 @@ impl From<ProxyVotingState> for VotingState {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VotingState {
|
impl VotingState {
|
||||||
pub fn contract_name(&self) -> String {
|
pub fn contract_name(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
VotingState::Keys(_) => "VotingToChangeKeys.sol".into(),
|
VotingState::Keys(_) => "VotingToChangeKeys.sol".into(),
|
||||||
VotingState::Threshold(_) => "VotingToChangeMinThreshold.sol".into(),
|
VotingState::Threshold(_) => "VotingToChangeMinThreshold.sol".into(),
|
||||||
VotingState::Proxy(_) => "VotingToChangeProxyAddress.sol".into(),
|
VotingState::Proxy(_) => "VotingToChangeProxyAddress.sol".into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn email_text(&self) -> String {
|
pub fn email_text(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
VotingState::Keys(state) => state.email_text(),
|
VotingState::Keys(state) => state.email_text(),
|
||||||
|
|
|
@ -37,7 +37,7 @@ impl From<EmissionBallotInfo> for BallotInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BallotInfo {
|
impl BallotInfo {
|
||||||
pub fn contract_name(&self) -> String {
|
pub fn contract_name(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
BallotInfo::Keys(_) => "VotingToChangeKeys.sol".into(),
|
BallotInfo::Keys(_) => "VotingToChangeKeys.sol".into(),
|
||||||
BallotInfo::Threshold(_) => "VotingToChangeMinThreshold.sol".into(),
|
BallotInfo::Threshold(_) => "VotingToChangeMinThreshold.sol".into(),
|
||||||
|
@ -46,7 +46,7 @@ impl BallotInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn email_text(&self) -> String {
|
pub fn email_text(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
BallotInfo::Keys(info) => info.email_text(),
|
BallotInfo::Keys(info) => info.email_text(),
|
||||||
BallotInfo::Threshold(info) => info.email_text(),
|
BallotInfo::Threshold(info) => info.email_text(),
|
||||||
|
|
Loading…
Reference in New Issue