git.delta.rocks / unique-network / refs/commits / 4a53d88957b6

difftreelog

fix serde no_std usage

Yaroslav Bolyukin2021-06-02parent: #5e83d89.patch.diff
in: master

6 files changed

modifiedpallets/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" }
modifiedpallets/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;
modifiedpallets/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" }
modifiedpallets/nft/src/eth/account.rsdiffbeforeafterboth
--- a/pallets/nft/src/eth/account.rs
+++ b/pallets/nft/src/eth/account.rs
@@ -2,7 +2,6 @@
 use codec::{Encode, EncodeLike, Decode};
 use sp_core::{H160, H256, crypto::AccountId32};
 use core::cmp::Ordering;
-#[cfg(feature = "std")]
 use serde::{Serialize, Deserialize};
 use pallet_evm::AddressMapping;
 use sp_std::vec::Vec;
@@ -21,7 +20,7 @@
 }
 
 #[derive(Eq)]
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+#[derive(Serialize, Deserialize)]
 pub struct BasicCrossAccountId<T: Config> {
     /// If true - then ethereum is canonical encoding
     from_ethereum: bool,
modifiedpallets/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,
modifiedpallets/nft/src/types.rsdiffbeforeafterboth
after · pallets/nft/src/types.rs
1#[cfg(feature = "std")]2pub use std::*;34pub use serde::{Serealize, Deserialize};56use codec::{Decode, Encode};78pub type CollectionId = u32;9pub type TokenId = u32;10pub type DecimalPoints = u8;1112#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]13#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]14pub enum CollectionMode {15    Invalid,16    NFT,17    // decimal points18    Fungible(DecimalPoints),19    // decimal points20    ReFungible(DecimalPoints),21}2223impl Into<u8> for CollectionMode {24    fn into(self) -> u8 {25        match self {26            CollectionMode::Invalid => 0,27            CollectionMode::NFT => 1,28            CollectionMode::Fungible(_) => 2,29            CollectionMode::ReFungible(_) => 3,30        }31    }32}3334#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]35#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]36pub enum AccessMode {37    Normal,38    WhiteList,39}40impl Default for AccessMode {41    fn default() -> Self {42        Self::Normal43    }44}4546impl Default for CollectionMode {47    fn default() -> Self {48        Self::Invalid49    }50}5152#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]53#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]54pub enum SchemaVersion {55    ImageURL,56    Unique,57}58impl Default for SchemaVersion {59    fn default() -> Self {60        Self::ImageURL61    }62}6364#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]65#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]66pub struct Ownership<AccountId> {67    pub owner: AccountId,68    pub fraction: u128,69}7071#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]72#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]73pub struct CollectionType<AccountId> {74    pub owner: AccountId,75    pub mode: CollectionMode,76    pub access: AccessMode,77    pub decimal_points: DecimalPoints,78    pub name: Vec<u16>,        // 64 include null escape char79    pub description: Vec<u16>, // 256 include null escape char80    pub token_prefix: Vec<u8>, // 16 include null escape char81    pub mint_mode: bool,82    pub offchain_schema: Vec<u8>,83    pub schema_version: SchemaVersion,84    pub sponsor: AccountId, // Who pays fees. If set to default address, the fees are applied to the transaction sender85    pub unconfirmed_sponsor: AccountId, // Sponsor address that has not yet confirmed sponsorship86    pub limits: CollectionLimits, // Collection private restrictions 87    pub variable_on_chain_schema: Vec<u8>, //88    pub const_on_chain_schema: Vec<u8>, //89}9091#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]92#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]93pub struct NftItemType<AccountId> {94    pub collection: CollectionId,95    pub owner: AccountId,96    pub const_data: Vec<u8>,97    pub variable_data: Vec<u8>,98}99100#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]101#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]102pub struct FungibleItemType<AccountId> {103    pub collection: CollectionId,104    pub owner: AccountId,105    pub value: u128,106}107108#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]109#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]110pub struct ReFungibleItemType<AccountId> {111    pub collection: CollectionId,112    pub owner: Vec<Ownership<AccountId>>,113    pub const_data: Vec<u8>,114    pub variable_data: Vec<u8>,115}116117#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]118#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]119pub struct ApprovePermissions<AccountId> {120    pub approved: AccountId,121    pub amount: u128,122}123124#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]125#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]126pub struct VestingItem<AccountId, Moment> {127    pub sender: AccountId,128    pub recipient: AccountId,129    pub collection_id: CollectionId,130    pub item_id: TokenId,131    pub amount: u64,132    pub vesting_date: Moment,133}134135#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]136#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]137pub struct BasketItem<AccountId, BlockNumber> {138    pub address: AccountId,139    pub start_block: BlockNumber,140}141142#[derive(Encode, Decode, Debug, Clone, PartialEq)]143#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]144pub struct CollectionLimits {145    pub account_token_ownership_limit: u32,146    pub sponsored_data_size: u32,147    pub token_limit: u32,148149    // Timeouts for item types in passed blocks150    pub sponsor_transfer_timeout: u32,151}152153impl Default for CollectionLimits {154    fn default() -> CollectionLimits {155        CollectionLimits { 156            account_token_ownership_limit: 10_000_000, 157            token_limit: u32::max_value(),158            sponsored_data_size: u32::max_value(), 159            sponsor_transfer_timeout: 14400 }160    }161}162163#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]164#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]165pub struct ChainLimits {166    pub collection_numbers_limit: u32,167    pub account_token_ownership_limit: u32,168    pub collections_admins_limit: u64,169    pub custom_data_limit: u32,170171    // Timeouts for item types in passed blocks172    pub nft_sponsor_transfer_timeout: u32,173    pub fungible_sponsor_transfer_timeout: u32,174    pub refungible_sponsor_transfer_timeout: u32,175}176177178#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]179#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]180pub struct CreateNftData {181    pub const_data: Vec<u8>,182    pub variable_data: Vec<u8>,183}184185#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]186#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]187pub struct CreateFungibleData {188}189190#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]191#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]192pub struct CreateReFungibleData {193    pub const_data: Vec<u8>,194    pub variable_data: Vec<u8>,195}196197#[derive(Encode, Decode, Debug, Clone, PartialEq)]198#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]199pub enum CreateItemData {200    NFT(CreateNftData),201    Fungible(CreateFungibleData),202    ReFungible(CreateReFungibleData),203}204205impl CreateItemData {206    pub fn len(&self) -> usize {207        let len = match self {208            CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),209            CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),210            _ => 0211        };212        213        return len;214    }215}216217impl From<CreateNftData> for CreateItemData {218    fn from(item: CreateNftData) -> Self {219        CreateItemData::NFT(item)220    }221}222223impl From<CreateReFungibleData> for CreateItemData {224    fn from(item: CreateReFungibleData) -> Self {225        CreateItemData::ReFungible(item)226    }227}228229impl From<CreateFungibleData> for CreateItemData {230    fn from(item: CreateFungibleData) -> Self {231        CreateItemData::Fungible(item)232    }233}