Skip to content

Commit

Permalink
Fix fmt (#135)
Browse files Browse the repository at this point in the history
* fix fmt

* add fmt ci

* fmt ci name change
  • Loading branch information
satellitex authored Apr 21, 2020
1 parent 4ea4e9d commit 133439e
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 86 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: fmt
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: hecrj/setup-rust-action@v1
- name: Checkout the source code
uses: actions/checkout@master
- name: Check targets are installed correctly
run: rustup target list --installed
- name: Check fmt
run: cargo fmt -- --check
40 changes: 20 additions & 20 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@ fn testnet_genesis(
) -> GenesisConfig {
const ENDOWMENT: Balance = 1_000_000_000_000_000_000;

let endowed_accounts: Vec<(AccountId, Balance)> = endowed_accounts.unwrap_or_else(|| {
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
]
}).iter().cloned().map(|acc| (acc, ENDOWMENT)).collect();
let endowed_accounts: Vec<(AccountId, Balance)> = endowed_accounts
.unwrap_or_else(|| {
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
]
})
.iter()
.cloned()
.map(|acc| (acc, ENDOWMENT))
.collect();

make_genesis(
initial_authorities,
endowed_accounts,
sudo_key,
true,
)
make_genesis(initial_authorities, endowed_accounts, sudo_key, true)
}

/// Helper function to create GenesisConfig
Expand Down Expand Up @@ -176,7 +176,7 @@ pub fn dusty_config() -> ChainSpec {
ChainSpec::from_genesis(
"Dusty",
"dusty",
ChainType::Live,
ChainType::Live,
dusty_genesis,
vec![],
Some(sc_telemetry::TelemetryEndpoints::new(vec![(STAGING_TELEMETRY_URL.to_string(),0)]).unwrap()),
Expand Down Expand Up @@ -216,7 +216,7 @@ fn dusty_genesis() -> GenesisConfig {
),
];
// akru
// akru
let root_key = hex!["16eb796bee0c857db3d646ee7070252707aec0c7d82b2eda856632f6a2306a58"];
// token holders
Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn development_config() -> ChainSpec {
ChainSpec::from_genesis(
"Development",
"dev",
ChainType::Development,
ChainType::Development,
development_config_genesis,
vec![],
None,
Expand All @@ -273,7 +273,7 @@ pub fn local_testnet_config() -> ChainSpec {
ChainSpec::from_genesis(
"Local Testnet",
"local_testnet",
ChainType::Local,
ChainType::Local,
local_testnet_genesis,
vec![],
None,
Expand Down
14 changes: 8 additions & 6 deletions bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,26 @@ pub fn run() -> sc_cli::Result<()> {
runner.run_node(
service::new_light,
service::new_full,
plasm_runtime::VERSION
plasm_runtime::VERSION,
)
},
}
Some(Subcommand::Benchmark(cmd)) => {
if cfg!(feature = "runtime-benchmarks") {
let runner = cli.create_runner(cmd)?;

runner.sync_run(|config| cmd.run::<Block, service::Executor>(config))
} else {
println!("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`.");
println!(
"Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
);
Ok(())
}
},
}
Some(Subcommand::Base(subcommand)) => {
let runner = cli.create_runner(subcommand)?;

runner.run_subcommand(subcommand, |config| Ok(new_full_start!(config).0))
},
}
}
}
54 changes: 25 additions & 29 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use sc_client::{Client, LocalCallExecutor};
use sc_client_api::ExecutorProvider;
use sc_client_db::Backend;
use sc_consensus_babe;
use sc_executor::{native_executor_instance, NativeExecutor};
use sc_finality_grandpa::{
FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider,
};
use sc_network::NetworkService;
use sc_offchain::OffchainWorkers;
use sc_executor::{native_executor_instance, NativeExecutor};
use sc_service::{
AbstractService, Service, ServiceBuilder, NetworkStatus,
config::Configuration, error::{Error as ServiceError},
config::Configuration, error::Error as ServiceError, AbstractService, NetworkStatus, Service,
ServiceBuilder,
};
use sp_runtime::traits::Block as BlockT;

Expand Down Expand Up @@ -84,18 +84,23 @@ macro_rules! new_full_start {
Ok(import_queue)
})?
.with_rpc_extensions(|builder| -> std::result::Result<RpcExtension, _> {
let babe_link = import_setup.as_ref().map(|s| &s.2)
let babe_link = import_setup
.as_ref()
.map(|s| &s.2)
.expect("BabeLink is present for full services or set up failed; qed.");
let deps = plasm_rpc::FullDeps {
client: builder.client().clone(),
pool: builder.pool(),
select_chain: builder.select_chain().cloned()
select_chain: builder
.select_chain()
.cloned()
.expect("SelectChain is present for full services or set up failed; qed."),
babe: plasm_rpc::BabeDeps {
keystore: builder.keystore(),
babe_config: sc_consensus_babe::BabeLink::config(babe_link).clone(),
shared_epoch_changes: sc_consensus_babe::BabeLink::epoch_changes(babe_link).clone()
}
shared_epoch_changes: sc_consensus_babe::BabeLink::epoch_changes(babe_link)
.clone(),
},
};
Ok(plasm_rpc::create_full(deps))
})?;
Expand All @@ -110,12 +115,7 @@ macro_rules! new_full_start {
/// concrete types instead.
macro_rules! new_full {
($config:expr, $with_startup_data: expr) => {{
let (
role,
force_authoring,
name,
disable_grandpa,
) = (
let (role, force_authoring, name, disable_grandpa) = (
$config.role.clone(),
$config.force_authoring,
$config.network.node_name.clone(),
Expand All @@ -126,7 +126,7 @@ macro_rules! new_full {

let service = builder
.with_finality_proof_provider(|client, backend| {
// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider
// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
})?
Expand All @@ -138,7 +138,7 @@ macro_rules! new_full {

($with_startup_data)(&block_import, &babe_link);

if let sc_service::config::Role::Authority { sentry_nodes: _ } = &role {
if let sc_service::config::Role::Authority { sentry_nodes: _ } = &role {
let proposer = sc_basic_authorship::ProposerFactory::new(
service.client(),
service.transaction_pool(),
Expand Down Expand Up @@ -227,14 +227,12 @@ macro_rules! new_full {
}

type ConcreteBlock = plasm_primitives::Block;
type ConcreteClient =
Client<
Backend<ConcreteBlock>,
LocalCallExecutor<Backend<ConcreteBlock>,
NativeExecutor<Executor>>,
ConcreteBlock,
plasm_runtime::RuntimeApi
>;
type ConcreteClient = Client<
Backend<ConcreteBlock>,
LocalCallExecutor<Backend<ConcreteBlock>, NativeExecutor<Executor>>,
ConcreteBlock,
plasm_runtime::RuntimeApi,
>;
type ConcreteBackend = Backend<ConcreteBlock>;
type ConcreteTransactionPool = sc_transaction_pool::BasicPool<
sc_transaction_pool::FullChainApi<ConcreteClient, ConcreteBlock>,
Expand Down Expand Up @@ -269,9 +267,7 @@ pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceE
let inherent_data_providers = sp_inherents::InherentDataProviders::new();

let service = ServiceBuilder::new_light::<Block, RuntimeApi, Executor>(config)?
.with_select_chain(|_config, backend| {
Ok(LongestChain::new(backend.clone()))
})?
.with_select_chain(|_config, backend| Ok(LongestChain::new(backend.clone())))?
.with_transaction_pool(|config, client, fetcher| {
let fetcher = fetcher
.ok_or_else(|| "Trying to start light transaction pool without active fetcher")?;
Expand Down Expand Up @@ -323,9 +319,9 @@ pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceE
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
})?
.with_rpc_extensions(|builder,| -> std::result::Result<RpcExtension, _>
{
let fetcher = builder.fetcher()
.with_rpc_extensions(|builder| -> std::result::Result<RpcExtension, _> {
let fetcher = builder
.fetcher()
.ok_or_else(|| "Trying to start node RPC without active fetcher")?;
let remote_blockchain = builder
.remote_backend()
Expand Down
4 changes: 2 additions & 2 deletions bin/node/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod currency {

#[cfg(feature = "std")]
fn to_account(full_public: &[u8]) -> plasm_primitives::AccountId {
use sp_runtime::{MultiSigner, traits::IdentifyAccount};
use sp_runtime::{traits::IdentifyAccount, MultiSigner};
let public = sp_core::ecdsa::Public::from_full(full_public).unwrap();
MultiSigner::from(public).into_account()
}
Expand Down Expand Up @@ -286,7 +286,7 @@ pub mod currency {
, (to_account(&hex!["239e8f64e31160d21e7da7efcaa4920c4066896399ae0770f36a7fe9871cd5bfe549f59489c69067954190bd3f5b292f013fe86570e11086b759d423945427c7"][..]), 60135395590491354663083)
, (to_account(&hex!["5ae3c95414793303b9a46eccd424b789cd4d873e5ebee2d2a8bcfb2ca3fe6b9323025774b7cf15a4af777e953a16fc117187ef70580be9dfaf9d0235e8eb51f1"][..]), 3969200735585470891107)
, (to_account(&hex!["9b9be3dcefb7184344b31386d6164717f49ed3971280532edcde1fd9ad5386fffb560042f5df49863481a5f4ba9ef2fb3ca3fbb86b5ae3a130fd2ad4e90ab715"][..]), 176408921581576484049)
];
];
}
}

Expand Down
7 changes: 4 additions & 3 deletions bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Some configurable implementations as associated type for the plasm runtime.
use crate::{MaximumBlockWeight, System};
use frame_support::{traits::Get, weights::Weight};
use plasm_primitives::Balance;
use sp_runtime::traits::{Convert, Saturating};
use sp_runtime::{Fixed64, Perbill};
use frame_support::{traits::Get, weights::Weight};

/// Convert from weight to balance via a simple coefficient multiplication
/// The associated type C encapsulates a constant in units of balance per weight
Expand Down Expand Up @@ -79,8 +79,8 @@ mod tests {
use super::*;
use crate::{constants::currency::*, TargetBlockFullness, TransactionPayment};
use crate::{AvailableBlockRatio, MaximumBlockWeight, Runtime};
use sp_runtime::assert_eq_error_rate;
use frame_support::weights::Weight;
use sp_runtime::assert_eq_error_rate;

fn max() -> Weight {
MaximumBlockWeight::get()
Expand Down Expand Up @@ -203,7 +203,8 @@ mod tests {
}
fm = next;
iterations += 1;
let fee = <Runtime as pallet_transaction_payment::Trait>::WeightToFee::convert(tx_weight);
let fee =
<Runtime as pallet_transaction_payment::Trait>::WeightToFee::convert(tx_weight);
let adjusted_fee = fm.saturated_multiply_accumulate(fee);
println!(
"iteration {}, new fm = {:?}. Fee at this point is: {} units / {} mPLM, \
Expand Down
12 changes: 7 additions & 5 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]

use frame_support::{construct_runtime, parameter_types, traits::Randomness, weights::Weight};
use pallet_contracts_rpc_runtime_api::ContractExecResult;
use pallet_grandpa::fg_primitives;
use pallet_grandpa::AuthorityList as GrandpaAuthorityList;
use sp_inherents::{CheckInherentsResult, InherentData};
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use plasm_primitives::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Moment, Signature,
};
use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata;
use sp_inherents::{CheckInherentsResult, InherentData};
use sp_runtime::traits::{
BlakeTwo256, Block as BlockT, ConvertInto, Extrinsic, OpaqueKeys, SaturatedConversion,
StaticLookup, Verify,
};
use sp_runtime::transaction_validity::{TransactionSource, TransactionValidity};
use sp_runtime::{create_runtime_str, generic, impl_opaque_keys, ApplyExtrinsicResult, Perbill};
use sp_std::prelude::*;
use frame_support::{construct_runtime, parameter_types, traits::Randomness, weights::Weight};
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
#[cfg(any(feature = "std", test))]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

pub use pallet_balances::Call as BalancesCall;
pub use pallet_contracts::Gas;
pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
pub use pallet_timestamp::Call as TimestampCall;

/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;
Expand Down Expand Up @@ -304,7 +304,9 @@ impl frame_system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for
type Public = <Signature as Verify>::Signer;
type Signature = Signature;

fn create_transaction<TSigner: frame_system::offchain::Signer<Self::Public, Self::Signature>>(
fn create_transaction<
TSigner: frame_system::offchain::Signer<Self::Public, Self::Signature>,
>(
call: Call,
public: Self::Public,
account: AccountId,
Expand Down
2 changes: 1 addition & 1 deletion bin/subkey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bip39::{Language, Mnemonic, MnemonicType};
use clap::{App, ArgMatches, SubCommand};
use codec::{Decode, Encode};
use hex_literal::hex;
use plasm_primitives::{Balance, Hash, Index, AccountId, Signature};
use plasm_primitives::{AccountId, Balance, Hash, Index, Signature};
use plasm_runtime::{BalancesCall, Call, Runtime, SignedPayload, UncheckedExtrinsic, VERSION};
use sp_core::{
crypto::{set_default_ss58_version, Ss58AddressFormat, Ss58Codec},
Expand Down
4 changes: 3 additions & 1 deletion frame/dapps-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#![cfg(test)]

use super::*;
use frame_support::{assert_ok, impl_outer_dispatch, impl_outer_origin, parameter_types, traits::OnFinalize};
use frame_support::{
assert_ok, impl_outer_dispatch, impl_outer_origin, parameter_types, traits::OnFinalize,
};
use pallet_plasm_rewards::{inflation::SimpleComputeTotalPayout, traits::MaybeValidators};
use sp_core::{crypto::key_types, H256};
use sp_runtime::{
Expand Down
3 changes: 1 addition & 2 deletions frame/operator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::{
decl_event, decl_module, decl_storage,
Parameter, weights::SimpleDispatchInfo,
decl_event, decl_module, decl_storage, weights::SimpleDispatchInfo, Parameter,
};
use frame_system::{self as system, ensure_signed, RawOrigin};
use pallet_contracts::{BalanceOf, CodeHash, ContractAddressFor, Gas};
Expand Down
Loading

0 comments on commit 133439e

Please sign in to comment.