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

Commit

Permalink
Integrate fee RPC (#508) (#511)
Browse files Browse the repository at this point in the history
* Integrate fee RPC (#508)

* Update cargo files

* First round of build fixes

* update lock file

* Fix builds again

* Revert cargo file

* remove elections genesis

* Fix chain spec

* Remove imports

* Update runtime/src/lib.rs

Co-Authored-By: Gavin Wood <[email protected]>

* Update lock
  • Loading branch information
gavofyork authored Oct 28, 2019
1 parent a15c029 commit 775a6d5
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 109 deletions.
201 changes: 118 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "pol
substrate-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
transaction_pool = { package = "substrate-transaction-pool", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
srml-system-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
srml-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
polkadot-runtime = { path = "../runtime" }

8 changes: 7 additions & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

use std::sync::Arc;

use polkadot_primitives::{Block, AccountId, Nonce};
use polkadot_primitives::{Block, AccountId, Nonce, Balance};
use sr_primitives::traits::ProvideRuntimeApi;
use transaction_pool::txpool::{ChainApi, Pool};
use polkadot_runtime::UncheckedExtrinsic;

/// A type representing all RPC extensions.
pub type RpcExtension = jsonrpc_core::IoHandler<substrate_rpc::Metadata>;
Expand All @@ -33,13 +34,18 @@ pub fn create<C, P>(client: Arc<C>, pool: Arc<Pool<P>>) -> RpcExtension where
C: client::blockchain::HeaderBackend<Block>,
C: Send + Sync + 'static,
C::Api: srml_system_rpc::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: srml_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance, UncheckedExtrinsic>,
P: ChainApi + Sync + Send + 'static,
{
use srml_system_rpc::{System, SystemApi};
use srml_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};

let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(
SystemApi::to_delegate(System::new(client.clone(), pool))
);
io.extend_with(
TransactionPaymentApi::to_delegate(TransactionPayment::new(client))
);
io
}
2 changes: 2 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ authorship = { package = "srml-authorship", git = "https://github.com/paritytech
babe = { package = "srml-babe", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
balances = { package = "srml-balances", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
transaction-payment = { package = "srml-transaction-payment", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
collective = { package = "srml-collective", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
democracy = { package = "srml-democracy", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
elections-phragmen = { package = "srml-elections-phragmen", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
Expand Down Expand Up @@ -92,6 +93,7 @@ std = [
"authorship/std",
"balances/std",
"transaction-payment/std",
"srml-transaction-payment-rpc-runtime-api/std",
"collective/std",
"elections-phragmen/std",
"democracy/std",
Expand Down
19 changes: 18 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use srml_support::{
};
use im_online::sr25519::AuthorityId as ImOnlineId;
use system::offchain::TransactionSubmitter;
use srml_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;

#[cfg(feature = "std")]
pub use staking::StakerStatus;
Expand Down Expand Up @@ -379,6 +380,9 @@ impl collective::Trait<CouncilCollective> for Runtime {
parameter_types! {
pub const CandidacyBond: Balance = 100 * DOLLARS;
pub const VotingBond: Balance = 5 * DOLLARS;
pub const TermDuration: BlockNumber = 10 * MINUTES;
pub const DesiredMembers: u32 = 13;
pub const DesiredRunnersUp: u32 = 7;
}

impl elections_phragmen::Trait for Runtime {
Expand All @@ -388,6 +392,9 @@ impl elections_phragmen::Trait for Runtime {
type CurrencyToVote = CurrencyToVoteHandler;
type CandidacyBond = CandidacyBond;
type VotingBond = VotingBond;
type TermDuration = TermDuration;
type DesiredMembers = DesiredMembers;
type DesiredRunnersUp = DesiredRunnersUp;
type LoserCandidate = Treasury;
type BadReport = Treasury;
type KickedMember = Treasury;
Expand Down Expand Up @@ -576,7 +583,7 @@ construct_runtime!(
Democracy: democracy::{Module, Call, Storage, Config, Event<T>},
Council: collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
TechnicalCommittee: collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
ElectionsPhragmen: elections_phragmen::{Module, Call, Storage, Event<T>, Config<T>},
ElectionsPhragmen: elections_phragmen::{Module, Call, Storage, Event<T>},
TechnicalMembership: membership::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
Treasury: treasury::{Module, Call, Storage, Event<T>},

Expand Down Expand Up @@ -742,4 +749,14 @@ impl_runtime_apis! {
System::account_nonce(account)
}
}

impl srml_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
Block,
Balance,
UncheckedExtrinsic,
> for Runtime {
fn query_info(uxt: UncheckedExtrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
TransactionPayment::query_info(uxt, len)
}
}
}
28 changes: 4 additions & 24 deletions service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
use primitives::{Pair, Public, crypto::UncheckedInto, sr25519};
use polkadot_primitives::{AccountId, AccountPublic, parachain::ValidatorId};
use polkadot_runtime::{
GenesisConfig, CouncilConfig, ElectionsPhragmenConfig, DemocracyConfig, SystemConfig,
SessionConfig, StakingConfig, BalancesConfig, SessionKeys, TechnicalCommitteeConfig,
SudoConfig, IndicesConfig, StakerStatus, WASM_BINARY,
ClaimsConfig, ParachainsConfig, RegistrarConfig
GenesisConfig, CouncilConfig, DemocracyConfig, SystemConfig, SessionConfig, StakingConfig,
BalancesConfig, SessionKeys, TechnicalCommitteeConfig, SudoConfig, IndicesConfig, StakerStatus,
WASM_BINARY, ClaimsConfig, ParachainsConfig, RegistrarConfig
};
use polkadot_runtime::constants::{currency::DOTS, time::*};
use polkadot_runtime::constants::currency::DOTS;
use sr_primitives::{traits::IdentifyAccount, Perbill};
use telemetry::TelemetryEndpoints;
use hex_literal::hex;
Expand Down Expand Up @@ -138,12 +137,6 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
members: vec![],
phantom: Default::default(),
}),
elections_phragmen: Some(ElectionsPhragmenConfig {
members: vec![],
term_duration: 49 * DAYS,
desired_members: 7,
desired_runners_up: 3,
}),
membership_Instance1: Some(Default::default()),
babe: Some(Default::default()),
grandpa: Some(Default::default()),
Expand Down Expand Up @@ -239,8 +232,6 @@ pub fn testnet_genesis(
const ENDOWMENT: u128 = 1_000_000 * DOTS;
const STASH: u128 = 100 * DOTS;

let desired_members = (endowed_accounts.len() / 2 - initial_authorities.len()) as u32;

GenesisConfig {
system: Some(SystemConfig {
code: WASM_BINARY.to_vec(),
Expand Down Expand Up @@ -280,17 +271,6 @@ pub fn testnet_genesis(
members: vec![],
phantom: Default::default(),
}),
elections_phragmen: Some(ElectionsPhragmenConfig {
members: endowed_accounts.iter()
.filter(|&endowed| initial_authorities.iter()
.find(|&(_, controller, _, _, _, _)| controller == endowed)
.is_none()
).cloned()
.collect(),
term_duration: 1 * DAYS,
desired_runners_up: desired_members / 2,
desired_members,
}),
membership_Instance1: Some(Default::default()),
babe: Some(Default::default()),
grandpa: Some(Default::default()),
Expand Down

0 comments on commit 775a6d5

Please sign in to comment.