From e6839d2d4137150fdecaca6b0219c2a78cb036cb Mon Sep 17 00:00:00 2001
From: Stanislav Tkach <stanislav.tkach@gmail.com>
Date: Tue, 29 Jan 2019 15:30:07 +0200
Subject: [PATCH] Migrate executor, xinherens, keyring and keystore to 2018
 edition (#1585)

---
 substrate/core/executor/Cargo.toml            | 13 +++----
 substrate/core/executor/src/error.rs          |  2 ++
 substrate/core/executor/src/heap.rs           |  1 +
 substrate/core/executor/src/lib.rs            | 34 ++-----------------
 .../core/executor/src/native_executor.rs      |  9 ++---
 substrate/core/executor/src/sandbox.rs        |  6 ++--
 substrate/core/executor/src/wasm_executor.rs  | 15 ++++----
 substrate/core/executor/wasm/Cargo.toml       |  5 +--
 substrate/core/executor/wasm/src/lib.rs       |  4 ---
 substrate/core/inherents/src/lib.rs           |  3 +-
 substrate/core/keyring/Cargo.toml             |  1 +
 substrate/core/keyring/src/lib.rs             |  6 ++--
 substrate/core/keystore/Cargo.toml            |  3 +-
 substrate/core/keystore/src/lib.rs            | 20 +++--------
 14 files changed, 42 insertions(+), 80 deletions(-)

diff --git a/substrate/core/executor/Cargo.toml b/substrate/core/executor/Cargo.toml
index 9b88c2f7bb2..d0e120c9faa 100644
--- a/substrate/core/executor/Cargo.toml
+++ b/substrate/core/executor/Cargo.toml
@@ -2,16 +2,17 @@
 name = "substrate-executor"
 version = "0.1.0"
 authors = ["Parity Technologies <admin@parity.io>"]
+edition = "2018"
 
 [dependencies]
 error-chain = "0.12"
 parity-codec = "3.0"
-sr-io = { path = "../sr-io" }
-substrate-primitives = { path = "../primitives" }
-substrate-trie = { path = "../trie" }
-substrate-serializer = { path = "../serializer" }
-substrate-state-machine = { path = "../state-machine"  }
-sr-version = { path = "../sr-version" }
+runtime_io = { package = "sr-io", path = "../sr-io" }
+primitives = { package = "substrate-primitives", path = "../primitives" }
+trie = { package = "substrate-trie", path = "../trie" }
+serializer = { package = "substrate-serializer", path = "../serializer" }
+state_machine = { package = "substrate-state-machine", path = "../state-machine"  }
+runtime_version = { package = "sr-version", path = "../sr-version" }
 serde = "1.0"
 serde_derive = "1.0"
 wasmi = { version = "0.4.3" }
diff --git a/substrate/core/executor/src/error.rs b/substrate/core/executor/src/error.rs
index 2a5690d9f65..c5a6160ac12 100644
--- a/substrate/core/executor/src/error.rs
+++ b/substrate/core/executor/src/error.rs
@@ -23,6 +23,8 @@
 use state_machine;
 use serializer;
 use wasmi;
+use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed,
+	impl_extract_backtrace, impl_error_chain_kind};
 
 error_chain! {
 	foreign_links {
diff --git a/substrate/core/executor/src/heap.rs b/substrate/core/executor/src/heap.rs
index da7aae22eef..708c81b3598 100644
--- a/substrate/core/executor/src/heap.rs
+++ b/substrate/core/executor/src/heap.rs
@@ -21,6 +21,7 @@
 extern crate fnv;
 
 use std::vec;
+use log::trace;
 use self::fnv::FnvHashMap;
 
 // The pointers need to be aligned to 8 bytes.
diff --git a/substrate/core/executor/src/lib.rs b/substrate/core/executor/src/lib.rs
index ddc98289164..a42b5a041d3 100644
--- a/substrate/core/executor/src/lib.rs
+++ b/substrate/core/executor/src/lib.rs
@@ -28,37 +28,6 @@
 #![warn(missing_docs)]
 #![recursion_limit="128"]
 
-extern crate tiny_keccak;
-extern crate secp256k1;
-extern crate parity_codec as codec;
-extern crate sr_io as runtime_io;
-#[cfg_attr(test, macro_use)]
-extern crate substrate_primitives as primitives;
-extern crate substrate_serializer as serializer;
-extern crate substrate_state_machine as state_machine;
-extern crate sr_version as runtime_version;
-extern crate substrate_trie as trie;
-
-extern crate wasmi;
-extern crate byteorder;
-extern crate parking_lot;
-
-#[macro_use]
-extern crate log;
-
-#[macro_use]
-extern crate error_chain;
-
-#[cfg(test)]
-extern crate assert_matches;
-
-#[cfg(test)]
-extern crate wabt;
-
-#[cfg(test)]
-#[macro_use]
-extern crate hex_literal;
-
 #[macro_use]
 mod wasm_utils;
 mod wasm_executor;
@@ -68,11 +37,12 @@ mod sandbox;
 mod heap;
 
 pub mod error;
+pub use wasmi;
 pub use wasm_executor::WasmExecutor;
 pub use native_executor::{with_native_environment, NativeExecutor, NativeExecutionDispatch};
 pub use state_machine::Externalities;
 pub use runtime_version::{RuntimeVersion, NativeVersion};
-pub use codec::Codec;
+pub use parity_codec::Codec;
 use primitives::Blake2Hasher;
 
 /// Provides runtime information.
diff --git a/substrate/core/executor/src/native_executor.rs b/substrate/core/executor/src/native_executor.rs
index fcba9c59147..d6de933c7fd 100644
--- a/substrate/core/executor/src/native_executor.rs
+++ b/substrate/core/executor/src/native_executor.rs
@@ -16,16 +16,17 @@
 
 use std::borrow::BorrowMut;
 use std::cell::{RefMut, RefCell};
-use error::{Error, ErrorKind, Result};
+use crate::error::{Error, ErrorKind, Result};
 use state_machine::{CodeExecutor, Externalities};
-use wasm_executor::WasmExecutor;
+use crate::wasm_executor::WasmExecutor;
 use wasmi::{Module as WasmModule, ModuleRef as WasmModuleInstanceRef};
 use runtime_version::{NativeVersion, RuntimeVersion};
 use std::{collections::HashMap, panic::UnwindSafe};
-use codec::{Decode, Encode};
-use RuntimeInfo;
+use parity_codec::{Decode, Encode};
+use crate::RuntimeInfo;
 use primitives::{Blake2Hasher, NativeOrEncoded};
 use primitives::storage::well_known_keys;
+use log::trace;
 
 /// Default num of pages for the heap
 const DEFAULT_HEAP_PAGES: u64 = 1024;
diff --git a/substrate/core/executor/src/sandbox.rs b/substrate/core/executor/src/sandbox.rs
index 87fb4083b38..b744920b6ed 100644
--- a/substrate/core/executor/src/sandbox.rs
+++ b/substrate/core/executor/src/sandbox.rs
@@ -20,9 +20,9 @@
 
 use std::collections::HashMap;
 use std::rc::Rc;
-use codec::{Decode, Encode};
+use parity_codec::{Decode, Encode};
 use primitives::sandbox as sandbox_primitives;
-use wasm_utils::UserError;
+use crate::wasm_utils::UserError;
 use wasmi;
 use wasmi::memory_units::Pages;
 use wasmi::{
@@ -558,7 +558,7 @@ impl Store {
 #[cfg(test)]
 mod tests {
 	use primitives::{Blake2Hasher};
-	use wasm_executor::WasmExecutor;
+	use crate::wasm_executor::WasmExecutor;
 	use state_machine::TestExternalities;
 	use wabt;
 
diff --git a/substrate/core/executor/src/wasm_executor.rs b/substrate/core/executor/src/wasm_executor.rs
index 7776c83f61d..a08f828d050 100644
--- a/substrate/core/executor/src/wasm_executor.rs
+++ b/substrate/core/executor/src/wasm_executor.rs
@@ -26,15 +26,16 @@ use wasmi::{
 use wasmi::RuntimeValue::{I32, I64};
 use wasmi::memory_units::{Bytes, Pages};
 use state_machine::Externalities;
-use error::{Error, ErrorKind, Result};
-use wasm_utils::UserError;
+use crate::error::{Error, ErrorKind, Result};
+use crate::wasm_utils::UserError;
 use primitives::{blake2_256, twox_128, twox_256, ed25519};
 use primitives::hexdisplay::HexDisplay;
 use primitives::sandbox as sandbox_primitives;
 use primitives::{H256, Blake2Hasher};
 use trie::ordered_trie_root;
-use sandbox;
-use heap;
+use crate::sandbox;
+use crate::heap;
+use log::trace;
 
 #[cfg(feature="wasm-extern-trace")]
 macro_rules! debug_trace {
@@ -547,7 +548,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
 		Ok(())
 	},
 	ext_sandbox_invoke(instance_idx: u32, export_ptr: *const u8, export_len: usize, args_ptr: *const u8, args_len: usize, return_val_ptr: *const u8, return_val_len: usize, state: usize) -> u32 => {
-		use codec::{Decode, Encode};
+		use parity_codec::{Decode, Encode};
 
 		trace!(target: "sr-sandbox", "invoke, instance_idx={}", instance_idx);
 		let export = this.memory.get(export_ptr, export_len as usize)
@@ -751,8 +752,10 @@ impl WasmExecutor {
 #[cfg(test)]
 mod tests {
 	use super::*;
-	use codec::Encode;
+	use parity_codec::Encode;
 	use state_machine::TestExternalities;
+	use hex_literal::{hex, hex_impl};
+	use primitives::map;
 
 	#[test]
 	fn returning_should_work() {
diff --git a/substrate/core/executor/wasm/Cargo.toml b/substrate/core/executor/wasm/Cargo.toml
index 091945e3064..9683cd764ee 100644
--- a/substrate/core/executor/wasm/Cargo.toml
+++ b/substrate/core/executor/wasm/Cargo.toml
@@ -2,13 +2,14 @@
 name = "runtime-test"
 version = "0.1.0"
 authors = ["Parity Technologies <admin@parity.io>"]
+edition = "2018"
 
 [lib]
 crate-type = ["cdylib"]
 
 [dependencies]
-sr-io = { path = "../../sr-io", version = "0.1", default-features = false }
-sr-sandbox = { path = "../../sr-sandbox", version = "0.1", default-features = false }
+runtime_io = { package = "sr-io", path = "../../sr-io", version = "0.1", default-features = false }
+sandbox = { package = "sr-sandbox", path = "../../sr-sandbox", version = "0.1", default-features = false }
 substrate-primitives = { path = "../../primitives", default-features = false }
 
 [profile.release]
diff --git a/substrate/core/executor/wasm/src/lib.rs b/substrate/core/executor/wasm/src/lib.rs
index b85ecafa5a8..2ede6f7010d 100644
--- a/substrate/core/executor/wasm/src/lib.rs
+++ b/substrate/core/executor/wasm/src/lib.rs
@@ -6,10 +6,6 @@ extern crate alloc;
 use alloc::vec::Vec;
 use alloc::slice;
 
-extern crate sr_io as runtime_io;
-extern crate sr_sandbox as sandbox;
-extern crate substrate_primitives;
-
 use runtime_io::{
 	set_storage, storage, clear_prefix, print, blake2_256,
 	twox_128, twox_256, ed25519_verify, enumerated_trie_root
diff --git a/substrate/core/inherents/src/lib.rs b/substrate/core/inherents/src/lib.rs
index 14b213b51d5..becd99e4816 100644
--- a/substrate/core/inherents/src/lib.rs
+++ b/substrate/core/inherents/src/lib.rs
@@ -32,8 +32,7 @@
 
 #![cfg_attr(not(feature = "std"), no_std)]
 
-extern crate parity_codec as codec;
-
+use parity_codec as codec;
 use parity_codec_derive::{Encode, Decode};
 
 use rstd::{collections::btree_map::{BTreeMap, IntoIter, Entry}, vec::Vec};
diff --git a/substrate/core/keyring/Cargo.toml b/substrate/core/keyring/Cargo.toml
index 04d6c2bd134..e3203742473 100644
--- a/substrate/core/keyring/Cargo.toml
+++ b/substrate/core/keyring/Cargo.toml
@@ -2,6 +2,7 @@
 name = "substrate-keyring"
 version = "0.1.0"
 authors = ["Parity Technologies <admin@parity.io>"]
+edition = "2018"
 
 [dependencies]
 substrate-primitives = { path = "../primitives" }
diff --git a/substrate/core/keyring/src/lib.rs b/substrate/core/keyring/src/lib.rs
index d2970c54c6b..267da3995cd 100644
--- a/substrate/core/keyring/src/lib.rs
+++ b/substrate/core/keyring/src/lib.rs
@@ -16,12 +16,10 @@
 
 //! Support code for the runtime. A set of test accounts.
 
-#[macro_use] extern crate hex_literal;
-#[macro_use] extern crate lazy_static;
-extern crate substrate_primitives;
-
 use std::collections::HashMap;
 use std::ops::Deref;
+use lazy_static::lazy_static;
+use hex_literal::{hex, hex_impl};
 use substrate_primitives::ed25519::{Pair, Public, Signature};
 pub use substrate_primitives::ed25519;
 
diff --git a/substrate/core/keystore/Cargo.toml b/substrate/core/keystore/Cargo.toml
index 332d22000ba..d5dd0cbca9b 100644
--- a/substrate/core/keystore/Cargo.toml
+++ b/substrate/core/keystore/Cargo.toml
@@ -2,10 +2,11 @@
 name = "substrate-keystore"
 version = "0.1.0"
 authors = ["Parity Technologies <admin@parity.io>"]
+edition = "2018"
 
 [dependencies]
 substrate-primitives = { path = "../primitives" }
-parity-crypto = { version = "0.2", default-features = false }
+crypto = { package = "parity-crypto", version = "0.2", default-features = false }
 error-chain = "0.12"
 hex = "0.3"
 rand = "0.6"
diff --git a/substrate/core/keystore/src/lib.rs b/substrate/core/keystore/src/lib.rs
index 130835f6bb4..56e1ae62e8e 100644
--- a/substrate/core/keystore/src/lib.rs
+++ b/substrate/core/keystore/src/lib.rs
@@ -20,27 +20,15 @@
 // https://github.com/paritytech/substrate/issues/1547
 #![allow(deprecated)]
 
-extern crate substrate_primitives;
-extern crate parity_crypto as crypto;
-extern crate subtle;
-extern crate rand;
-extern crate serde_json;
-extern crate hex;
-
-#[macro_use]
-extern crate serde_derive;
-
-#[macro_use]
-extern crate error_chain;
-
-#[cfg(test)]
-extern crate tempdir;
-
 use std::collections::HashMap;
 use std::path::PathBuf;
 use std::fs::{self, File};
 use std::io::{self, Write};
 
+use serde_derive::{Serialize, Deserialize};
+use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed,
+	impl_extract_backtrace, impl_error_chain_kind};
+
 use substrate_primitives::{hashing::blake2_256, ed25519::{Pair, Public, PKCS_LEN}};
 
 pub use crypto::KEY_ITERATIONS;
-- 
GitLab