Clean up sr-io (#3609)

* Move trait `Printable` into `sr-primitives`

* Cleanup runtime io trie_root interfaces

* Remove last generic bits from sr-io interface

* Fix srml-sudo after master merge

* Fix benchmarks

* Runtime bump
This commit is contained in:
Bastian Köcher
2019-09-13 16:39:50 +02:00
committed by GitHub
parent 5cb8c0dc1c
commit 45d64a711c
34 changed files with 309 additions and 372 deletions
+23 -58
View File
@@ -29,12 +29,8 @@
use hash_db::Hasher;
use rstd::vec::Vec;
#[doc(hidden)]
pub use codec;
pub use primitives::Blake2Hasher;
use primitives::{
crypto::KeyTypeId, ed25519, sr25519,
crypto::KeyTypeId, ed25519, sr25519, H256,
offchain::{
Timestamp, HttpRequestId, HttpRequestStatus, HttpError, StorageKind, OpaqueNetworkState,
},
@@ -52,18 +48,6 @@ pub enum EcdsaVerifyError {
pub mod offchain;
/// Trait for things which can be printed.
pub trait Printable {
/// Print the object.
fn print(&self);
}
impl Printable for u8 {
fn print(&self) {
u64::from(*self).print()
}
}
/// Converts a public trait definition into a private trait and set of public functions
/// that assume the trait is implemented for `()` for ease of calling.
macro_rules! export_api {
@@ -73,7 +57,6 @@ macro_rules! export_api {
$(
$( #[$attr:meta] )*
fn $name:ident
$(< $( $g_name:ident $( : $g_ty:path )? ),+ >)?
( $( $arg:ident : $arg_ty:ty ),* $(,)? )
$( -> $ret:ty )?
$( where $( $w_name:path : $w_ty:path ),+ )?;
@@ -84,18 +67,18 @@ macro_rules! export_api {
pub(crate) trait $trait_name {
$(
$( #[$attr] )*
fn $name $(< $( $g_name $( : $g_ty )? ),+ >)? ( $($arg : $arg_ty ),* ) $( -> $ret )?
fn $name ( $($arg : $arg_ty ),* ) $( -> $ret )?
$( where $( $w_name : $w_ty ),+ )?;
)*
}
$(
$( #[$attr] )*
pub fn $name $(< $( $g_name $( : $g_ty )? ),+ >)? ( $($arg : $arg_ty ),* ) $( -> $ret )?
pub fn $name ( $($arg : $arg_ty ),* ) $( -> $ret )?
$( where $( $w_name : $w_ty ),+ )?
{
#[allow(deprecated)]
<()>:: $name $(::< $( $g_name ),+ > )? ( $( $arg ),* )
<()>:: $name ( $( $arg ),* )
}
)*
}
@@ -160,26 +143,10 @@ export_api! {
fn storage_changes_root(parent_hash: [u8; 32]) -> Option<[u8; 32]>;
/// A trie root formed from the iterated items.
fn trie_root<H, I, A, B>(input: I) -> H::Out
where
I: IntoIterator<Item = (A, B)>,
A: AsRef<[u8]>,
A: Ord,
B: AsRef<[u8]>,
H: Hasher,
H: self::imp::HasherBounds,
H::Out: Ord
;
fn blake2_256_trie_root(input: Vec<(Vec<u8>, Vec<u8>)>) -> H256;
/// A trie root formed from the enumerated items.
fn ordered_trie_root<H, I, A>(input: I) -> H::Out
where
I: IntoIterator<Item = A>,
A: AsRef<[u8]>,
H: Hasher,
H: self::imp::HasherBounds,
H::Out: Ord
;
fn blake2_256_ordered_trie_root(input: Vec<Vec<u8>>) -> H256;
}
}
@@ -188,12 +155,12 @@ export_api! {
/// The current relay chain identifier.
fn chain_id() -> u64;
/// Print a printable value.
fn print<T>(value: T)
where
T: Printable,
T: Sized
;
/// Print a number.
fn print_num(val: u64);
/// Print any valid `utf8` buffer.
fn print_utf8(utf8: &[u8]);
/// Print any `u8` slice as hex.
fn print_hex(data: &[u8]);
}
}
@@ -209,10 +176,10 @@ export_api! {
/// key type in the keystore.
///
/// Returns the raw signature.
fn ed25519_sign<M: AsRef<[u8]>>(
fn ed25519_sign(
id: KeyTypeId,
pubkey: &ed25519::Public,
msg: &M,
msg: &[u8],
) -> Option<ed25519::Signature>;
/// Verify an ed25519 signature.
///
@@ -229,10 +196,10 @@ export_api! {
/// key type in the keystore.
///
/// Returns the raw signature.
fn sr25519_sign<M: AsRef<[u8]>>(
fn sr25519_sign(
id: KeyTypeId,
pubkey: &sr25519::Public,
msg: &M,
msg: &[u8],
) -> Option<sr25519::Signature>;
/// Verify an sr25519 signature.
///
@@ -315,7 +282,7 @@ export_api! {
kind: StorageKind,
key: &[u8],
old_value: Option<&[u8]>,
new_value: &[u8]
new_value: &[u8],
) -> bool;
/// Gets a value from the local storage.
@@ -332,14 +299,14 @@ export_api! {
fn http_request_start(
method: &str,
uri: &str,
meta: &[u8]
meta: &[u8],
) -> Result<HttpRequestId, ()>;
/// Append header to the request.
fn http_request_add_header(
request_id: HttpRequestId,
name: &str,
value: &str
value: &str,
) -> Result<(), ()>;
/// Write a chunk of request body.
@@ -351,7 +318,7 @@ export_api! {
fn http_request_write_body(
request_id: HttpRequestId,
chunk: &[u8],
deadline: Option<Timestamp>
deadline: Option<Timestamp>,
) -> Result<(), HttpError>;
/// Block and wait for the responses for given requests.
@@ -363,16 +330,14 @@ export_api! {
/// Passing `None` as deadline blocks forever.
fn http_response_wait(
ids: &[HttpRequestId],
deadline: Option<Timestamp>
deadline: Option<Timestamp>,
) -> Vec<HttpRequestStatus>;
/// Read all response headers.
///
/// Returns a vector of pairs `(HeaderKey, HeaderValue)`.
/// NOTE response headers have to be read before response body.
fn http_response_headers(
request_id: HttpRequestId
) -> Vec<(Vec<u8>, Vec<u8>)>;
fn http_response_headers(request_id: HttpRequestId) -> Vec<(Vec<u8>, Vec<u8>)>;
/// Read a chunk of body response to given buffer.
///
@@ -385,7 +350,7 @@ export_api! {
fn http_response_read_body(
request_id: HttpRequestId,
buffer: &mut [u8],
deadline: Option<Timestamp>
deadline: Option<Timestamp>,
) -> Result<usize, HttpError>;
}
}