mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
Enable Babe RPC for getting epoch authorship (#1065)
Enable babe_epochAuthorship that was added in substrate#4729 for querying information about slots that can be claimed in the current epoch.
This commit is contained in:
Generated
+28
@@ -4276,11 +4276,17 @@ dependencies = [
|
||||
"parity-scale-codec",
|
||||
"polkadot-primitives",
|
||||
"sc-client-api",
|
||||
"sc-consensus-babe",
|
||||
"sc-consensus-babe-rpc",
|
||||
"sc-consensus-epochs",
|
||||
"sc-finality-grandpa",
|
||||
"sc-finality-grandpa-rpc",
|
||||
"sc-keystore",
|
||||
"sc-rpc",
|
||||
"sp-api",
|
||||
"sp-blockchain",
|
||||
"sp-consensus",
|
||||
"sp-consensus-babe",
|
||||
"sp-runtime",
|
||||
"sp-transaction-pool",
|
||||
"substrate-frame-rpc-system",
|
||||
@@ -5536,6 +5542,28 @@ dependencies = [
|
||||
"substrate-prometheus-endpoint",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sc-consensus-babe-rpc"
|
||||
version = "0.8.0-dev"
|
||||
source = "git+https://github.com/paritytech/substrate#c0ccc24d02080ab4fbb2c65440327fc72acb6c42"
|
||||
dependencies = [
|
||||
"derive_more 0.99.5",
|
||||
"futures 0.3.4",
|
||||
"jsonrpc-core",
|
||||
"jsonrpc-core-client",
|
||||
"jsonrpc-derive",
|
||||
"sc-consensus-babe",
|
||||
"sc-consensus-epochs",
|
||||
"sc-keystore",
|
||||
"serde",
|
||||
"sp-api",
|
||||
"sp-blockchain",
|
||||
"sp-consensus",
|
||||
"sp-consensus-babe",
|
||||
"sp-core",
|
||||
"sp-runtime",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sc-consensus-epochs"
|
||||
version = "0.8.0-alpha.8"
|
||||
|
||||
@@ -11,9 +11,15 @@ sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "mas
|
||||
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master"}
|
||||
sc-consensus-babe-rpc = { git = "https://github.com/paritytech/substrate", branch = "master"}
|
||||
sc-consensus-epochs = { git = "https://github.com/paritytech/substrate", branch = "master"}
|
||||
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-finality-grandpa-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master"}
|
||||
txpool-api = { package = "sp-transaction-pool", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
+71
-11
@@ -23,12 +23,37 @@ use std::sync::Arc;
|
||||
use polkadot_primitives::{Block, BlockNumber, AccountId, Nonce, Balance, Hash};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use txpool_api::TransactionPool;
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_blockchain::{HeaderBackend, HeaderMetadata, Error as BlockChainError};
|
||||
use sp_consensus::SelectChain;
|
||||
use sc_client_api::light::{Fetcher, RemoteBlockchain};
|
||||
use sc_consensus_babe::Epoch;
|
||||
use sp_consensus_babe::BabeApi;
|
||||
|
||||
/// A type representing all RPC extensions.
|
||||
pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
|
||||
|
||||
/// Light client extra dependencies.
|
||||
pub struct LightDeps<C, F, P> {
|
||||
/// The client instance to use.
|
||||
pub client: Arc<C>,
|
||||
/// Transaction pool instance.
|
||||
pub pool: Arc<P>,
|
||||
/// Remote access to the blockchain (async).
|
||||
pub remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
|
||||
/// Fetcher instance.
|
||||
pub fetcher: Arc<F>,
|
||||
}
|
||||
|
||||
/// Extra dependencies for BABE.
|
||||
pub struct BabeDeps {
|
||||
/// BABE protocol config.
|
||||
pub babe_config: sc_consensus_babe::Config,
|
||||
/// BABE pending epoch changes.
|
||||
pub shared_epoch_changes: sc_consensus_epochs::SharedEpochChanges<Block, Epoch>,
|
||||
/// The keystore that manages the keys of the node.
|
||||
pub keystore: sc_keystore::KeyStorePtr,
|
||||
}
|
||||
|
||||
/// Dependencies for GRANDPA
|
||||
pub struct GrandpaDeps {
|
||||
/// Voting round info.
|
||||
@@ -37,31 +62,65 @@ pub struct GrandpaDeps {
|
||||
pub shared_authority_set: sc_finality_grandpa::SharedAuthoritySet<Hash, BlockNumber>,
|
||||
}
|
||||
|
||||
/// Full client dependencies
|
||||
pub struct FullDeps<C, P, SC> {
|
||||
/// The client instance to use.
|
||||
pub client: Arc<C>,
|
||||
/// Transaction pool instance.
|
||||
pub pool: Arc<P>,
|
||||
/// The SelectChain Strategy
|
||||
pub select_chain: SC,
|
||||
/// BABE specific dependencies.
|
||||
pub babe: BabeDeps,
|
||||
/// GRANDPA specific dependencies.
|
||||
pub grandpa: GrandpaDeps,
|
||||
}
|
||||
|
||||
/// Instantiate all RPC extensions.
|
||||
pub fn create_full<C, P, UE>(client: Arc<C>, pool: Arc<P>, grandpa_deps: GrandpaDeps) -> RpcExtension where
|
||||
pub fn create_full<C, P, UE, SC>(deps: FullDeps<C, P, SC>) -> RpcExtension where
|
||||
C: ProvideRuntimeApi<Block>,
|
||||
C: HeaderBackend<Block>,
|
||||
C: HeaderBackend<Block> + HeaderMetadata<Block, Error=BlockChainError>,
|
||||
C: Send + Sync + 'static,
|
||||
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
|
||||
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance, UE>,
|
||||
C::Api: BabeApi<Block>,
|
||||
P: TransactionPool + Sync + Send + 'static,
|
||||
UE: codec::Codec + Send + Sync + 'static,
|
||||
SC: SelectChain<Block> + 'static,
|
||||
{
|
||||
use frame_rpc_system::{FullSystem, SystemApi};
|
||||
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
|
||||
use sc_finality_grandpa_rpc::{GrandpaApi, GrandpaRpcHandler};
|
||||
use sc_consensus_babe_rpc::BabeRPCHandler;
|
||||
|
||||
let mut io = jsonrpc_core::IoHandler::default();
|
||||
let FullDeps {
|
||||
client,
|
||||
pool,
|
||||
select_chain,
|
||||
babe,
|
||||
grandpa,
|
||||
} = deps;
|
||||
let BabeDeps {
|
||||
keystore,
|
||||
babe_config,
|
||||
shared_epoch_changes,
|
||||
} = babe;
|
||||
let GrandpaDeps {
|
||||
shared_voter_state,
|
||||
shared_authority_set,
|
||||
} = grandpa_deps;
|
||||
} = grandpa;
|
||||
|
||||
io.extend_with(
|
||||
SystemApi::to_delegate(FullSystem::new(client.clone(), pool))
|
||||
);
|
||||
io.extend_with(
|
||||
TransactionPaymentApi::to_delegate(TransactionPayment::new(client))
|
||||
TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone()))
|
||||
);
|
||||
io.extend_with(
|
||||
sc_consensus_babe_rpc::BabeApi::to_delegate(
|
||||
BabeRPCHandler::new(client, shared_epoch_changes, keystore, babe_config, select_chain)
|
||||
)
|
||||
);
|
||||
io.extend_with(
|
||||
GrandpaApi::to_delegate(GrandpaRpcHandler::new(
|
||||
@@ -73,12 +132,7 @@ pub fn create_full<C, P, UE>(client: Arc<C>, pool: Arc<P>, grandpa_deps: Grandpa
|
||||
}
|
||||
|
||||
/// Instantiate all RPC extensions for light node.
|
||||
pub fn create_light<C, P, F, UE>(
|
||||
client: Arc<C>,
|
||||
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
|
||||
fetcher: Arc<F>,
|
||||
pool: Arc<P>,
|
||||
) -> RpcExtension
|
||||
pub fn create_light<C, P, F, UE>(deps: LightDeps<C, F, P>) -> RpcExtension
|
||||
where
|
||||
C: ProvideRuntimeApi<Block>,
|
||||
C: HeaderBackend<Block>,
|
||||
@@ -91,6 +145,12 @@ pub fn create_light<C, P, F, UE>(
|
||||
{
|
||||
use frame_rpc_system::{LightSystem, SystemApi};
|
||||
|
||||
let LightDeps {
|
||||
client,
|
||||
pool,
|
||||
remote_blockchain,
|
||||
fetcher,
|
||||
} = deps;
|
||||
let mut io = jsonrpc_core::IoHandler::default();
|
||||
io.extend_with(
|
||||
SystemApi::<AccountId, Nonce>::to_delegate(LightSystem::new(client, remote_blockchain, fetcher, pool))
|
||||
|
||||
@@ -214,16 +214,29 @@ macro_rules! new_full_start {
|
||||
Ok(import_queue)
|
||||
})?
|
||||
.with_rpc_extensions(|builder| -> Result<polkadot_rpc::RpcExtension, _> {
|
||||
let babe_link = import_setup.as_ref().map(|s| &s.2)
|
||||
.expect("BabeLink is present for full services or set up faile; qed.");
|
||||
let grandpa_link = import_setup.as_ref().map(|s| &s.1)
|
||||
.expect("GRANDPA LinkHalf is present for full services or set up failed; qed.");
|
||||
let shared_authority_set = grandpa_link.shared_authority_set();
|
||||
let shared_voter_state = SharedVoterState::empty();
|
||||
let grandpa_deps = polkadot_rpc::GrandpaDeps {
|
||||
let deps = polkadot_rpc::FullDeps {
|
||||
client: builder.client().clone(),
|
||||
pool: builder.pool(),
|
||||
select_chain: builder.select_chain().cloned()
|
||||
.expect("SelectChain is present for full services or set up failed; qed."),
|
||||
babe: polkadot_rpc::BabeDeps {
|
||||
keystore: builder.keystore(),
|
||||
babe_config: babe::BabeLink::config(babe_link).clone(),
|
||||
shared_epoch_changes: babe::BabeLink::epoch_changes(babe_link).clone(),
|
||||
},
|
||||
grandpa: polkadot_rpc::GrandpaDeps {
|
||||
shared_voter_state: shared_voter_state.clone(),
|
||||
shared_authority_set: shared_authority_set.clone(),
|
||||
},
|
||||
};
|
||||
rpc_setup = Some((shared_voter_state));
|
||||
Ok(polkadot_rpc::create_full(builder.client().clone(), builder.pool(), grandpa_deps))
|
||||
Ok(polkadot_rpc::create_full(deps))
|
||||
})?;
|
||||
|
||||
(builder, import_setup, inherent_data_providers, rpc_setup)
|
||||
@@ -586,7 +599,13 @@ macro_rules! new_light {
|
||||
let remote_blockchain = builder.remote_backend()
|
||||
.ok_or_else(|| "Trying to start node RPC without active remote blockchain")?;
|
||||
|
||||
Ok(polkadot_rpc::create_light(builder.client().clone(), remote_blockchain, fetcher, builder.pool()))
|
||||
let light_deps = polkadot_rpc::LightDeps {
|
||||
remote_blockchain,
|
||||
fetcher,
|
||||
client: builder.client().clone(),
|
||||
pool: builder.pool(),
|
||||
};
|
||||
Ok(polkadot_rpc::create_light(light_deps))
|
||||
})?
|
||||
.build()
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user