mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 20:31:13 +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
@@ -18,7 +18,7 @@
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use num_traits::Zero;
|
||||
|
||||
/// Substrate changes trie configuration.
|
||||
|
||||
@@ -25,7 +25,7 @@ use parking_lot::Mutex;
|
||||
#[cfg(feature = "std")]
|
||||
use rand::{RngCore, rngs::OsRng};
|
||||
#[cfg(feature = "std")]
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
#[cfg(feature = "std")]
|
||||
use regex::Regex;
|
||||
#[cfg(feature = "std")]
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
|
||||
use crate::{hash::H256, hash::H512};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use blake2_rfc;
|
||||
|
||||
@@ -33,7 +33,7 @@ macro_rules! map {
|
||||
|
||||
use rstd::prelude::*;
|
||||
use rstd::ops::Deref;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
#[cfg(feature = "std")]
|
||||
use std::borrow::Cow;
|
||||
#[cfg(feature = "std")]
|
||||
@@ -138,14 +138,14 @@ pub enum NativeOrEncoded<R> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<R: parity_codec::Encode> ::std::fmt::Debug for NativeOrEncoded<R> {
|
||||
impl<R: codec::Encode> ::std::fmt::Debug for NativeOrEncoded<R> {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
self.as_encoded().as_ref().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<R: parity_codec::Encode> NativeOrEncoded<R> {
|
||||
impl<R: codec::Encode> NativeOrEncoded<R> {
|
||||
/// Return the value as the encoded format.
|
||||
pub fn as_encoded<'a>(&'a self) -> Cow<'a, [u8]> {
|
||||
match self {
|
||||
@@ -164,13 +164,13 @@ impl<R: parity_codec::Encode> NativeOrEncoded<R> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<R: PartialEq + parity_codec::Decode> PartialEq for NativeOrEncoded<R> {
|
||||
impl<R: PartialEq + codec::Decode> PartialEq for NativeOrEncoded<R> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(NativeOrEncoded::Native(l), NativeOrEncoded::Native(r)) => l == r,
|
||||
(NativeOrEncoded::Native(n), NativeOrEncoded::Encoded(e)) |
|
||||
(NativeOrEncoded::Encoded(e), NativeOrEncoded::Native(n)) =>
|
||||
Some(n) == parity_codec::Decode::decode(&mut &e[..]).as_ref(),
|
||||
Some(n) == codec::Decode::decode(&mut &e[..]).ok().as_ref(),
|
||||
(NativeOrEncoded::Encoded(l), NativeOrEncoded::Encoded(r)) => l == r,
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,7 @@ impl<R: PartialEq + parity_codec::Decode> PartialEq for NativeOrEncoded<R> {
|
||||
pub enum NeverNativeValue {}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl parity_codec::Encode for NeverNativeValue {
|
||||
impl codec::Encode for NeverNativeValue {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
// The enum is not constructable, so this function should never be callable!
|
||||
unreachable!()
|
||||
@@ -191,8 +191,11 @@ impl parity_codec::Encode for NeverNativeValue {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl parity_codec::Decode for NeverNativeValue {
|
||||
fn decode<I: parity_codec::Input>(_: &mut I) -> Option<Self> {
|
||||
None
|
||||
impl codec::EncodeLike for NeverNativeValue {}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl codec::Decode for NeverNativeValue {
|
||||
fn decode<I: codec::Input>(_: &mut I) -> Result<Self, codec::Error> {
|
||||
Err("`NeverNativeValue` should never be decoded".into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Offchain workers types
|
||||
|
||||
use crate::crypto;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use rstd::prelude::{Vec, Box};
|
||||
use rstd::convert::TryFrom;
|
||||
|
||||
@@ -397,7 +397,7 @@ pub trait Externalities {
|
||||
|
||||
/// Initiates a http request given HTTP verb and the URL.
|
||||
///
|
||||
/// Meta is a future-reserved field containing additional, parity-codec encoded parameters.
|
||||
/// Meta is a future-reserved field containing additional, parity-scale-codec encoded parameters.
|
||||
/// Returns the id of newly started request.
|
||||
fn http_request_start(
|
||||
&mut self,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Definition of a sandbox environment.
|
||||
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use rstd::vec::Vec;
|
||||
|
||||
/// Error error that can be returned from host function.
|
||||
@@ -184,7 +184,7 @@ pub const ERR_EXECUTION: u32 = -3i32 as u32;
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fmt;
|
||||
use parity_codec::Codec;
|
||||
use codec::Codec;
|
||||
|
||||
fn roundtrip<S: Codec + PartialEq + fmt::Debug>(s: S) {
|
||||
let encoded = s.encode();
|
||||
|
||||
@@ -33,7 +33,7 @@ use bip39::{Mnemonic, Language, MnemonicType};
|
||||
use crate::crypto::{Pair as TraitPair, DeriveJunction, Infallible, SecretStringError, Derive, Ss58Codec};
|
||||
use crate::crypto::{key_types, KeyTypeId, Public as TraitPublic, TypedKey, UncheckedFrom};
|
||||
use crate::hash::{H256, H512};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
@@ -21,7 +21,7 @@ pub use primitive_types::U256;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use substrate_serializer as ser;
|
||||
|
||||
macro_rules! test {
|
||||
@@ -78,10 +78,10 @@ mod tests {
|
||||
res2);
|
||||
assert_eq!(
|
||||
U256::decode(&mut &res1[..]),
|
||||
Some(U256::from(120)));
|
||||
Ok(U256::from(120)));
|
||||
assert_eq!(
|
||||
U256::decode(&mut &res2[..]),
|
||||
Some(U256::max_value()));
|
||||
Ok(U256::max_value()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user