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
+2 -1
View File
@@ -8,7 +8,8 @@ edition = "2018"
[dependencies]
bytes = "0.4.12"
client = { package = "substrate-client", path = "../../core/client" }
client = { package = "substrate-client", path = "../client" }
sr-api = { path = "../sr-api" }
fnv = "1.0.6"
futures01 = { package = "futures", version = "0.1" }
futures-preview = "0.3.0-alpha.19"
@@ -7,12 +7,12 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
client = { package = "substrate-client", path = "../../client", default-features = false }
sr-api = { path = "../../sr-api", default-features = false }
sr-primitives = { path = "../../sr-primitives", default-features = false }
[features]
default = ["std"]
std = [
"client/std",
"sr-api/std",
"sr-primitives/std"
]
@@ -19,13 +19,12 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]
use client::decl_runtime_apis;
use sr_primitives::traits::NumberFor;
/// Local Storage Prefix used by the Offchain Worker API to
pub const STORAGE_PREFIX: &[u8] = b"storage";
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
/// The offchain worker api.
pub trait OffchainWorkerApi {
/// Starts the off-chain task for given block number.
+3 -7
View File
@@ -33,15 +33,11 @@
#![warn(missing_docs)]
use std::{
fmt,
marker::PhantomData,
sync::Arc,
};
use std::{fmt, marker::PhantomData, sync::Arc};
use parking_lot::Mutex;
use threadpool::ThreadPool;
use client::runtime_api::ApiExt;
use sr_api::ApiExt;
use futures::future::Future;
use log::{debug, warn};
use network::NetworkStateInfo;
@@ -106,7 +102,7 @@ impl<Client, Storage, Block> OffchainWorkers<
) -> impl Future<Output = ()> where A: ChainApi<Block=Block> + 'static {
let runtime = self.client.runtime_api();
let at = BlockId::number(*number);
let has_api = runtime.has_api::<dyn OffchainWorkerApi<Block>>(&at);
let has_api = runtime.has_api::<dyn OffchainWorkerApi<Block, Error = ()>>(&at);
debug!("Checking offchain workers at {:?}: {:?}", at, has_api);
if has_api.unwrap_or(false) {