mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 01:41:09 +00:00
Refactor sr-api to not depend on client anymore (#4086)
* Refactor sr-api to not depend on client anymore * Fix benches * Apply suggestions from code review Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Apply suggestions from code review
This commit is contained in:
committed by
Benjamin Kampmann
parent
e26d1a0b3e
commit
2ecffa1cd0
@@ -10,6 +10,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive
|
||||
primitives = { package = "substrate-primitives", path = "../../primitives" }
|
||||
sr-primitives = { path = "../../sr-primitives" }
|
||||
client = { package = "substrate-client", path = "../../client" }
|
||||
block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../block-builder/runtime-api" }
|
||||
srml-timestamp = { path = "../../../srml/timestamp" }
|
||||
inherents = { package = "substrate-inherents", path = "../../inherents" }
|
||||
pow-primitives = { package = "substrate-consensus-pow-primitives", path = "primitives" }
|
||||
|
||||
@@ -6,7 +6,7 @@ description = "Primitives for Aura consensus"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
substrate-client = { path = "../../../client", default-features = false }
|
||||
sr-api = { path = "../../../sr-api", default-features = false }
|
||||
rstd = { package = "sr-std", path = "../../../sr-std", default-features = false }
|
||||
sr-primitives = { path = "../../../sr-primitives", default-features = false }
|
||||
primitives = { package = "substrate-primitives", path = "../../../primitives", default-features = false }
|
||||
@@ -16,7 +16,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", default-features =
|
||||
default = ["std"]
|
||||
std = [
|
||||
"rstd/std",
|
||||
"substrate-client/std",
|
||||
"sr-api/std",
|
||||
"sr-primitives/std",
|
||||
"primitives/std",
|
||||
"codec/std",
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
use rstd::vec::Vec;
|
||||
use sr_primitives::ConsensusEngineId;
|
||||
use codec::Decode;
|
||||
use substrate_client::decl_runtime_apis;
|
||||
|
||||
/// The `ConsensusEngineId` of PoW.
|
||||
pub const POW_ENGINE_ID: ConsensusEngineId = [b'p', b'o', b'w', b'_'];
|
||||
@@ -48,7 +47,7 @@ impl TotalDifficulty for u128 {
|
||||
}
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
sr_api::decl_runtime_apis! {
|
||||
/// API necessary for timestamp-based difficulty adjustment algorithms.
|
||||
pub trait TimestampApi<Moment: Decode> {
|
||||
/// Return the timestamp in the current block.
|
||||
|
||||
@@ -33,10 +33,10 @@ use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::collections::HashMap;
|
||||
use client::{
|
||||
BlockOf, blockchain::{HeaderBackend, ProvideCache},
|
||||
block_builder::api::BlockBuilder as BlockBuilderApi, backend::AuxStore,
|
||||
BlockOf, blockchain::{HeaderBackend, ProvideCache}, backend::AuxStore,
|
||||
well_known_cache_keys::Id as CacheKeyId,
|
||||
};
|
||||
use block_builder_api::BlockBuilder as BlockBuilderApi;
|
||||
use sr_primitives::{Justification, RuntimeString};
|
||||
use sr_primitives::generic::{BlockId, Digest, DigestItem};
|
||||
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, ProvideRuntimeApi};
|
||||
@@ -75,7 +75,7 @@ pub enum Error<B: BlockT> {
|
||||
#[display(fmt = "Error with block built on {:?}: {:?}", _0, _1)]
|
||||
BlockBuiltError(B::Hash, ConsensusError),
|
||||
#[display(fmt = "Creating inherents failed: {}", _0)]
|
||||
CreateInherents(RuntimeString),
|
||||
CreateInherents(inherents::Error),
|
||||
#[display(fmt = "Checking inherents failed: {}", _0)]
|
||||
CheckInherents(String),
|
||||
Client(client::error::Error),
|
||||
@@ -210,7 +210,7 @@ impl<B: BlockT<Hash=H256>, C, S, Algorithm> PowVerifier<B, C, S, Algorithm> {
|
||||
inherent_data: InherentData,
|
||||
timestamp_now: u64,
|
||||
) -> Result<(), Error<B>> where
|
||||
C: ProvideRuntimeApi, C::Api: BlockBuilderApi<B>
|
||||
C: ProvideRuntimeApi, C::Api: BlockBuilderApi<B, Error = client::error::Error>
|
||||
{
|
||||
const MAX_TIMESTAMP_DRIFT_SECS: u64 = 60;
|
||||
|
||||
@@ -248,7 +248,7 @@ impl<B: BlockT<Hash=H256>, C, S, Algorithm> PowVerifier<B, C, S, Algorithm> {
|
||||
|
||||
impl<B: BlockT<Hash=H256>, C, S, Algorithm> Verifier<B> for PowVerifier<B, C, S, Algorithm> where
|
||||
C: ProvideRuntimeApi + Send + Sync + HeaderBackend<B> + AuxStore + ProvideCache<B> + BlockOf,
|
||||
C::Api: BlockBuilderApi<B>,
|
||||
C::Api: BlockBuilderApi<B, Error = client::error::Error>,
|
||||
S: SelectChain<B>,
|
||||
Algorithm: PowAlgorithm<B> + Send + Sync,
|
||||
{
|
||||
@@ -260,8 +260,8 @@ impl<B: BlockT<Hash=H256>, C, S, Algorithm> Verifier<B> for PowVerifier<B, C, S,
|
||||
mut body: Option<Vec<B::Extrinsic>>,
|
||||
) -> Result<(BlockImportParams<B>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String> {
|
||||
let inherent_data = self.inherent_data_providers
|
||||
.create_inherent_data().map_err(String::from)?;
|
||||
let timestamp_now = inherent_data.timestamp_inherent_data().map_err(String::from)?;
|
||||
.create_inherent_data().map_err(|e| e.into_string())?;
|
||||
let timestamp_now = inherent_data.timestamp_inherent_data().map_err(|e| e.into_string())?;
|
||||
|
||||
let best_hash = match self.select_chain.as_ref() {
|
||||
Some(select_chain) => select_chain.best_chain()
|
||||
@@ -340,7 +340,7 @@ pub fn import_queue<B, C, S, Algorithm>(
|
||||
B: BlockT<Hash=H256>,
|
||||
C: ProvideRuntimeApi + HeaderBackend<B> + BlockOf + ProvideCache<B> + AuxStore,
|
||||
C: Send + Sync + AuxStore + 'static,
|
||||
C::Api: BlockBuilderApi<B>,
|
||||
C::Api: BlockBuilderApi<B, Error = client::error::Error>,
|
||||
Algorithm: PowAlgorithm<B> + Send + Sync + 'static,
|
||||
S: SelectChain<B> + 'static,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user