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
@@ -16,7 +16,7 @@
use super::api::BlockBuilder as BlockBuilderApi;
use std::vec::Vec;
use parity_codec::Encode;
use codec::Encode;
use sr_primitives::ApplyOutcome;
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{
+1 -1
View File
@@ -15,7 +15,7 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use std::{sync::Arc, cmp::Ord, panic::UnwindSafe, result, cell::RefCell, rc::Rc};
use parity_codec::{Encode, Decode};
use codec::{Encode, Decode};
use sr_primitives::{
generic::BlockId, traits::Block as BlockT,
};
+3 -3
View File
@@ -17,7 +17,7 @@
//! Functionality for reading and storing children hashes from db.
use kvdb::{KeyValueDB, DBTransaction};
use parity_codec::{Encode, Decode};
use codec::{Encode, Decode};
use crate::error;
use std::hash::Hash;
@@ -41,8 +41,8 @@ pub fn read_children<
};
let children: Vec<V> = match Decode::decode(&mut &raw_val[..]) {
Some(children) => children,
None => return Err(error::Error::Backend("Error decoding children".into())),
Ok(children) => children,
Err(_) => return Err(error::Error::Backend("Error decoding children".into())),
};
Ok(children)
+1 -1
View File
@@ -26,7 +26,7 @@
use std::collections::HashSet;
use hash_db;
use parity_codec::Encode;
use codec::Encode;
use trie;
use primitives::{H256, convert_hash};
+2 -2
View File
@@ -50,7 +50,7 @@ use primitives::{
};
use primitives::storage::{StorageKey, StorageData};
use primitives::storage::well_known_keys;
use parity_codec::{Encode, Decode};
use codec::{Encode, Decode};
use state_machine::{
DBValue, Backend as StateBackend, CodeExecutor, ChangesTrieAnchorBlockId,
ExecutionStrategy, ExecutionManager, prove_read, prove_child_read,
@@ -1327,7 +1327,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
Ok(self.backend.state_at(BlockId::Number(self.backend.blockchain().info().best_number))?
.storage(well_known_keys::CHANGES_TRIE_CONFIG)
.map_err(|e| error::Error::from_state(Box::new(e)))?
.and_then(|c| Decode::decode(&mut &*c)))
.and_then(|c| Decode::decode(&mut &*c).ok()))
}
/// Prepare in-memory header that is used in execution environment.
+3 -3
View File
@@ -74,11 +74,11 @@ pub enum Error {
#[display(fmt = "Remote data fetch has been failed")]
RemoteFetchFailed,
/// Error decoding call result.
#[display(fmt = "Error decoding call result of {}", _0)]
CallResultDecode(&'static str),
#[display(fmt = "Error decoding call result of {}: {}", _0, _1)]
CallResultDecode(&'static str, codec::Error),
/// Error converting a parameter between runtime and node.
#[display(fmt = "Error converting `{}` between runtime and node", _0)]
RuntimeParamConversion(&'static str),
RuntimeParamConversion(String),
/// Changes tries are not supported.
#[display(fmt = "Changes tries are not supported by the runtime")]
ChangesTriesNotSupported,
+1 -1
View File
@@ -40,7 +40,7 @@ pub fn construct_genesis_block<
#[cfg(test)]
mod tests {
use super::*;
use parity_codec::{Encode, Decode, Joiner};
use codec::{Encode, Decode, Joiner};
use executor::native_executor_instance;
use state_machine::{self, OverlayedChanges, ExecutionStrategy, InMemoryChangesTrieStorage};
use state_machine::backend::InMemory;
+5 -5
View File
@@ -20,7 +20,7 @@ use std::collections::BTreeMap;
use std::cmp::Reverse;
use kvdb::{KeyValueDB, DBTransaction};
use sr_primitives::traits::SimpleArithmetic;
use parity_codec::{Encode, Decode};
use codec::{Encode, Decode};
use crate::error;
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -84,12 +84,12 @@ impl<H, N> LeafSet<H, N> where
if !key.starts_with(prefix) { break }
let raw_hash = &mut &key[prefix.len()..];
let hash = match Decode::decode(raw_hash) {
Some(hash) => hash,
None => return Err(error::Error::Backend("Error decoding hash".into())),
Ok(hash) => hash,
Err(_) => return Err(error::Error::Backend("Error decoding hash".into())),
};
let number = match Decode::decode(&mut &value[..]) {
Some(number) => number,
None => return Err(error::Error::Backend("Error decoding number".into())),
Ok(number) => number,
Err(_) => return Err(error::Error::Backend("Error decoding number".into())),
};
storage.entry(Reverse(number)).or_insert_with(Vec::new).push(hash);
}
@@ -22,7 +22,7 @@ use std::{
marker::PhantomData, cell::RefCell, rc::Rc,
};
use parity_codec::{Encode, Decode};
use codec::{Encode, Decode};
use primitives::{offchain, H256, Blake2Hasher, convert_hash, NativeOrEncoded};
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{One, Block as BlockT, Header as HeaderT};
@@ -149,7 +149,7 @@ where
fn runtime_version(&self, id: &BlockId<Block>) -> ClientResult<RuntimeVersion> {
let call_result = self.call(id, "Core_version", &[], ExecutionStrategy::NativeElseWasm, NeverOffchainExt::new())?;
RuntimeVersion::decode(&mut call_result.as_slice())
.ok_or_else(|| ClientError::VersionInvalid.into())
.map_err(|_| ClientError::VersionInvalid.into())
}
fn call_at_state<
+3 -3
View File
@@ -22,7 +22,7 @@ use std::marker::PhantomData;
use std::future::Future;
use hash_db::{HashDB, Hasher, EMPTY_PREFIX};
use parity_codec::{Decode, Encode};
use codec::{Decode, Encode};
use primitives::{ChangesTrieConfiguration, convert_hash};
use sr_primitives::traits::{
Block as BlockT, Header as HeaderT, Hash, HashFor, NumberFor,
@@ -486,7 +486,7 @@ impl<'a, H, Number, Hash> ChangesTrieRootsStorage<H, Number> for RootsStorage<'a
pub mod tests {
use futures::future::Ready;
use parking_lot::Mutex;
use parity_codec::Decode;
use codec::Decode;
use crate::client::tests::prepare_client_with_key_changes;
use executor::{self, NativeExecutor};
use crate::error::Error as ClientError;
@@ -566,7 +566,7 @@ pub mod tests {
// 'fetch' read proof from remote node
let heap_pages = remote_client.storage(&remote_block_id, &StorageKey(well_known_keys::HEAP_PAGES.to_vec()))
.unwrap()
.and_then(|v| Decode::decode(&mut &v.0[..])).unwrap();
.and_then(|v| Decode::decode(&mut &v.0[..]).ok()).unwrap();
let remote_read_proof = remote_client.read_proof(&remote_block_id, well_known_keys::HEAP_PAGES).unwrap();
// check remote read proof locally
+1 -1
View File
@@ -39,7 +39,7 @@ pub use rstd::{slice, mem};
#[cfg(feature = "std")]
use rstd::result;
#[doc(hidden)]
pub use parity_codec::{Encode, Decode};
pub use codec::{Encode, Decode};
#[cfg(feature = "std")]
use crate::error;
use sr_api_macros::decl_runtime_apis;