[big refactor] Remove crate aliasing. (#4395)

* Rename: Phase 1.

* Unify codec.

* Fixing: Phase 2

* Fixing: Phase 3.

* Fixing: Phase 4.

* Fixing: Phase 5.

* Fixing: Phase 6.

* Fixing: Phase 7.

* Fixing: Phase 8. Tests

* Fixing: Phase 9. Tests!!!

* Fixing: Phase 10. Moar tests!

* Finally done!

* More fixes.

* Rename primitives:: to sp_core::

* Apply renames in finality-grandpa.

* Fix benches.

* Fix benches 2.

* Revert node-template.

* Fix frame-system in our modules.
This commit is contained in:
Tomasz Drwięga
2019-12-16 13:36:49 +01:00
committed by Gavin Wood
parent f14d98a439
commit 8778ca7dc8
485 changed files with 4023 additions and 4005 deletions
@@ -16,9 +16,9 @@ use sp_io::{
#[cfg(not(feature = "std"))]
use sp_runtime::{print, traits::{BlakeTwo256, Hash}};
#[cfg(not(feature = "std"))]
use primitives::{ed25519, sr25519};
use sp_core::{ed25519, sr25519};
primitives::wasm_export_functions! {
sp_core::wasm_export_functions! {
fn test_data_in(input: Vec<u8>) -> Vec<u8> {
print("set_storage");
storage::set(b"input", &input);
@@ -112,8 +112,8 @@ primitives::wasm_export_functions! {
execute_sandboxed(
&code,
&[
sandbox::TypedValue::I32(0x12345678),
sandbox::TypedValue::I64(0x1234567887654321),
sp_sandbox::TypedValue::I32(0x12345678),
sp_sandbox::TypedValue::I64(0x1234567887654321),
],
).is_ok()
}
@@ -122,10 +122,10 @@ primitives::wasm_export_functions! {
let ok = match execute_sandboxed(
&code,
&[
sandbox::TypedValue::I32(0x1336),
sp_sandbox::TypedValue::I32(0x1336),
]
) {
Ok(sandbox::ReturnValue::Value(sandbox::TypedValue::I32(0x1337))) => true,
Ok(sp_sandbox::ReturnValue::Value(sp_sandbox::TypedValue::I32(0x1337))) => true,
_ => false,
};
@@ -133,19 +133,19 @@ primitives::wasm_export_functions! {
}
fn test_sandbox_instantiate(code: Vec<u8>) -> u8 {
let env_builder = sandbox::EnvironmentDefinitionBuilder::new();
let code = match sandbox::Instance::new(&code, &env_builder, &mut ()) {
let env_builder = sp_sandbox::EnvironmentDefinitionBuilder::new();
let code = match sp_sandbox::Instance::new(&code, &env_builder, &mut ()) {
Ok(_) => 0,
Err(sandbox::Error::Module) => 1,
Err(sandbox::Error::Execution) => 2,
Err(sandbox::Error::OutOfBounds) => 3,
Err(sp_sandbox::Error::Module) => 1,
Err(sp_sandbox::Error::Execution) => 2,
Err(sp_sandbox::Error::OutOfBounds) => 3,
};
code
}
fn test_offchain_local_storage() -> bool {
let kind = primitives::offchain::StorageKind::PERSISTENT;
let kind = sp_core::offchain::StorageKind::PERSISTENT;
assert_eq!(sp_io::offchain::local_storage_get(kind, b"test"), None);
sp_io::offchain::local_storage_set(kind, b"test", b"asd");
assert_eq!(sp_io::offchain::local_storage_get(kind, b"test"), Some(b"asd".to_vec()));
@@ -161,7 +161,7 @@ primitives::wasm_export_functions! {
}
fn test_offchain_local_storage_with_none() {
let kind = primitives::offchain::StorageKind::PERSISTENT;
let kind = sp_core::offchain::StorageKind::PERSISTENT;
assert_eq!(sp_io::offchain::local_storage_get(kind, b"test"), None);
let res = sp_io::offchain::local_storage_compare_and_set(kind, b"test", None, b"value");
@@ -170,7 +170,7 @@ primitives::wasm_export_functions! {
}
fn test_offchain_http() -> bool {
use primitives::offchain::HttpRequestStatus;
use sp_core::offchain::HttpRequestStatus;
let run = || -> Option<()> {
let id = sp_io::offchain::http_request_start(
"POST",
@@ -201,45 +201,45 @@ primitives::wasm_export_functions! {
#[cfg(not(feature = "std"))]
fn execute_sandboxed(
code: &[u8],
args: &[sandbox::TypedValue],
) -> Result<sandbox::ReturnValue, sandbox::HostError> {
args: &[sp_sandbox::TypedValue],
) -> Result<sp_sandbox::ReturnValue, sp_sandbox::HostError> {
struct State {
counter: u32,
}
fn env_assert(
_e: &mut State,
args: &[sandbox::TypedValue],
) -> Result<sandbox::ReturnValue, sandbox::HostError> {
args: &[sp_sandbox::TypedValue],
) -> Result<sp_sandbox::ReturnValue, sp_sandbox::HostError> {
if args.len() != 1 {
return Err(sandbox::HostError);
return Err(sp_sandbox::HostError);
}
let condition = args[0].as_i32().ok_or_else(|| sandbox::HostError)?;
let condition = args[0].as_i32().ok_or_else(|| sp_sandbox::HostError)?;
if condition != 0 {
Ok(sandbox::ReturnValue::Unit)
Ok(sp_sandbox::ReturnValue::Unit)
} else {
Err(sandbox::HostError)
Err(sp_sandbox::HostError)
}
}
fn env_inc_counter(
e: &mut State,
args: &[sandbox::TypedValue],
) -> Result<sandbox::ReturnValue, sandbox::HostError> {
args: &[sp_sandbox::TypedValue],
) -> Result<sp_sandbox::ReturnValue, sp_sandbox::HostError> {
if args.len() != 1 {
return Err(sandbox::HostError);
return Err(sp_sandbox::HostError);
}
let inc_by = args[0].as_i32().ok_or_else(|| sandbox::HostError)?;
let inc_by = args[0].as_i32().ok_or_else(|| sp_sandbox::HostError)?;
e.counter += inc_by as u32;
Ok(sandbox::ReturnValue::Value(sandbox::TypedValue::I32(e.counter as i32)))
Ok(sp_sandbox::ReturnValue::Value(sp_sandbox::TypedValue::I32(e.counter as i32)))
}
let mut state = State { counter: 0 };
let env_builder = {
let mut env_builder = sandbox::EnvironmentDefinitionBuilder::new();
let mut env_builder = sp_sandbox::EnvironmentDefinitionBuilder::new();
env_builder.add_host_func("env", "assert", env_assert);
env_builder.add_host_func("env", "inc_counter", env_inc_counter);
let memory = match sandbox::Memory::new(1, Some(16)) {
let memory = match sp_sandbox::Memory::new(1, Some(16)) {
Ok(m) => m,
Err(_) => unreachable!("
Memory::new() can return Err only if parameters are borked; \
@@ -251,8 +251,8 @@ fn execute_sandboxed(
env_builder
};
let mut instance = sandbox::Instance::new(code, &env_builder, &mut state)?;
let mut instance = sp_sandbox::Instance::new(code, &env_builder, &mut state)?;
let result = instance.invoke("call", args, &mut state);
result.map_err(|_| sandbox::HostError)
result.map_err(|_| sp_sandbox::HostError)
}