Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[WIP] Styling with rustfmt #286

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# SEE https://github.com/rust-lang-nursery/rustfmt/blob/master/Configurations.md
# activate unstable features, so we can configure a few of them
unstable_features = true


# everything without a comment is at the default value, but we could
# also always pin the rustfmt version with the following line
# (at the time of writing):
#
# required_version = "0.8.2"
#

indent_style = "Block"
use_small_heuristics = "Default"
binop_separator = "Front"
combine_control_expr = true
comment_width = 100
condense_wildcard_suffixes = false
control_brace_style = "AlwaysSameLine"
disable_all_formatting = false
error_on_line_overflow = false
error_on_unformatted = false
fn_args_density = "Tall"
brace_style = "SameLineWhere"
empty_item_single_line = true
fn_single_line = false
where_single_line = false
force_explicit_abi = true
format_strings = false
# use tabs not spaces
hard_tabs = true
imports_indent = "Block"
imports_layout = "Mixed"
# do keep imports as they were written
merge_imports = false
# put a trailing comma in match block
match_block_trailing_comma = true
max_width = 100
merge_derives = true
force_multiline_blocks = false
newline_style = "Unix"
normalize_comments = false
remove_nested_parens = true
reorder_imports = true
# our module order is intentional
reorder_modules = false
reorder_impl_items = false
report_todo = "Never"
report_fixme = "Never"
skip_children = false
space_after_colon = true
space_before_colon = false
struct_field_align_threshold = 0
spaces_around_ranges = false
struct_lit_single_line = true
tab_spaces = 4
trailing_comma = "Vertical"
# do not leave unneeded semicolons around
trailing_semicolon = false
type_punctuation_density = "Wide"
# we use field shorthands
use_field_init_shorthand = true
# we prefer `?` over `try!`
use_try_shorthand = true
# we prefer to have a block over long lines
# even in comments :D
wrap_comments = true
# do not create unnaccesary arm blocks
match_arm_blocks = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
hide_parse_errors = false
color = "Auto"
# license_template_path = ""
ignore = []
2 changes: 1 addition & 1 deletion demo/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ error_chain! {
}
links {
Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"];
}
}
}
94 changes: 55 additions & 39 deletions demo/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
#![warn(missing_docs)]

extern crate ctrlc;
extern crate demo_executor;
extern crate demo_primitives;
extern crate demo_runtime;
extern crate ed25519;
extern crate env_logger;
extern crate futures;
extern crate tokio_core;
extern crate triehash;
extern crate substrate_client as client;
extern crate substrate_codec as codec;
extern crate substrate_extrinsic_pool as extrinsic_pool;
extern crate substrate_primitives as primitives;
extern crate substrate_rpc;
extern crate substrate_rpc_servers as rpc;
extern crate substrate_runtime_io as runtime_io;
extern crate substrate_state_machine as state_machine;
extern crate substrate_extrinsic_pool as extrinsic_pool;
extern crate demo_executor;
extern crate demo_primitives;
extern crate demo_runtime;
extern crate tokio_core;
extern crate triehash;

#[macro_use]
extern crate hex_literal;
Expand All @@ -47,20 +47,23 @@ extern crate log;

pub mod error;

use std::sync::Arc;
use demo_primitives::Hash;
use demo_runtime::{Block, BlockId, UncheckedExtrinsic, GenesisConfig,
ConsensusConfig, CouncilConfig, DemocracyConfig, SessionConfig, StakingConfig,
TimestampConfig};
use demo_runtime::{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only possible to configure rustfmt (at the moment) to either have importans in the first line and then match up the second line to it (imports_indent = "Visual") or make one-tabbed blocks like this (imports_indent = "Block")

Block, BlockId, ConsensusConfig, CouncilConfig, DemocracyConfig, GenesisConfig, SessionConfig,
StakingConfig, TimestampConfig, UncheckedExtrinsic,
};
use futures::{Future, Sink, Stream};
use std::sync::Arc;

struct DummyPool;
impl extrinsic_pool::api::ExtrinsicPool<UncheckedExtrinsic, BlockId, Hash> for DummyPool {
type Error = extrinsic_pool::txpool::Error;

fn submit(&self, _block: BlockId, _: Vec<UncheckedExtrinsic>)
-> Result<Vec<Hash>, Self::Error>
{
fn submit(
&self,
_block: BlockId,
_: Vec<UncheckedExtrinsic>,
) -> Result<Vec<Hash>, Self::Error> {
Err("unimplemented".into())
}
}
Expand All @@ -86,12 +89,15 @@ impl substrate_rpc::system::SystemApi for DummySystem {
/// 9556-9591 Unassigned
/// 9803-9874 Unassigned
/// 9926-9949 Unassigned
pub fn run<I, T>(args: I) -> error::Result<()> where
pub fn run<I, T>(args: I) -> error::Result<()>
where
I: IntoIterator<Item = T>,
T: Into<std::ffi::OsString> + Clone,
{
let yaml = load_yaml!("./cli.yml");
let matches = clap::App::from_yaml(yaml).version(crate_version!()).get_matches_from_safe(args)?;
let matches = clap::App::from_yaml(yaml)
.version(crate_version!())
.get_matches_from_safe(args)?;

// TODO [ToDr] Split parameters parsing from actual execution.
let log_pattern = matches.value_of("log").unwrap_or("");
Expand All @@ -103,13 +109,13 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
let god_key = hex!["3d866ec8a9190c8343c2fc593d21d8a6d0c5c4763aaab2349de3a6111d64d124"];
let genesis_config = GenesisConfig {
consensus: Some(ConsensusConfig {
code: vec![], // TODO
code: vec![], // TODO
authorities: vec![god_key.clone().into()],
}),
system: None,
session: Some(SessionConfig {
validators: vec![god_key.clone().into()],
session_length: 720, // that's 1 hour per session.
session_length: 720, // that's 1 hour per session.
broken_percent_late: 30,
}),
staking: Some(StakingConfig {
Expand All @@ -122,35 +128,41 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
contract_fee: 0,
reclaim_rebate: 0,
existential_deposit: 500,
balances: vec![(god_key.clone().into(), 1u64 << 63)].into_iter().collect(),
balances: vec![(god_key.clone().into(), 1u64 << 63)]
.into_iter()
.collect(),
validator_count: 12,
sessions_per_era: 24, // 24 hours per era.
bonding_duration: 90, // 90 days per bond.
sessions_per_era: 24, // 24 hours per era.
bonding_duration: 90, // 90 days per bond.
early_era_slash: 10000,
session_reward: 100,
}),
democracy: Some(DemocracyConfig {
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
}),
council: Some(CouncilConfig {
active_council: vec![],
candidacy_bond: 1000, // 1000 to become a council candidate
voter_bond: 100, // 100 down to vote for a candidate
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
carry_count: 24, // carry over the 24 runners-up to the next council election
presentation_duration: 120 * 24, // one day for presenting winners.
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
term_duration: 180 * 120 * 24, // 180 day term duration for the council.
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.

cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
candidacy_bond: 1000, // 1000 to become a council candidate
voter_bond: 100, // 100 down to vote for a candidate
present_slash_per_voter: 1, /* slash by 1 per voter for an invalid
* presentation. */
carry_count: 24, // carry over the 24 runners-up to the next council election
presentation_duration: 120 * 24, // one day for presenting winners.
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
term_duration: 180 * 120 * 24, // 180 day term duration for the council.
desired_seats: 0, /* start with no council: we'll raise this once the stake has been
* dispersed a bit. */
inactive_grace_period: 1, /* one addition vote should go by before an inactive voter
* can be reaped. */

cooloff_period: 90 * 120 * 24, /* 90 day cooling off period if council member vetoes
* a proposal. */
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
}),
timestamp: Some(TimestampConfig {
period: 5, // 5 second block time.
period: 5, // 5 second block time.
}),
};

Expand All @@ -168,17 +180,22 @@ pub fn run<I, T>(args: I) -> error::Result<()> where

(
rpc::start_http(&http_address, handler())?,
rpc::start_ws(&ws_address, handler())?
rpc::start_ws(&ws_address, handler())?,
)
};

if let Some(_) = matches.subcommand_matches("validator") {
info!("Starting validator.");
let (exit_send, exit) = futures::sync::mpsc::channel(1);
ctrlc::CtrlC::set_handler(move || {
exit_send.clone().send(()).wait().expect("Error sending exit notification");
exit_send
.clone()
.send(())
.wait()
.expect("Error sending exit notification");
});
core.run(exit.into_future()).expect("Error running informant event loop");
core.run(exit.into_future())
.expect("Error running informant event loop");
return Ok(())
}

Expand All @@ -201,6 +218,5 @@ fn init_logger(pattern: &str) {

builder.parse(pattern);


builder.init().expect("Logger initialized only once.");
}
Loading