From 4991c0d80d8ae246eed2d58e6319da8695e24eaf Mon Sep 17 00:00:00 2001 From: Andrey Kuprianov Date: Mon, 20 Jul 2020 11:45:34 +0200 Subject: [PATCH] #393: shorten imports --- mbt-utils/bin/tendermint-testgen.rs | 6 ++---- mbt-utils/src/commit.rs | 26 +++++++++++------------- mbt-utils/src/header.rs | 15 ++++++-------- mbt-utils/src/validator.rs | 31 ++++++++++++----------------- mbt-utils/src/vote.rs | 3 +-- 5 files changed, 34 insertions(+), 47 deletions(-) diff --git a/mbt-utils/bin/tendermint-testgen.rs b/mbt-utils/bin/tendermint-testgen.rs index b74a209d1..84cc71deb 100644 --- a/mbt-utils/bin/tendermint-testgen.rs +++ b/mbt-utils/bin/tendermint-testgen.rs @@ -1,10 +1,8 @@ use gumdrop::Options; - +use simple_error::SimpleError; use tendermint_testgen::{ - Generator, Validator, Header, Vote, Commit + Generator, Validator, Header, Vote, Commit, helpers::* }; -use simple_error::SimpleError; -use tendermint_testgen::helpers::read_stdin; const USAGE: &str = r#" This is a small utility for producing tendermint datastructures diff --git a/mbt-utils/src/commit.rs b/mbt-utils/src/commit.rs index a6723150a..39d94c2b3 100644 --- a/mbt-utils/src/commit.rs +++ b/mbt-utils/src/commit.rs @@ -1,18 +1,16 @@ use gumdrop::Options; use serde::Deserialize; -use signatory::ed25519; -use signatory::ed25519::SIGNATURE_SIZE; -use signatory::signature::Signature as _; -use signatory::signature::Signer; -use signatory_dalek::Ed25519Signer; use simple_error::*; +use signatory::{ + ed25519, + signature::{ Signature as _, Signer } +}; +use signatory_dalek::Ed25519Signer; +use tendermint::{ + amino_types, block, lite, vote, + signature::Signature }; -use tendermint::signature::Signature; -use tendermint::vote::{Type, Vote}; -use tendermint::{amino_types, block, lite, vote}; - -use crate::helpers::*; -use crate::{Generator, Validator, Header}; +use crate::{Generator, Validator, Header, helpers::*}; #[derive(Debug, Options, Deserialize)] pub struct Commit { @@ -63,8 +61,8 @@ impl Generator for Commit { let val_sign = |(i, v): (usize, &Validator)| -> Result { let validator = v.generate()?; let signer: Ed25519Signer = v.get_signer()?; - let vote = Vote { - vote_type: Type::Precommit, + let vote = vote::Vote { + vote_type: vote::Type::Precommit, height: block_header.height, round: choose_or(self.round, 1), block_id: Some(block_id.clone()), @@ -72,7 +70,7 @@ impl Generator for Commit { validator_address: validator.address, validator_index: i as u64, signature: Signature::Ed25519( - try_with!(ed25519::Signature::from_bytes(&[0_u8; SIGNATURE_SIZE]), "failed to construct empty ed25519 signature"), + try_with!(ed25519::Signature::from_bytes(&[0_u8; ed25519::SIGNATURE_SIZE]), "failed to construct empty ed25519 signature"), ), }; let signed_vote = vote::SignedVote::new( diff --git a/mbt-utils/src/header.rs b/mbt-utils/src/header.rs index a5156f2ce..c39a8dadb 100644 --- a/mbt-utils/src/header.rs +++ b/mbt-utils/src/header.rs @@ -1,15 +1,12 @@ use std::str::FromStr; - use gumdrop::Options; use serde::Deserialize; use simple_error::*; - -use tendermint::block::header::Version; -use tendermint::lite::ValidatorSet; -use tendermint::{block, chain, validator, Time}; - -use crate::helpers::*; -use crate::{Generator, Validator, validator::generate_validators}; +use tendermint::{ + block, chain, validator, Time, + lite::ValidatorSet }; +use crate::{ + Generator, Validator, validator::generate_validators, helpers::* }; #[derive(Debug, Options, Deserialize, Clone)] pub struct Header { @@ -86,7 +83,7 @@ impl Generator for Header { Err(_) => bail!("failed to construct header chain_id") }; let header = block::Header { - version: Version { block: 0, app: 0 }, + version: block::header::Version { block: 0, app: 0 }, chain_id: chain_id, height: block::Height(choose_or(self.height, 1)), time: choose_or(self.time, Time::now()), diff --git a/mbt-utils/src/validator.rs b/mbt-utils/src/validator.rs index 77c7e6163..5d1f97741 100644 --- a/mbt-utils/src/validator.rs +++ b/mbt-utils/src/validator.rs @@ -1,17 +1,12 @@ use gumdrop::Options; use serde::Deserialize; -use signatory::ed25519; -use signatory::public_key::PublicKeyed; -use signatory_dalek::Ed25519Signer; use simple_error::*; - -use tendermint::account; -use tendermint::public_key::PublicKey; -use tendermint::validator::{Info, ProposerPriority}; -use tendermint::vote::Power; - -use crate::helpers::*; -use crate::Generator; +use signatory::{ ed25519, public_key::PublicKeyed}; +use signatory_dalek::Ed25519Signer; +use tendermint::{ + account, public_key::PublicKey, validator, vote +}; +use crate::{Generator, helpers::*}; #[derive(Debug, Options, Deserialize, Clone)] pub struct Validator { @@ -71,7 +66,7 @@ impl std::str::FromStr for Validator { } } -impl Generator for Validator { +impl Generator for Validator { fn merge_with_default(&self, default: &Self) -> Self { Validator { id: choose_from(&self.id, &default.id), @@ -80,22 +75,22 @@ impl Generator for Validator { } } - fn generate(&self) -> Result { + fn generate(&self) -> Result { let signer = self.get_signer()?; let pk = try_with!(signer.public_key(), "failed to get a public key"); - let info = Info { + let info = validator::Info { address: account::Id::from(pk), pub_key: PublicKey::from(pk), - voting_power: Power::new(choose_or(self.voting_power, 0)), + voting_power: vote::Power::new(choose_or(self.voting_power, 0)), proposer_priority: match self.proposer_priority { None => None, - Some(p) => Some(ProposerPriority::new(p)), + Some(p) => Some(validator::ProposerPriority::new(p)), }, }; Ok(info) } } -pub fn generate_validators(vals: &[Validator]) -> Result, SimpleError> { - Ok(vals.iter().map(|v| v.generate()).collect::, SimpleError>>()?) +pub fn generate_validators(vals: &[Validator]) -> Result, SimpleError> { + Ok(vals.iter().map(|v| v.generate()).collect::, SimpleError>>()?) } diff --git a/mbt-utils/src/vote.rs b/mbt-utils/src/vote.rs index 2b977b884..7074164cd 100644 --- a/mbt-utils/src/vote.rs +++ b/mbt-utils/src/vote.rs @@ -1,9 +1,8 @@ use gumdrop::Options; use serde::Deserialize; use simple_error::*; -use crate::helpers::*; use tendermint::{Time}; -use crate::{Validator, Header}; +use crate::{Validator, Header, helpers::*}; #[derive(Debug, Options, Deserialize, Clone)] pub struct Vote {