Offchain-worker APIs stubs (#2615)

* WiP: HTTP Apis.

* Working on the API.

* Add docs, clean up the API.

* Expose ext_ stuff as well.

* Implement HTTP helpers for offchain sr-io.

* Remove HTTP stuff.

* Revert "Remove HTTP stuff."

This reverts commit 7cca029d6ae93c5849b50edfcc6d2c313ba3e5bf.

* HTTP apis.

* Additional offchain methods.

* Make it compile.

* Implement wasm-ext boundary of offchain methods.

* Add stubs for offchain stuff to prevent panics.

* Fix tests.

* Addres some more issues.

* Introduce typedef, use unsafe from_utf8

* Bump runtime version.

* Introduce error to distinguish deadline and io errors.

* Add local_storage_cas

* Some tests for offchain stuff.

* Address more grumbles.

* Fix tests compilation.

* Fix borked merge.

* Improve docs for expected return values from ext functions.

* Adding new sign/enrypt/decrypt APIs.
This commit is contained in:
Tomasz Drwięga
2019-05-31 09:33:44 +02:00
committed by Gavin Wood
parent 80b18c8531
commit 308ab4f269
26 changed files with 2648 additions and 120 deletions
+7 -9
View File
@@ -26,9 +26,7 @@ use state_machine::{
use executor::{RuntimeVersion, RuntimeInfo, NativeVersion};
use hash_db::Hasher;
use trie::MemoryDB;
use primitives::{
H256, Blake2Hasher, NativeOrEncoded, NeverNativeValue, OffchainExt
};
use primitives::{offchain, H256, Blake2Hasher, NativeOrEncoded, NeverNativeValue};
use crate::runtime_api::{ProofRecorder, InitializeBlock};
use crate::backend;
@@ -48,7 +46,7 @@ where
///
/// No changes are made.
fn call<
O: OffchainExt,
O: offchain::Externalities,
>(
&self,
id: &BlockId<B>,
@@ -65,7 +63,7 @@ where
/// of the execution context.
fn contextual_call<
'a,
O: OffchainExt,
O: offchain::Externalities,
IB: Fn() -> error::Result<()>,
EM: Fn(
Result<NativeOrEncoded<R>, Self::Error>,
@@ -96,7 +94,7 @@ where
///
/// No changes are made.
fn call_at_state<
O: OffchainExt,
O: offchain::Externalities,
S: state_machine::Backend<H>,
F: FnOnce(
Result<NativeOrEncoded<R>, Self::Error>,
@@ -181,7 +179,7 @@ where
{
type Error = E::Error;
fn call<O: OffchainExt>(
fn call<O: offchain::Externalities>(
&self,
id: &BlockId<Block>,
method: &str,
@@ -211,7 +209,7 @@ where
fn contextual_call<
'a,
O: OffchainExt,
O: offchain::Externalities,
IB: Fn() -> error::Result<()>,
EM: Fn(
Result<NativeOrEncoded<R>, Self::Error>,
@@ -300,7 +298,7 @@ where
}
fn call_at_state<
O: OffchainExt,
O: offchain::Externalities,
S: state_machine::Backend<Blake2Hasher>,
F: FnOnce(
Result<NativeOrEncoded<R>, Self::Error>,
@@ -24,7 +24,7 @@ use std::{
use futures::{IntoFuture, Future};
use parity_codec::{Encode, Decode};
use primitives::{H256, Blake2Hasher, convert_hash, NativeOrEncoded, OffchainExt};
use primitives::{offchain, H256, Blake2Hasher, convert_hash, NativeOrEncoded};
use runtime_primitives::generic::BlockId;
use runtime_primitives::traits::{One, Block as BlockT, Header as HeaderT};
use state_machine::{
@@ -87,7 +87,7 @@ where
type Error = ClientError;
fn call<
O: OffchainExt,
O: offchain::Externalities,
>(
&self,
id: &BlockId<Block>,
@@ -111,7 +111,7 @@ where
fn contextual_call<
'a,
O: OffchainExt,
O: offchain::Externalities,
IB: Fn() -> ClientResult<()>,
EM: Fn(
Result<NativeOrEncoded<R>, Self::Error>,
@@ -154,7 +154,7 @@ where
}
fn call_at_state<
O: OffchainExt,
O: offchain::Externalities,
S: StateBackend<Blake2Hasher>,
FF: FnOnce(
Result<NativeOrEncoded<R>, Self::Error>,
@@ -230,7 +230,7 @@ impl<Block, B, Remote, Local> CallExecutor<Block, Blake2Hasher> for
type Error = ClientError;
fn call<
O: OffchainExt,
O: offchain::Externalities,
>(
&self,
id: &BlockId<Block>,
@@ -247,7 +247,7 @@ impl<Block, B, Remote, Local> CallExecutor<Block, Blake2Hasher> for
fn contextual_call<
'a,
O: OffchainExt,
O: offchain::Externalities,
IB: Fn() -> ClientResult<()>,
EM: Fn(
Result<NativeOrEncoded<R>, Self::Error>,
@@ -327,7 +327,7 @@ impl<Block, B, Remote, Local> CallExecutor<Block, Blake2Hasher> for
}
fn call_at_state<
O: OffchainExt,
O: offchain::Externalities,
S: StateBackend<Blake2Hasher>,
FF: FnOnce(
Result<NativeOrEncoded<R>, Self::Error>,
+1 -1
View File
@@ -31,7 +31,7 @@ pub use runtime_primitives::{
generic::BlockId, transaction_validity::TransactionValidity,
};
#[doc(hidden)]
pub use primitives::{ExecutionContext, OffchainExt};
pub use primitives::{offchain, ExecutionContext};
#[doc(hidden)]
pub use runtime_version::{ApiId, RuntimeVersion, ApisVec, create_apis_vec};
#[doc(hidden)]