mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 19:51:05 +00:00
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:
committed by
Bastian Köcher
parent
a0d442333f
commit
4ed67e03a4
@@ -19,7 +19,7 @@ trie = { package = "substrate-trie", path = "../trie", optional = true }
|
||||
substrate-telemetry = { path = "../telemetry", optional = true }
|
||||
hash-db = { version = "0.15.0", default-features = false }
|
||||
kvdb = { git = "https://github.com/paritytech/parity-common", optional = true, rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
|
||||
parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
|
||||
sr-primitives = { path = "../sr-primitives", default-features = false }
|
||||
runtime-version = { package = "sr-version", path = "../sr-version", default-features = false }
|
||||
@@ -36,7 +36,7 @@ kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b031
|
||||
default = ["std"]
|
||||
std = [
|
||||
"rstd/std",
|
||||
"parity-codec/std",
|
||||
"codec/std",
|
||||
"primitives/std",
|
||||
"inherents/std",
|
||||
"sr-primitives/std",
|
||||
|
||||
@@ -17,7 +17,7 @@ primitives = { package = "substrate-primitives", path = "../../primitives" }
|
||||
sr-primitives = { path = "../../sr-primitives" }
|
||||
client = { package = "substrate-client", path = "../../client" }
|
||||
state-machine = { package = "substrate-state-machine", path = "../../state-machine" }
|
||||
parity-codec = { version = "4.1.1", features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] }
|
||||
executor = { package = "substrate-executor", path = "../../executor" }
|
||||
state_db = { package = "substrate-state-db", path = "../../state-db" }
|
||||
trie = { package = "substrate-trie", path = "../../trie" }
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
|
||||
use client::error::Result as ClientResult;
|
||||
use sr_primitives::traits::{Block as BlockT, NumberFor};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
use crate::cache::{CacheItemT, ComplexBlockId};
|
||||
use crate::cache::list_storage::{Storage};
|
||||
|
||||
+4
-4
@@ -21,7 +21,7 @@ use std::sync::Arc;
|
||||
use kvdb::{KeyValueDB, DBTransaction};
|
||||
|
||||
use client::error::{Error as ClientError, Result as ClientResult};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use sr_primitives::generic::BlockId;
|
||||
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor};
|
||||
use crate::utils::{self, db_err, meta_keys};
|
||||
@@ -151,7 +151,7 @@ impl<Block: BlockT, T: CacheItemT> Storage<Block, T> for DbStorage {
|
||||
.map_err(db_err)
|
||||
.and_then(|entry| match entry {
|
||||
Some(entry) => StorageEntry::<Block, T>::decode(&mut &entry[..])
|
||||
.ok_or_else(|| ClientError::Backend("Failed to decode cache entry".into()))
|
||||
.map_err(|_| ClientError::Backend("Failed to decode cache entry".into()))
|
||||
.map(Some),
|
||||
None => Ok(None),
|
||||
})
|
||||
@@ -236,9 +236,9 @@ mod meta {
|
||||
pub fn decode<Block: BlockT>(encoded: &[u8]) -> ClientResult<Metadata<Block>> {
|
||||
let input = &mut &*encoded;
|
||||
let finalized: Option<ComplexBlockId<Block>> = Decode::decode(input)
|
||||
.ok_or_else(|| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?;
|
||||
.map_err(|_| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?;
|
||||
let unfinalized: Vec<ComplexBlockId<Block>> = Decode::decode(input)
|
||||
.ok_or_else(|| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?;
|
||||
.map_err(|_| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?;
|
||||
|
||||
Ok(Metadata { finalized, unfinalized })
|
||||
}
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ use kvdb::{KeyValueDB, DBTransaction};
|
||||
|
||||
use client::blockchain::Cache as BlockchainCache;
|
||||
use client::error::Result as ClientResult;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use sr_primitives::generic::BlockId;
|
||||
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
|
||||
use consensus_common::well_known_cache_keys::Id as CacheKeyId;
|
||||
|
||||
@@ -42,7 +42,7 @@ use client::backend::NewBlockState;
|
||||
use client::blockchain::HeaderBackend;
|
||||
use client::ExecutionStrategies;
|
||||
use client::backend::{StorageCollection, ChildStorageCollection};
|
||||
use parity_codec::{Decode, Encode};
|
||||
use codec::{Decode, Encode};
|
||||
use hash_db::{Hasher, Prefix};
|
||||
use kvdb::{KeyValueDB, DBTransaction};
|
||||
use trie::{MemoryDB, PrefixedMemoryDB, prefixed_key};
|
||||
@@ -338,8 +338,10 @@ impl<Block: BlockT> client::blockchain::Backend<Block> for BlockchainDb<Block> {
|
||||
fn body(&self, id: BlockId<Block>) -> Result<Option<Vec<Block::Extrinsic>>, client::error::Error> {
|
||||
match read_db(&*self.db, columns::KEY_LOOKUP, columns::BODY, id)? {
|
||||
Some(body) => match Decode::decode(&mut &body[..]) {
|
||||
Some(body) => Ok(Some(body)),
|
||||
None => return Err(client::error::Error::Backend("Error decoding body".into())),
|
||||
Ok(body) => Ok(Some(body)),
|
||||
Err(err) => return Err(client::error::Error::Backend(
|
||||
format!("Error decoding body: {}", err)
|
||||
)),
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
@@ -348,8 +350,10 @@ impl<Block: BlockT> client::blockchain::Backend<Block> for BlockchainDb<Block> {
|
||||
fn justification(&self, id: BlockId<Block>) -> Result<Option<Justification>, client::error::Error> {
|
||||
match read_db(&*self.db, columns::KEY_LOOKUP, columns::JUSTIFICATION, id)? {
|
||||
Some(justification) => match Decode::decode(&mut &justification[..]) {
|
||||
Some(justification) => Ok(Some(justification)),
|
||||
None => return Err(client::error::Error::Backend("Error decoding justification".into())),
|
||||
Ok(justification) => Ok(Some(justification)),
|
||||
Err(err) => return Err(client::error::Error::Backend(
|
||||
format!("Error decoding justification: {}", err)
|
||||
)),
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
@@ -838,7 +842,7 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> {
|
||||
let changes_trie_config = self
|
||||
.state_at(BlockId::Hash(block))?
|
||||
.storage(well_known_keys::CHANGES_TRIE_CONFIG)?
|
||||
.and_then(|v| Decode::decode(&mut &*v));
|
||||
.and_then(|v| Decode::decode(&mut &*v).ok());
|
||||
*cached_changes_trie_config = Some(changes_trie_config.clone());
|
||||
Ok(changes_trie_config)
|
||||
},
|
||||
|
||||
@@ -29,7 +29,7 @@ use client::cht;
|
||||
use client::leaves::{LeafSet, FinalizationDisplaced};
|
||||
use client::error::{Error as ClientError, Result as ClientResult};
|
||||
use client::light::blockchain::Storage as LightBlockchainStorage;
|
||||
use parity_codec::{Decode, Encode};
|
||||
use codec::{Decode, Encode};
|
||||
use primitives::Blake2Hasher;
|
||||
use sr_primitives::generic::{DigestItem, BlockId};
|
||||
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, One, NumberFor};
|
||||
@@ -360,7 +360,7 @@ impl<Block: BlockT> LightStorage<Block> {
|
||||
let cht_start = cht::start_number(cht_size, cht_number);
|
||||
self.db.get(columns::CHT, &cht_key(cht_type, cht_start)?).map_err(db_err)?
|
||||
.ok_or_else(no_cht_for_block)
|
||||
.and_then(|hash| Block::Hash::decode(&mut &*hash).ok_or_else(no_cht_for_block))
|
||||
.and_then(|hash| Block::Hash::decode(&mut &*hash).map_err(|_| no_cht_for_block()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -887,7 +887,8 @@ pub(crate) mod tests {
|
||||
}
|
||||
|
||||
fn get_authorities(cache: &dyn BlockchainCache<Block>, at: BlockId<Block>) -> Option<Vec<AuthorityId>> {
|
||||
cache.get_at(&well_known_cache_keys::AUTHORITIES, &at).and_then(|val| Decode::decode(&mut &val[..]))
|
||||
cache.get_at(&well_known_cache_keys::AUTHORITIES, &at)
|
||||
.and_then(|val| Decode::decode(&mut &val[..]).ok())
|
||||
}
|
||||
|
||||
let auth1 = || AuthorityId::from_raw([1u8; 32]);
|
||||
|
||||
@@ -27,7 +27,7 @@ use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||
use log::debug;
|
||||
|
||||
use client;
|
||||
use parity_codec::Decode;
|
||||
use codec::Decode;
|
||||
use trie::DBValue;
|
||||
use sr_primitives::generic::BlockId;
|
||||
use sr_primitives::traits::{
|
||||
@@ -260,8 +260,8 @@ pub fn read_header<Block: BlockT>(
|
||||
) -> client::error::Result<Option<Block::Header>> {
|
||||
match read_db(db, col_index, col, id)? {
|
||||
Some(header) => match Block::Header::decode(&mut &header[..]) {
|
||||
Some(header) => Ok(Some(header)),
|
||||
None => return Err(
|
||||
Ok(header) => Ok(Some(header)),
|
||||
Err(_) => return Err(
|
||||
client::error::Error::Backend("Error decoding header".into())
|
||||
),
|
||||
}
|
||||
@@ -290,8 +290,10 @@ pub fn read_meta<Block>(db: &dyn KeyValueDB, col_meta: Option<u32>, col_header:
|
||||
{
|
||||
let genesis_hash: Block::Hash = match db.get(col_meta, meta_keys::GENESIS_HASH).map_err(db_err)? {
|
||||
Some(h) => match Decode::decode(&mut &h[..]) {
|
||||
Some(h) => h,
|
||||
None => return Err(client::error::Error::Backend("Error decoding genesis hash".into())),
|
||||
Ok(h) => h,
|
||||
Err(err) => return Err(client::error::Error::Backend(
|
||||
format!("Error decoding genesis hash: {}", err)
|
||||
)),
|
||||
},
|
||||
None => return Ok(Meta {
|
||||
best_hash: Default::default(),
|
||||
@@ -305,7 +307,7 @@ pub fn read_meta<Block>(db: &dyn KeyValueDB, col_meta: Option<u32>, col_header:
|
||||
let load_meta_block = |desc, key| -> Result<_, client::error::Error> {
|
||||
if let Some(Some(header)) = db.get(col_meta, key).and_then(|id|
|
||||
match id {
|
||||
Some(id) => db.get(col_header, &id).map(|h| h.map(|b| Block::Header::decode(&mut &b[..]))),
|
||||
Some(id) => db.get(col_header, &id).map(|h| h.map(|b| Block::Header::decode(&mut &b[..]).ok())),
|
||||
None => Ok(None),
|
||||
}).map_err(db_err)?
|
||||
{
|
||||
|
||||
@@ -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::{
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user