Rearrange export structure to something a bit more convenient.

This commit is contained in:
Gav
2018-01-28 13:41:22 +01:00
parent 5b337e3a9c
commit daa77d09a6
42 changed files with 126 additions and 137 deletions
+3 -3
View File
@@ -558,7 +558,7 @@ dependencies = [
name = "native-runtime"
version = "0.1.0"
dependencies = [
"runtime-support 0.1.0",
"runtime-std 0.1.0",
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -737,7 +737,7 @@ dependencies = [
"polkadot-primitives 0.1.0",
"polkadot-serializer 0.1.0",
"polkadot-state-machine 0.1.0",
"runtime-support 0.1.0",
"runtime-std 0.1.0",
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -921,7 +921,7 @@ dependencies = [
]
[[package]]
name = "runtime-support"
name = "runtime-std"
version = "0.1.0"
dependencies = [
"environmental 0.1.0",
+1 -1
View File
@@ -14,7 +14,7 @@ parity-wasm = "0.15.0"
byteorder = "1.1"
rustc-hex = "1.0.0"
native-runtime = { path = "../native-runtime", version = "0.1" }
runtime-support = { path = "../native-runtime/support", version = "0.1" }
runtime-std = { path = "../native-runtime/std", version = "0.1" }
memcmp = { version = "0.0.6" }
[dev-dependencies]
+1 -1
View File
@@ -35,7 +35,7 @@ extern crate parity_wasm;
extern crate byteorder;
extern crate rustc_hex;
extern crate native_runtime;
extern crate runtime_support;
extern crate runtime_std;
extern crate memcmp;
#[macro_use]
+7 -8
View File
@@ -4,7 +4,7 @@ use state_machine::{Externalities, CodeExecutor};
use error::{Error, ErrorKind, Result};
use wasm_executor::WasmExecutor;
use native_runtime as runtime;
use runtime_support;
use runtime_std;
pub struct NativeExecutor;
@@ -22,7 +22,7 @@ impl CodeExecutor for NativeExecutor {
// get a proper build script, this must be strictly adhered to or things will go wrong.
let native_equivalent = include_bytes!("../../wasm-runtime/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm");
if code == &native_equivalent[..] {
runtime_support::with_externalities(ext, || match method {
runtime_std::with_externalities(ext, || match method {
"execute_block" => catch_unwind(|| runtime::execute_block(&data.0)).map_err(|_| ErrorKind::Runtime.into()),
"execute_transaction" => catch_unwind(|| runtime::execute_transaction(&data.0)).map_err(|_| ErrorKind::Runtime.into()),
_ => Err(ErrorKind::MethodNotFound(method.to_owned()).into()),
@@ -37,11 +37,10 @@ impl CodeExecutor for NativeExecutor {
#[cfg(test)]
mod tests {
use super::*;
use primitives::twox_128;
use native_runtime::testing::{TestExternalities, one, two};
use native_runtime::statichex::StaticHexInto;
use native_runtime::keyedvec::KeyedVec;
use native_runtime::codec::KeyedVec;
use native_runtime::support::{TestExternalities, one, two, StaticHexInto};
use native_runtime::runtime::staking::balance;
use primitives::twox_128;
fn tx() -> Vec<u8> { "679fcf0a846b4224c84ecad7d91a26241c46d00cb53d6480a363274e8965ee34b0b80b4b2e3836d3d8f8f12c0c1aef7350af587d9aee3883561d11726068ac0a2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000000228000000d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000".convert() }
@@ -82,7 +81,7 @@ mod tests {
let r = NativeExecutor.call(&mut t, &native_equivalent_code[..], "execute_transaction", &CallData(tx()));
assert!(r.is_ok());
runtime_support::with_externalities(&mut t, || {
runtime_std::with_externalities(&mut t, || {
assert_eq!(balance(&one), 42);
assert_eq!(balance(&two), 69);
});
@@ -101,7 +100,7 @@ mod tests {
let r = NativeExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &CallData(tx()));
assert!(r.is_ok());
runtime_support::with_externalities(&mut t, || {
runtime_std::with_externalities(&mut t, || {
assert_eq!(balance(&one), 42);
assert_eq!(balance(&two), 69);
});
+6 -10
View File
@@ -274,8 +274,11 @@ mod tests {
use super::*;
use rustc_hex::FromHex;
use native_runtime::testing::TestExternalities;
use primitives::hashing::blake2_256;
use primitives::{blake2_256, twox_128};
use runtime_std;
use native_runtime::support::{one, two, StaticHexInto, TestExternalities};
use native_runtime::codec::KeyedVec;
use native_runtime::runtime::staking::balance;
#[test]
fn returning_should_work() {
@@ -373,13 +376,6 @@ mod tests {
);
}
use primitives::twox_128;
use native_runtime::testing::{one, two};
use native_runtime::statichex::StaticHexInto;
use native_runtime::keyedvec::KeyedVec;
use native_runtime::runtime::staking::balance;
use runtime_support;
fn tx() -> Vec<u8> { "679fcf0a846b4224c84ecad7d91a26241c46d00cb53d6480a363274e8965ee34b0b80b4b2e3836d3d8f8f12c0c1aef7350af587d9aee3883561d11726068ac0a2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000000228000000d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000".convert() }
#[test]
@@ -407,7 +403,7 @@ mod tests {
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &CallData(tx()));
assert!(r.is_ok());
runtime_support::with_externalities(&mut t, || {
runtime_std::with_externalities(&mut t, || {
assert_eq!(balance(&one), 42);
assert_eq!(balance(&two), 69);
});
+1 -1
View File
@@ -9,5 +9,5 @@ with-std = []
without-std = []
[dependencies]
runtime-support = { path = "./support", version = "0.1" }
runtime-std = { path = "./std", version = "0.1" }
rustc-hex = "1.0"
@@ -1,5 +1,5 @@
[package]
name = "runtime-support"
name = "runtime-std"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
+3 -3
View File
@@ -13,11 +13,11 @@ version = "0.1.0"
name = "runtime-polkadot"
version = "0.1.0"
dependencies = [
"runtime-support 0.1.0",
"runtime-std 0.1.0",
]
[[package]]
name = "runtime-support"
name = "runtime-std"
version = "0.1.0"
dependencies = [
"pwasm-alloc 0.1.0",
@@ -28,6 +28,6 @@ dependencies = [
name = "runtime-test"
version = "0.1.0"
dependencies = [
"runtime-support 0.1.0",
"runtime-std 0.1.0",
]
+1 -1
View File
@@ -1,7 +1,7 @@
#!/bin/sh
cargo +nightly build --target=wasm32-unknown-unknown --release
dirs=`find * -maxdepth 0 -type d | grep -v pwasm- | grep -v support`
dirs=`find * -maxdepth 0 -type d | grep -v pwasm- | grep -v std`
for i in $dirs
do
if [[ -e $i/Cargo.toml ]]
+1 -1
View File
@@ -7,7 +7,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
crate-type = ["cdylib"]
[dependencies]
runtime-support = { path = "../support", version = "0.1" }
runtime-std = { path = "../std", version = "0.1" }
[features]
default = ["without-std"]
@@ -16,8 +16,8 @@
//! Vec<u8> serialiser.
use runtime_support::prelude::*;
use slicable::Slicable;
use runtime_std::prelude::*;
use super::slicable::Slicable;
/// Trait to allow itself to be serialised into a `Vec<u8>`
pub trait Joiner {
@@ -16,8 +16,8 @@
//! Serialiser and prepender.
use runtime_support::prelude::*;
use slicable::Slicable;
use runtime_std::prelude::*;
use super::slicable::Slicable;
/// Trait to allow itselg to be serialised and prepended by a given slice.
pub trait KeyedVec {
@@ -16,8 +16,14 @@
//! Codec utils.
pub mod endiansensitive;
pub mod streamreader;
pub mod joiner;
pub mod slicable;
pub mod keyedvec;
mod endiansensitive;
mod slicable;
mod streamreader;
mod joiner;
mod keyedvec;
pub use self::endiansensitive::EndianSensitive;
pub use self::slicable::{Slicable, NonTrivialSlicable};
pub use self::streamreader::StreamReader;
pub use self::joiner::Joiner;
pub use self::keyedvec::KeyedVec;
@@ -16,10 +16,10 @@
//! Serialisation.
use runtime_support::prelude::*;
use runtime_support::{mem, slice};
use joiner::Joiner;
use endiansensitive::EndianSensitive;
use runtime_std::prelude::*;
use runtime_std::{mem, slice};
use super::joiner::Joiner;
use super::endiansensitive::EndianSensitive;
/// Trait that allows zero-copy read/write of value-references to/from slices in LE format.
pub trait Slicable: Sized {
@@ -16,7 +16,7 @@
//! Deserialiser.
use slicable::Slicable;
use super::slicable::Slicable;
/// Simple deserialiser.
pub struct StreamReader<'a> {
+5 -9
View File
@@ -20,23 +20,19 @@
#![cfg_attr(feature = "strict", deny(warnings))]
#[macro_use]
extern crate runtime_support;
extern crate runtime_std;
#[cfg(feature = "with-std")]
extern crate rustc_hex;
mod codec;
pub mod codec;
#[macro_use]
mod support;
pub mod support;
pub mod primitives;
pub mod runtime;
pub use codec::{endiansensitive, streamreader, joiner, slicable, keyedvec};
pub use support::{environment, storable, hashable};
#[cfg(feature = "with-std")]
pub use support::{testing, statichex};
use runtime_support::prelude::*;
use slicable::Slicable;
use runtime_std::prelude::*;
use codec::Slicable;
use primitives::{Block, UncheckedTransaction};
/// Execute a block, with `input` being the canonical serialisation of the block. Returns the
@@ -16,10 +16,8 @@
//! Block type.
use runtime_support::prelude::*;
use streamreader::StreamReader;
use joiner::Joiner;
use slicable::{Slicable, NonTrivialSlicable};
use runtime_std::prelude::*;
use codec::{StreamReader, Joiner, Slicable, NonTrivialSlicable};
use primitives::{Header, UncheckedTransaction};
/// A Polkadot relay chain block.
@@ -16,7 +16,7 @@
//! Digest type.
use runtime_support::prelude::*;
use runtime_std::prelude::*;
#[derive(Clone, Default)]
#[cfg_attr(feature = "with-std", derive(PartialEq, Debug))]
@@ -17,7 +17,7 @@
//! Function data: This describes a function that can be called from an external transaction.
use primitives::AccountID;
use streamreader::StreamReader;
use codec::StreamReader;
use runtime::{staking, session, timestamp, governance};
/// Public functions that can be dispatched to.
@@ -16,11 +16,9 @@
//! Block header type.
use runtime_support::prelude::*;
use streamreader::StreamReader;
use joiner::Joiner;
use slicable::{Slicable, NonTrivialSlicable};
use runtime_support::mem;
use runtime_std::prelude::*;
use codec::{StreamReader, Joiner, Slicable, NonTrivialSlicable};
use runtime_std::mem;
use primitives::{BlockNumber, Hash, Digest};
#[derive(Clone)]
@@ -17,11 +17,9 @@
//! Proposal: This describes a combination of a function ID and data that can be used to call into
//! an internal function.
use runtime_support::prelude::*;
use runtime_support::mem;
use slicable::Slicable;
use joiner::Joiner;
use streamreader::StreamReader;
use runtime_std::prelude::*;
use runtime_std::mem;
use codec::{Slicable, Joiner, StreamReader};
use runtime::{system, governance, staking, session};
/// Internal functions that can be dispatched to.
@@ -17,10 +17,9 @@
//! Tests.
use super::*;
use runtime_support::prelude::*;
use joiner::Joiner;
use slicable::{Slicable, NonTrivialSlicable};
use function::Function;
use runtime_std::prelude::*;
use codec::{Joiner, Slicable};
use primitives::Function;
#[test]
fn serialise_transaction_works() {
@@ -16,12 +16,10 @@
//! Transaction type.
use runtime_support::prelude::*;
use streamreader::StreamReader;
use joiner::Joiner;
use slicable::{Slicable, NonTrivialSlicable};
use runtime_std::prelude::*;
use codec::{StreamReader, Joiner, Slicable, NonTrivialSlicable};
use primitives::{AccountID, TxOrder, Function};
use runtime_support::mem;
use runtime_std::mem;
/// A vetted and verified transaction from the external world.
#[cfg_attr(feature = "with-std", derive(PartialEq, Debug))]
@@ -16,12 +16,10 @@
//! Unchecked Transaction type.
use slicable::{Slicable, NonTrivialSlicable};
use streamreader::StreamReader;
use joiner::Joiner;
use runtime_std::{mem, ed25519_verify};
use runtime_std::prelude::*;
use codec::{Slicable, NonTrivialSlicable, StreamReader, Joiner};
use primitives::Transaction;
use runtime_support::{mem, ed25519_verify};
use runtime_support::prelude::*;
#[cfg(feature = "with-std")]
use std::fmt;
@@ -16,8 +16,8 @@
//! Conensus module for runtime; manages the authority set ready for the native code.
use runtime_support::prelude::*;
use storable::StorageVec;
use runtime_std::prelude::*;
use support::StorageVec;
use primitives::SessionKey;
struct AuthorityStorageVec {}
@@ -25,9 +25,9 @@
//! At the end of the era, all validators approvals are tallied and if there are sufficient to pass
//! the proposal then it is enacted. All items in storage concerning the proposal are reset.
use runtime_support::prelude::*;
use keyedvec::KeyedVec;
use storable::{Storable, StorageVec, kill};
use runtime_std::prelude::*;
use codec::KeyedVec;
use support::{Storable, StorageVec, kill};
use primitives::{AccountID, Hash, BlockNumber, Proposal};
use runtime::{staking, system, session};
@@ -105,7 +105,7 @@ pub fn end_of_an_era() {
#[cfg(test)]
mod tests {
use super::*;
use runtime_support::{with_externalities, twox_128};
use runtime_std::{with_externalities, twox_128};
use keyedvec::KeyedVec;
use joiner::Joiner;
use testing::{one, two, TestExternalities};
@@ -17,9 +17,9 @@
//! Session manager: is told the validators and allows them to manage their session keys for the
//! consensus module.
use runtime_support::prelude::*;
use keyedvec::KeyedVec;
use storable::{kill, Storable, StorageVec};
use runtime_std::prelude::*;
use codec::KeyedVec;
use support::{kill, Storable, StorageVec};
use primitives::{AccountID, SessionKey, BlockNumber};
use runtime::{system, staking, consensus};
@@ -118,7 +118,7 @@ fn rotate_session() {
#[cfg(test)]
mod tests {
use runtime_support::{with_externalities, twox_128};
use runtime_std::{with_externalities, twox_128};
use keyedvec::KeyedVec;
use joiner::Joiner;
use testing::{one, two, TestExternalities};
@@ -16,10 +16,10 @@
//! Staking manager: Handles balances and periodically determines the best set of validators.
use runtime_support::prelude::*;
use runtime_support::cell::RefCell;
use keyedvec::KeyedVec;
use storable::{Storable, StorageVec};
use runtime_std::prelude::*;
use runtime_std::cell::RefCell;
use codec::KeyedVec;
use support::{Storable, StorageVec};
use primitives::{BlockNumber, AccountID};
use runtime::{system, session, governance};
@@ -190,7 +190,7 @@ fn new_era() {
#[cfg(test)]
mod tests {
use runtime_support::{with_externalities, twox_128};
use runtime_std::{with_externalities, twox_128};
use keyedvec::KeyedVec;
use joiner::Joiner;
use testing::{one, two, TestExternalities};
@@ -17,14 +17,11 @@
//! System manager: Handles all of the top-level stuff; executing block/transaction, setting code
//! and depositing logs.
use runtime_std::prelude::*;
use runtime_std::{mem, print};
use codec::KeyedVec;
use support::{Hashable, Storable, with_env};
use primitives::{Block, BlockNumber, Hash, UncheckedTransaction, TxOrder};
use runtime_support::mem;
use runtime_support::prelude::*;
use runtime_support::print;
use hashable::Hashable;
use storable::Storable;
use keyedvec::KeyedVec;
use environment::with_env;
use runtime::{staking, session};
/// The current block number being processed. Set by `execute_block`.
@@ -120,7 +117,7 @@ mod tests {
use function::Function;
use keyedvec::KeyedVec;
use slicable::Slicable;
use runtime_support::{with_externalities, twox_128};
use runtime_std::{with_externalities, twox_128};
use primitives::{UncheckedTransaction, Transaction};
use statichex::StaticHexInto;
use runtime::{system, staking};
@@ -16,7 +16,7 @@
//! Timestamp manager: just handles the current timestamp.
use storable::Storable;
use support::Storable;
/// Representation of a time.
pub type Timestamp = u64;
@@ -35,7 +35,7 @@ pub fn set(now: Timestamp) {
mod tests {
use joiner::Joiner;
use keyedvec::KeyedVec;
use runtime_support::{with_externalities, twox_128};
use runtime_std::{with_externalities, twox_128};
use runtime::timestamp;
use testing::TestExternalities;
@@ -16,10 +16,10 @@
//! Environment API: Allows certain information to be accessed throughout the runtime.
use runtime_support::boxed::Box;
use runtime_support::mem;
use runtime_support::cell::RefCell;
use runtime_support::rc::Rc;
use runtime_std::boxed::Box;
use runtime_std::mem;
use runtime_std::cell::RefCell;
use runtime_std::rc::Rc;
use primitives::{BlockNumber, Digest};
@@ -16,8 +16,8 @@
//! Hashable trait.
use slicable::Slicable;
use runtime_support::{blake2_256, twox_128, twox_256};
use codec::Slicable;
use runtime_std::{blake2_256, twox_128, twox_256};
pub trait Hashable: Sized {
fn blake2_256(&self) -> [u8; 32];
@@ -16,12 +16,19 @@
//! Support code for the runtime.
pub mod environment;
pub mod storable;
pub mod hashable;
mod environment;
mod storable;
mod hashable;
#[cfg(feature = "with-std")]
pub mod statichex;
mod statichex;
#[macro_use]
#[cfg(feature = "with-std")]
pub mod testing;
mod testing;
pub use self::environment::{Environment, with_env};
pub use self::storable::{StorageVec, Storable, kill};
pub use self::hashable::Hashable;
#[cfg(feature = "with-std")]
pub use self::statichex::{StaticHexConversion, StaticHexInto};
#[cfg(feature = "with-std")]
pub use self::testing::{AsBytesRef, HexDisplay, TestExternalities, one, two};
@@ -16,10 +16,9 @@
//! Stuff to do with the runtime's storage.
use slicable::Slicable;
use keyedvec::KeyedVec;
use runtime_support::prelude::*;
use runtime_support::{self, twox_128};
use runtime_std::prelude::*;
use runtime_std::{self, twox_128};
use codec::{Slicable, KeyedVec};
/// Trait for a value which may be stored in the storage DB.
pub trait Storable {
@@ -51,23 +50,23 @@ pub trait Storable {
/// Remove `key` from storage.
pub fn kill(key: &[u8]) {
runtime_support::set_storage(&twox_128(key)[..], b"");
runtime_std::set_storage(&twox_128(key)[..], b"");
}
impl<T: Sized + Slicable> Storable for T {
fn lookup(key: &[u8]) -> Option<Self> {
Slicable::set_as_slice(&|out, offset|
runtime_support::read_storage(&twox_128(key)[..], out, offset) >= out.len()
runtime_std::read_storage(&twox_128(key)[..], out, offset) >= out.len()
)
}
fn store(&self, key: &[u8]) {
self.as_slice_then(|slice| runtime_support::set_storage(&twox_128(key)[..], slice));
self.as_slice_then(|slice| runtime_std::set_storage(&twox_128(key)[..], slice));
}
}
impl Storable for [u8] {
fn store(&self, key: &[u8]) {
runtime_support::set_storage(&twox_128(key)[..], self)
runtime_std::set_storage(&twox_128(key)[..], self)
}
}
@@ -110,9 +109,9 @@ pub trait StorageVec {
mod tests {
use super::*;
use std::collections::HashMap;
use runtime_support::with_externalities;
use runtime_std::with_externalities;
use testing::{TestExternalities, HexDisplay};
use runtime_support::{storage, twox_128};
use runtime_std::{storage, twox_128};
#[test]
fn integers_can_be_stored() {
@@ -153,7 +152,7 @@ mod tests {
fn vecs_can_be_retrieved() {
let mut t = TestExternalities { storage: HashMap::new(), };
with_externalities(&mut t, || {
runtime_support::set_storage(&twox_128(b":test"), b"\x0b\0\0\0Hello world");
runtime_std::set_storage(&twox_128(b":test"), b"\x0b\0\0\0Hello world");
let x = b"Hello world".to_vec();
println!("Hex: {}", HexDisplay::from(&storage(&twox_128(b":test"))));
let y = <Vec<u8>>::lookup(b":test").unwrap();
@@ -16,10 +16,10 @@
//! Testing helpers.
use runtime_support::{Externalities, ExternalitiesError};
use std::collections::HashMap;
use runtime_std::{Externalities, ExternalitiesError};
use primitives::AccountID;
use statichex::StaticHexInto;
use super::statichex::StaticHexInto;
#[derive(Debug, Default)]
/// Simple externaties implementation.
@@ -1,5 +1,5 @@
[package]
name = "runtime-support"
name = "runtime-std"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
+1 -1
View File
@@ -7,4 +7,4 @@ authors = ["Parity Technologies <admin@parity.io>"]
crate-type = ["cdylib"]
[dependencies]
runtime-support = { path = "../support", version = "0.1" }
runtime-std = { path = "../std", version = "0.1" }
+2 -2
View File
@@ -7,8 +7,8 @@ extern crate alloc;
use alloc::vec::Vec;
#[macro_use]
extern crate runtime_support;
use runtime_support::{set_storage, storage, print, blake2_256, twox_128, twox_256, ed25519_verify};
extern crate runtime_std;
use runtime_std::{set_storage, storage, print, blake2_256, twox_128, twox_256, ed25519_verify};
fn test_blake2_256(input: &[u8]) -> Vec<u8> {
blake2_256(&input).to_vec()