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
+12 -6
View File
@@ -98,12 +98,15 @@ use codec::Decode;
use inherents::ProvideInherentData;
use support::{Parameter, decl_storage, decl_module};
use support::traits::{Time, Get};
use sr_primitives::traits::{
SimpleArithmetic, Zero, SaturatedConversion, Scale
use sr_primitives::{
RuntimeString,
traits::{
SimpleArithmetic, Zero, SaturatedConversion, Scale
}
};
use sr_primitives::weights::SimpleDispatchInfo;
use system::ensure_none;
use inherents::{RuntimeString, InherentIdentifier, ProvideInherent, IsFatalError, InherentData};
use inherents::{InherentIdentifier, ProvideInherent, IsFatalError, InherentData};
/// The identifier for the `timestamp` inherent.
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"timstap0";
@@ -145,11 +148,11 @@ impl InherentError {
/// Auxiliary trait to extract timestamp inherent data.
pub trait TimestampInherentData {
/// Get timestamp inherent data.
fn timestamp_inherent_data(&self) -> Result<InherentType, RuntimeString>;
fn timestamp_inherent_data(&self) -> Result<InherentType, inherents::Error>;
}
impl TimestampInherentData for InherentData {
fn timestamp_inherent_data(&self) -> Result<InherentType, RuntimeString> {
fn timestamp_inherent_data(&self) -> Result<InherentType, inherents::Error> {
self.get_data(&INHERENT_IDENTIFIER)
.and_then(|r| r.ok_or_else(|| "Timestamp inherent data not found".into()))
}
@@ -164,7 +167,10 @@ impl ProvideInherentData for InherentDataProvider {
&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> {
use std::time::SystemTime;
let now = SystemTime::now();