Skip to content

Commit

Permalink
#393: shorten imports
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-kuprianov committed Jul 20, 2020
1 parent ede2e45 commit 4991c0d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 47 deletions.
6 changes: 2 additions & 4 deletions mbt-utils/bin/tendermint-testgen.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 12 additions & 14 deletions mbt-utils/src/commit.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -63,16 +61,16 @@ impl Generator<block::Commit> for Commit {
let val_sign = |(i, v): (usize, &Validator)| -> Result<block::CommitSig, SimpleError> {
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()),
timestamp: block_header.time,
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(
Expand Down
15 changes: 6 additions & 9 deletions mbt-utils/src/header.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -86,7 +83,7 @@ impl Generator<block::Header> 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()),
Expand Down
31 changes: 13 additions & 18 deletions mbt-utils/src/validator.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -71,7 +66,7 @@ impl std::str::FromStr for Validator {
}
}

impl Generator<Info> for Validator {
impl Generator<validator::Info> for Validator {
fn merge_with_default(&self, default: &Self) -> Self {
Validator {
id: choose_from(&self.id, &default.id),
Expand All @@ -80,22 +75,22 @@ impl Generator<Info> for Validator {
}
}

fn generate(&self) -> Result<Info, SimpleError> {
fn generate(&self) -> Result<validator::Info, SimpleError> {
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<Vec<Info>, SimpleError> {
Ok(vals.iter().map(|v| v.generate()).collect::<Result<Vec<Info>, SimpleError>>()?)
pub fn generate_validators(vals: &[Validator]) -> Result<Vec<validator::Info>, SimpleError> {
Ok(vals.iter().map(|v| v.generate()).collect::<Result<Vec<validator::Info>, SimpleError>>()?)
}
3 changes: 1 addition & 2 deletions mbt-utils/src/vote.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 4991c0d

Please sign in to comment.