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:
Bastian Köcher
2019-11-11 16:26:49 +01:00
committed by Benjamin Kampmann
parent e26d1a0b3e
commit 2ecffa1cd0
140 changed files with 1514 additions and 984 deletions
+4 -7
View File
@@ -29,10 +29,7 @@ use codec::{Encode, Decode};
use system::ensure_none;
use sr_primitives::traits::{Header as HeaderT, One, Zero};
use sr_primitives::weights::SimpleDispatchInfo;
use inherents::{
RuntimeString, InherentIdentifier, ProvideInherent,
InherentData, MakeFatalError,
};
use inherents::{InherentIdentifier, ProvideInherent, InherentData, MakeFatalError};
/// The identifier for the `uncles` inherent.
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"uncles00";
@@ -40,11 +37,11 @@ pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"uncles00";
/// Auxiliary trait to extract uncles inherent data.
pub trait UnclesInherentData<H: Decode> {
/// Get uncles.
fn uncles(&self) -> Result<Vec<H>, RuntimeString>;
fn uncles(&self) -> Result<Vec<H>, inherents::Error>;
}
impl<H: Decode> UnclesInherentData<H> for InherentData {
fn uncles(&self) -> Result<Vec<H>, RuntimeString> {
fn uncles(&self) -> Result<Vec<H>, inherents::Error> {
Ok(self.get_data(&INHERENT_IDENTIFIER)?.unwrap_or_default())
}
}
@@ -71,7 +68,7 @@ where F: Fn() -> Vec<H>
&INHERENT_IDENTIFIER
}
fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), RuntimeString> {
fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), inherents::Error> {
let uncles = (self.inner)();
if !uncles.is_empty() {
inherent_data.put_data(INHERENT_IDENTIFIER, &uncles)