mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
Add chain RPCs and getHeader. (#124)
* Add chain RPCs and getHeader. Also: - finish renaming transaction -> extrinsic; - rejig development chain spec to be more useful. * Fix. * Remove invalid comments. * Fix.
This commit is contained in:
@@ -141,7 +141,7 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
|||||||
address.set_port(rpc_port);
|
address.set_port(rpc_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
let handler = rpc::rpc_handler(service.client(), service.transaction_pool());
|
let handler = rpc::rpc_handler(service.client(), service.transaction_pool(), service.client());
|
||||||
let _server = rpc::start_http(&address, handler)?;
|
let _server = rpc::start_http(&address, handler)?;
|
||||||
|
|
||||||
informant::start(&service, core.handle());
|
informant::start(&service, core.handle());
|
||||||
|
|||||||
+37
-29
@@ -123,7 +123,12 @@ impl network::TransactionPool for TransactionPoolAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poc_1_testnet_config() -> GenesisConfig {
|
pub struct ChainConfig {
|
||||||
|
genesis_config: GenesisConfig,
|
||||||
|
boot_nodes: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poc_1_testnet_config() -> ChainConfig {
|
||||||
let initial_authorities = vec![
|
let initial_authorities = vec![
|
||||||
hex!["82c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf5"].into(),
|
hex!["82c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf5"].into(),
|
||||||
hex!["4de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7"].into(),
|
hex!["4de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7"].into(),
|
||||||
@@ -132,13 +137,12 @@ fn poc_1_testnet_config() -> GenesisConfig {
|
|||||||
let endowed_accounts = vec![
|
let endowed_accounts = vec![
|
||||||
hex!["24d132eb1a4cbf8e46de22652019f1e07fadd5037a6a057c75dbbfd4641ba85d"].into(),
|
hex!["24d132eb1a4cbf8e46de22652019f1e07fadd5037a6a057c75dbbfd4641ba85d"].into(),
|
||||||
];
|
];
|
||||||
GenesisConfig {
|
let genesis_config = GenesisConfig {
|
||||||
consensus: Some(ConsensusConfig {
|
consensus: Some(ConsensusConfig {
|
||||||
code: include_bytes!("../../runtime/wasm/genesis.wasm").to_vec(), // TODO change
|
code: include_bytes!("../../runtime/wasm/genesis.wasm").to_vec(), // TODO change
|
||||||
authorities: initial_authorities.clone(),
|
authorities: initial_authorities.clone(),
|
||||||
}),
|
}),
|
||||||
system: None,
|
system: None,
|
||||||
// block_time: 5, // 5 second block time.
|
|
||||||
session: Some(SessionConfig {
|
session: Some(SessionConfig {
|
||||||
validators: initial_authorities.clone(),
|
validators: initial_authorities.clone(),
|
||||||
session_length: 720, // that's 1 hour per session.
|
session_length: 720, // that's 1 hour per session.
|
||||||
@@ -173,10 +177,12 @@ fn poc_1_testnet_config() -> GenesisConfig {
|
|||||||
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
|
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
|
||||||
}),
|
}),
|
||||||
parachains: Some(Default::default()),
|
parachains: Some(Default::default()),
|
||||||
}
|
};
|
||||||
|
let boot_nodes = Vec::new();
|
||||||
|
ChainConfig { genesis_config, boot_nodes }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_testnet_config() -> GenesisConfig {
|
fn local_testnet_config() -> ChainConfig {
|
||||||
let initial_authorities = vec![
|
let initial_authorities = vec![
|
||||||
ed25519::Pair::from_seed(b"Alice ").public().into(),
|
ed25519::Pair::from_seed(b"Alice ").public().into(),
|
||||||
ed25519::Pair::from_seed(b"Bob ").public().into(),
|
ed25519::Pair::from_seed(b"Bob ").public().into(),
|
||||||
@@ -189,53 +195,54 @@ fn local_testnet_config() -> GenesisConfig {
|
|||||||
ed25519::Pair::from_seed(b"Eve ").public().into(),
|
ed25519::Pair::from_seed(b"Eve ").public().into(),
|
||||||
ed25519::Pair::from_seed(b"Ferdie ").public().into(),
|
ed25519::Pair::from_seed(b"Ferdie ").public().into(),
|
||||||
];
|
];
|
||||||
GenesisConfig {
|
let genesis_config = GenesisConfig {
|
||||||
consensus: Some(ConsensusConfig {
|
consensus: Some(ConsensusConfig {
|
||||||
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm").to_vec(),
|
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm").to_vec(),
|
||||||
authorities: initial_authorities.clone(),
|
authorities: initial_authorities.clone(),
|
||||||
}),
|
}),
|
||||||
system: None,
|
system: None,
|
||||||
// block_time: 5, // 5 second block time.
|
|
||||||
session: Some(SessionConfig {
|
session: Some(SessionConfig {
|
||||||
validators: initial_authorities.clone(),
|
validators: initial_authorities.clone(),
|
||||||
session_length: 720, // that's 1 hour per session.
|
session_length: 10,
|
||||||
}),
|
}),
|
||||||
staking: Some(StakingConfig {
|
staking: Some(StakingConfig {
|
||||||
current_era: 0,
|
current_era: 0,
|
||||||
intentions: vec![],
|
intentions: vec![],
|
||||||
transaction_fee: 100,
|
transaction_fee: 1,
|
||||||
balances: endowed_accounts.iter().map(|&k|(k, 1u64 << 60)).collect(),
|
balances: endowed_accounts.iter().map(|&k|(k, 1u64 << 60)).collect(),
|
||||||
validator_count: 12,
|
validator_count: 2,
|
||||||
sessions_per_era: 24, // 24 hours per era.
|
sessions_per_era: 5,
|
||||||
bonding_duration: 90, // 90 days per bond.
|
bonding_duration: 2,
|
||||||
}),
|
}),
|
||||||
democracy: Some(DemocracyConfig {
|
democracy: Some(DemocracyConfig {
|
||||||
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
|
launch_period: 9,
|
||||||
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
|
voting_period: 18,
|
||||||
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
|
minimum_deposit: 10,
|
||||||
}),
|
}),
|
||||||
council: Some(CouncilConfig {
|
council: Some(CouncilConfig {
|
||||||
active_council: vec![],
|
active_council: vec![],
|
||||||
candidacy_bond: 1000, // 1000 to become a council candidate
|
candidacy_bond: 10,
|
||||||
voter_bond: 100, // 100 down to vote for a candidate
|
voter_bond: 2,
|
||||||
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
|
present_slash_per_voter: 1,
|
||||||
carry_count: 24, // carry over the 24 runners-up to the next council election
|
carry_count: 4,
|
||||||
presentation_duration: 120 * 24, // one day for presenting winners.
|
presentation_duration: 10,
|
||||||
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
|
approval_voting_period: 20,
|
||||||
term_duration: 180 * 120 * 24, // 180 day term duration for the council.
|
term_duration: 40,
|
||||||
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
|
desired_seats: 0,
|
||||||
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.
|
inactive_grace_period: 1,
|
||||||
|
|
||||||
cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
|
cooloff_period: 75,
|
||||||
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
|
voting_period: 20,
|
||||||
}),
|
}),
|
||||||
parachains: Some(Default::default()),
|
parachains: Some(Default::default()),
|
||||||
}
|
};
|
||||||
|
let boot_nodes = Vec::new();
|
||||||
|
ChainConfig { genesis_config, boot_nodes }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
/// Creates and register protocol with the network service
|
/// Creates and register protocol with the network service
|
||||||
pub fn new(config: Configuration) -> Result<Service, error::Error> {
|
pub fn new(mut config: Configuration) -> Result<Service, error::Error> {
|
||||||
// Create client
|
// Create client
|
||||||
let executor = polkadot_executor::Executor::new();
|
let executor = polkadot_executor::Executor::new();
|
||||||
let mut storage = Default::default();
|
let mut storage = Default::default();
|
||||||
@@ -250,10 +257,11 @@ impl Service {
|
|||||||
info!("Generated a new keypair: {:?}", key.public());
|
info!("Generated a new keypair: {:?}", key.public());
|
||||||
}
|
}
|
||||||
|
|
||||||
let genesis_config = match config.chain_spec {
|
let ChainConfig { genesis_config, boot_nodes } = match config.chain_spec {
|
||||||
ChainSpec::Development => local_testnet_config(),
|
ChainSpec::Development => local_testnet_config(),
|
||||||
ChainSpec::PoC1Testnet => poc_1_testnet_config(),
|
ChainSpec::PoC1Testnet => poc_1_testnet_config(),
|
||||||
};
|
};
|
||||||
|
config.network.boot_nodes.extend(boot_nodes);
|
||||||
|
|
||||||
let prepare_genesis = || {
|
let prepare_genesis = || {
|
||||||
storage = genesis_config.build_externalities();
|
storage = genesis_config.build_externalities();
|
||||||
|
|||||||
Reference in New Issue
Block a user