difftreelog
fix serde no_std usage
in: master
6 files changed
pallets/inflation/Cargo.tomldiffbeforeafterboth--- a/pallets/inflation/Cargo.toml
+++ b/pallets/inflation/Cargo.toml
@@ -19,7 +19,7 @@
version = '2.0.0'
[dependencies]
-serde = { version = "1.0.119" }
+serde = { default-features = false, version = "1.0.119", features = ["derive"] }
frame-support = { default-features = false, version = '3.0.0', git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
frame-system = { default-features = false, version = '3.0.0', git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
pallet-balances = { default-features = false, version = '3.0.0', git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
pallets/inflation/src/lib.rsdiffbeforeafterboth--- a/pallets/inflation/src/lib.rs
+++ b/pallets/inflation/src/lib.rs
@@ -10,8 +10,7 @@
#[cfg(feature = "std")]
pub use std::*;
-#[cfg(feature = "std")]
-pub use serde::*;
+pub use serde::{Serialize, Deserialize};
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pallets/nft/Cargo.tomldiffbeforeafterboth--- a/pallets/nft/Cargo.toml
+++ b/pallets/nft/Cargo.toml
@@ -19,7 +19,7 @@
version = '2.0.0'
[dependencies]
-serde = { version = "1.0.119" }
+serde = { default-features = false, version = "1.0.119", features = ["derive"] }
frame-support = { default-features = false, version = '3.0.0', git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
frame-system = { default-features = false, version = '3.0.0', git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
pallet-balances = { default-features = false, version = '3.0.0', git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
pallets/nft/src/eth/account.rsdiffbeforeafterboth1use crate::Config;2use codec::{Encode, EncodeLike, Decode};3use sp_core::{H160, H256, crypto::AccountId32};4use core::cmp::Ordering;5#[cfg(feature = "std")]6use serde::{Serialize, Deserialize};7use pallet_evm::AddressMapping;8use sp_std::vec::Vec;9use sp_std::clone::Clone;1011pub trait CrossAccountId<AccountId>: 12 Encode + EncodeLike + Decode + 13 Clone + PartialEq + Ord + core::fmt::Debug // + 14 // Serialize + Deserialize<'static> 15{16 fn as_sub(&self) -> &AccountId;17 fn as_eth(&self) -> &H160;1819 fn from_sub(account: AccountId) -> Self;20 fn from_eth(account: H160) -> Self;21}2223#[derive(Eq)]24#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]25pub struct BasicCrossAccountId<T: Config> {26 /// If true - then ethereum is canonical encoding27 from_ethereum: bool,28 substrate: T::AccountId,29 ethereum: H160,30}3132impl<T: Config> core::fmt::Debug for BasicCrossAccountId<T> {33 fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {34 if self.from_ethereum {35 fmt.debug_tuple("CrossAccountId::Ethereum")36 .field(&self.ethereum)37 .finish()38 } else {39 fmt.debug_tuple("CrossAccountId::Substrate")40 .field(&self.substrate)41 .finish()42 }43 }44}4546impl<T: Config> PartialOrd for BasicCrossAccountId<T> {47 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {48 Some(self.substrate.cmp(&other.substrate))49 }50}5152impl<T: Config> Ord for BasicCrossAccountId<T> {53 fn cmp(&self, other: &Self) -> Ordering {54 self.partial_cmp(other).expect("substrate account is total ordered")55 }56}5758impl<T: Config> PartialEq for BasicCrossAccountId<T> {59 fn eq(&self, other: &Self) -> bool {60 if self.from_ethereum == other.from_ethereum {61 self.substrate == other.substrate && self.ethereum == other.ethereum62 } else if self.from_ethereum {63 // ethereum is canonical encoding, but we need to compare derived address64 self.substrate == other.substrate65 } else {66 self.ethereum == other.ethereum67 }68 }69}70impl<T: Config> Clone for BasicCrossAccountId<T> {71 fn clone(&self) -> Self {72 Self {73 from_ethereum: self.from_ethereum,74 substrate: self.substrate.clone(),75 ethereum: self.ethereum,76 }77 }78}79impl<T: Config> Encode for BasicCrossAccountId<T> {80 fn encode(&self) -> Vec<u8> {81 let as_result = if !self.from_ethereum {82 Ok(self.substrate.clone())83 } else {84 Err(self.ethereum)85 };86 as_result.encode()87 }88}89impl<T: Config> EncodeLike for BasicCrossAccountId<T> {}90impl<T: Config> Decode for BasicCrossAccountId<T> {91 fn decode<I>(input: &mut I) -> Result<Self, codec::Error>92 where I: codec::Input93 {94 Ok(match <Result<T::AccountId, H160>>::decode(input)? {95 Ok(s) => Self::from_sub(s),96 Err(e) => Self::from_eth(e),97 })98 }99}100impl<T: Config> CrossAccountId<T::AccountId> for BasicCrossAccountId<T> {101 fn as_sub(&self) -> &T::AccountId {102 &self.substrate103 }104 fn as_eth(&self) -> &H160 {105 &self.ethereum106 }107 fn from_sub(substrate: T::AccountId) -> Self {108 Self {109 ethereum: T::EvmBackwardsAddressMapping::from_account_id(substrate.clone()),110 substrate,111 from_ethereum: false,112 }113 }114 fn from_eth(ethereum: H160) -> Self {115 Self {116 ethereum,117 substrate: T::EvmAddressMapping::into_account_id(ethereum),118 from_ethereum: true,119 }120 }121}122123pub trait EvmBackwardsAddressMapping<AccountId> {124 fn from_account_id(account_id: AccountId) -> H160;125}126127/// Should have same mapping as EnsureAddressTruncated128pub struct MapBackwardsAddressTruncated;129impl EvmBackwardsAddressMapping<AccountId32> for MapBackwardsAddressTruncated {130 fn from_account_id(account_id: AccountId32) -> H160 {131 let mut out = [0; 20];132 out.copy_from_slice(&(account_id.as_ref() as &[u8])[0..20]);133 H160(out)134 }135}1use crate::Config;2use codec::{Encode, EncodeLike, Decode};3use sp_core::{H160, H256, crypto::AccountId32};4use core::cmp::Ordering;5use serde::{Serialize, Deserialize};6use pallet_evm::AddressMapping;7use sp_std::vec::Vec;8use sp_std::clone::Clone;910pub trait CrossAccountId<AccountId>: 11 Encode + EncodeLike + Decode + 12 Clone + PartialEq + Ord + core::fmt::Debug // + 13 // Serialize + Deserialize<'static> 14{15 fn as_sub(&self) -> &AccountId;16 fn as_eth(&self) -> &H160;1718 fn from_sub(account: AccountId) -> Self;19 fn from_eth(account: H160) -> Self;20}2122#[derive(Eq)]23#[derive(Serialize, Deserialize)]24pub struct BasicCrossAccountId<T: Config> {25 /// If true - then ethereum is canonical encoding26 from_ethereum: bool,27 substrate: T::AccountId,28 ethereum: H160,29}3031impl<T: Config> core::fmt::Debug for BasicCrossAccountId<T> {32 fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {33 if self.from_ethereum {34 fmt.debug_tuple("CrossAccountId::Ethereum")35 .field(&self.ethereum)36 .finish()37 } else {38 fmt.debug_tuple("CrossAccountId::Substrate")39 .field(&self.substrate)40 .finish()41 }42 }43}4445impl<T: Config> PartialOrd for BasicCrossAccountId<T> {46 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {47 Some(self.substrate.cmp(&other.substrate))48 }49}5051impl<T: Config> Ord for BasicCrossAccountId<T> {52 fn cmp(&self, other: &Self) -> Ordering {53 self.partial_cmp(other).expect("substrate account is total ordered")54 }55}5657impl<T: Config> PartialEq for BasicCrossAccountId<T> {58 fn eq(&self, other: &Self) -> bool {59 if self.from_ethereum == other.from_ethereum {60 self.substrate == other.substrate && self.ethereum == other.ethereum61 } else if self.from_ethereum {62 // ethereum is canonical encoding, but we need to compare derived address63 self.substrate == other.substrate64 } else {65 self.ethereum == other.ethereum66 }67 }68}69impl<T: Config> Clone for BasicCrossAccountId<T> {70 fn clone(&self) -> Self {71 Self {72 from_ethereum: self.from_ethereum,73 substrate: self.substrate.clone(),74 ethereum: self.ethereum,75 }76 }77}78impl<T: Config> Encode for BasicCrossAccountId<T> {79 fn encode(&self) -> Vec<u8> {80 let as_result = if !self.from_ethereum {81 Ok(self.substrate.clone())82 } else {83 Err(self.ethereum)84 };85 as_result.encode()86 }87}88impl<T: Config> EncodeLike for BasicCrossAccountId<T> {}89impl<T: Config> Decode for BasicCrossAccountId<T> {90 fn decode<I>(input: &mut I) -> Result<Self, codec::Error>91 where I: codec::Input92 {93 Ok(match <Result<T::AccountId, H160>>::decode(input)? {94 Ok(s) => Self::from_sub(s),95 Err(e) => Self::from_eth(e),96 })97 }98}99impl<T: Config> CrossAccountId<T::AccountId> for BasicCrossAccountId<T> {100 fn as_sub(&self) -> &T::AccountId {101 &self.substrate102 }103 fn as_eth(&self) -> &H160 {104 &self.ethereum105 }106 fn from_sub(substrate: T::AccountId) -> Self {107 Self {108 ethereum: T::EvmBackwardsAddressMapping::from_account_id(substrate.clone()),109 substrate,110 from_ethereum: false,111 }112 }113 fn from_eth(ethereum: H160) -> Self {114 Self {115 ethereum,116 substrate: T::EvmAddressMapping::into_account_id(ethereum),117 from_ethereum: true,118 }119 }120}121122pub trait EvmBackwardsAddressMapping<AccountId> {123 fn from_account_id(account_id: AccountId) -> H160;124}125126/// Should have same mapping as EnsureAddressTruncated127pub struct MapBackwardsAddressTruncated;128impl EvmBackwardsAddressMapping<AccountId32> for MapBackwardsAddressTruncated {129 fn from_account_id(account_id: AccountId32) -> H160 {130 let mut out = [0; 20];131 out.copy_from_slice(&(account_id.as_ref() as &[u8])[0..20]);132 H160(out)133 }134}pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -7,9 +7,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
-#[cfg(feature = "std")]
-pub use serde::*;
+pub use serde::{Serialize, Deserialize};
+
use core::ops::{Deref, DerefMut};
use codec::{Decode, Encode};
pub use frame_support::{
@@ -71,7 +71,7 @@
pub type DecimalPoints = u8;
#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+#[derive(Serialize, Deserialize)]
pub enum CollectionMode {
Invalid,
NFT,
pallets/nft/src/types.rsdiffbeforeafterboth--- a/pallets/nft/src/types.rs
+++ b/pallets/nft/src/types.rs
@@ -1,8 +1,7 @@
#[cfg(feature = "std")]
pub use std::*;
-#[cfg(feature = "std")]
-pub use serde::*;
+pub use serde::{Serealize, Deserialize};
use codec::{Decode, Encode};