Update to parity-scale-codec (#3232)

* WIP: update codec

* WIP

* compiling

* WIP

* rename parity-scale-codec to codec

* WIP

* fix

* remove old comments

* use published crates

* fix expected error msg

* bump version

* fmt and fix

* remove old comment

* fix wrong decoding impl

* implement encode like for structures

* undo removal of old pending changes

* trailingzeroinput

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* update codec

* fmt

* version is 1.0.0

* show more error

* fmt
This commit is contained in:
thiolliere
2019-08-06 19:36:23 +02:00
committed by Bastian Köcher
parent a0d442333f
commit 4ed67e03a4
211 changed files with 867 additions and 682 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ pub use native_executor::{with_native_environment, NativeExecutor, NativeExecuti
pub use wasm_runtimes_cache::RuntimesCache;
pub use state_machine::Externalities;
pub use runtime_version::{RuntimeVersion, NativeVersion};
pub use parity_codec::Codec;
pub use codec::Codec;
#[doc(hidden)]
pub use primitives::Blake2Hasher;
@@ -19,7 +19,7 @@ use crate::error::{Error, Result};
use state_machine::{CodeExecutor, Externalities};
use crate::wasm_executor::WasmExecutor;
use runtime_version::{NativeVersion, RuntimeVersion};
use parity_codec::{Decode, Encode};
use codec::{Decode, Encode};
use crate::RuntimeInfo;
use primitives::{Blake2Hasher, NativeOrEncoded};
use log::trace;
+3 -3
View File
@@ -20,7 +20,7 @@
use crate::error::{Result, Error};
use std::{collections::HashMap, rc::Rc};
use parity_codec::{Decode, Encode};
use codec::{Decode, Encode};
use primitives::sandbox as sandbox_primitives;
use wasmi::{
Externals, FuncRef, ImportResolver, MemoryInstance, MemoryRef, Module, ModuleInstance,
@@ -193,7 +193,7 @@ fn trap(msg: &'static str) -> Trap {
fn deserialize_result(serialized_result: &[u8]) -> std::result::Result<Option<RuntimeValue>, Trap> {
use self::sandbox_primitives::{HostError, ReturnValue};
let result_val = std::result::Result::<ReturnValue, HostError>::decode(&mut &serialized_result[..])
.ok_or_else(|| trap("Decoding Result<ReturnValue, HostError> failed!"))?;
.map_err(|_| trap("Decoding Result<ReturnValue, HostError> failed!"))?;
match result_val {
Ok(return_value) => Ok(match return_value {
@@ -361,7 +361,7 @@ fn decode_environment_definition(
memories: &[Option<MemoryRef>],
) -> std::result::Result<(Imports, GuestToSupervisorFunctionMapping), InstantiationError> {
let env_def = sandbox_primitives::EnvironmentDefinition::decode(&mut &raw_env_def[..])
.ok_or_else(|| InstantiationError::EnvironmentDefinitionCorrupted)?;
.map_err(|_| InstantiationError::EnvironmentDefinitionCorrupted)?;
let mut func_map = HashMap::new();
let mut memories_map = HashMap::new();
+5 -5
View File
@@ -26,7 +26,7 @@ use wasmi::{
};
use state_machine::{Externalities, ChildStorageKey};
use crate::error::{Error, Result};
use parity_codec::Encode;
use codec::Encode;
use primitives::{blake2_128, blake2_256, twox_64, twox_128, twox_256, ed25519, sr25519, Pair};
use primitives::offchain;
use primitives::hexdisplay::HexDisplay;
@@ -1081,7 +1081,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
request_id: u32,
written_out: *mut u32
) -> *mut u8 => {
use parity_codec::Encode;
use codec::Encode;
let headers = this.ext.offchain()
.map(|api| api.http_response_headers(offchain::HttpRequestId(request_id as u16)))
@@ -1172,7 +1172,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
return_val_len: usize,
state: usize
) -> u32 => {
use parity_codec::{Decode, Encode};
use codec::{Decode, Encode};
trace!(target: "sr-sandbox", "invoke, instance_idx={}", instance_idx);
let export = this.memory.get(export_ptr, export_len as usize)
@@ -1186,7 +1186,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
let serialized_args = this.memory.get(args_ptr, args_len as usize)
.map_err(|_| "OOB while ext_sandbox_invoke: args")?;
let args = Vec::<sandbox_primitives::TypedValue>::decode(&mut &serialized_args[..])
.ok_or_else(|| "Can't decode serialized arguments for the invocation")?
.map_err(|_| "Can't decode serialized arguments for the invocation")?
.into_iter()
.map(Into::into)
.collect::<Vec<_>>();
@@ -1443,7 +1443,7 @@ impl WasmExecutor {
mod tests {
use super::*;
use parity_codec::Encode;
use codec::Encode;
use state_machine::TestExternalities as CoreTestExternalities;
use hex_literal::hex;
@@ -19,7 +19,7 @@
use crate::error::Error;
use crate::wasm_executor::WasmExecutor;
use log::{trace, warn};
use parity_codec::Decode;
use codec::Decode;
use parity_wasm::elements::{deserialize_buffer, DataSegment, Instruction, Module as RawModule};
use primitives::storage::well_known_keys;
use primitives::Blake2Hasher;
@@ -288,7 +288,7 @@ impl RuntimesCache {
let heap_pages = ext
.storage(well_known_keys::HEAP_PAGES)
.and_then(|pages| u64::decode(&mut &pages[..]))
.and_then(|pages| u64::decode(&mut &pages[..]).ok())
.or(default_heap_pages)
.unwrap_or(DEFAULT_HEAP_PAGES);
@@ -308,7 +308,7 @@ impl RuntimesCache {
let version = wasm_executor
.call_in_wasm_module(ext, &instance, "Core_version", &[])
.ok()
.and_then(|v| RuntimeVersion::decode(&mut v.as_slice()));
.and_then(|v| RuntimeVersion::decode(&mut v.as_slice()).ok());
Ok(Rc::new(CachedRuntime {
instance,
version,