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
before · pallets/inflation/src/lib.rs
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56#![recursion_limit = "1024"]78#![cfg_attr(not(feature = "std"), no_std)]910#[cfg(feature = "std")]11pub use std::*;1213#[cfg(feature = "std")]14pub use serde::*;1516#[cfg(feature = "runtime-benchmarks")]17mod benchmarking;1819#[cfg(test)]20mod tests;2122pub use frame_support::{23	construct_runtime, decl_module, decl_storage,24	ensure,25	traits::{26		Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,27		Randomness, IsSubType, WithdrawReasons,28	},29	weights::{30		constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},31		DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,32		WeightToFeePolynomial, DispatchClass,33	},34	StorageValue,35	transactional,36};3738// #[cfg(feature = "runtime-benchmarks")]39pub use frame_support::dispatch::DispatchResult;4041use sp_runtime::{42	Perbill,43	traits::{Zero}44};45use sp_std::convert::TryInto;4647use frame_system::{self as system};4849/// The balance type of this module.50pub type BalanceOf<T> =51	<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;5253pub const YEAR: u32 = 5_259_600;54pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;55pub const START_INFLATION_PERCENT: u32 = 10;56pub const END_INFLATION_PERCENT: u32 = 4;5758pub trait Config: system::Config {59	type Currency: Currency<Self::AccountId>;60	type TreasuryAccountId: Get<Self::AccountId>;61	type InflationBlockInterval: Get<Self::BlockNumber>;62}6364decl_storage! {65	trait Store for Module<T: Config> as Inflation {66		/// starting year total issuance67		pub StartingYearTotalIssuance get(fn starting_year_total_issuance): BalanceOf<T>;6869		/// Current block inflation70		pub BlockInflation get(fn block_inflation): BalanceOf<T>;71	}72}7374decl_module! {75	pub struct Module<T: Config> for enum Call 76	where 77		origin: T::Origin,78	{79		const InflationBlockInterval: T::BlockNumber = T::InflationBlockInterval::get();8081		fn on_initialize(now: T::BlockNumber) -> Weight 82		{83			let mut consumed_weight = 0;84			let mut add_weight = |reads, writes, weight| {85				consumed_weight += T::DbWeight::get().reads_writes(reads, writes);86				consumed_weight += weight;87			};8889			let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);9091			// Recalculate inflation on the first block of the year (or if it is not initialized yet)92			if (now % T::BlockNumber::from(YEAR)).is_zero() || <BlockInflation<T>>::get().is_zero() {93				let current_year: u32 = (now / T::BlockNumber::from(YEAR)).try_into().unwrap_or(0);9495				let one_percent = Perbill::from_percent(1);9697				if current_year <= TOTAL_YEARS_UNTIL_FLAT {98					let amount: BalanceOf<T> = Perbill::from_rational_approximation(99						block_interval * (START_INFLATION_PERCENT * TOTAL_YEARS_UNTIL_FLAT - current_year * (START_INFLATION_PERCENT - END_INFLATION_PERCENT)), 100						YEAR * TOTAL_YEARS_UNTIL_FLAT101					) * ( one_percent * T::Currency::total_issuance() );102					<BlockInflation<T>>::put(amount);103				}104				else {105					let amount: BalanceOf<T> = Perbill::from_rational_approximation(106						block_interval * END_INFLATION_PERCENT, 107						YEAR108					) * (one_percent * T::Currency::total_issuance());109					<BlockInflation<T>>::put(amount);110				}111				<StartingYearTotalIssuance<T>>::set(T::Currency::total_issuance());112113				// First time deposit114				T::Currency::deposit_creating(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get());115116				add_weight(7, 6, 28_300_000);117			}118119			// Apply inflation every InflationBlockInterval blocks and in the 1st block to initialize Treasury account120			else if (now % T::BlockNumber::from(block_interval)).is_zero() {121				T::Currency::deposit_into_existing(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get()).ok();122123				add_weight(3, 2, 12_900_000);124			}125126			consumed_weight127		}128129	}130}
after · pallets/inflation/src/lib.rs
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56#![recursion_limit = "1024"]78#![cfg_attr(not(feature = "std"), no_std)]910#[cfg(feature = "std")]11pub use std::*;1213pub use serde::{Serialize, Deserialize};1415#[cfg(feature = "runtime-benchmarks")]16mod benchmarking;1718#[cfg(test)]19mod tests;2021pub use frame_support::{22	construct_runtime, decl_module, decl_storage,23	ensure,24	traits::{25		Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,26		Randomness, IsSubType, WithdrawReasons,27	},28	weights::{29		constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},30		DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,31		WeightToFeePolynomial, DispatchClass,32	},33	StorageValue,34	transactional,35};3637// #[cfg(feature = "runtime-benchmarks")]38pub use frame_support::dispatch::DispatchResult;3940use sp_runtime::{41	Perbill,42	traits::{Zero}43};44use sp_std::convert::TryInto;4546use frame_system::{self as system};4748/// The balance type of this module.49pub type BalanceOf<T> =50	<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;5152pub const YEAR: u32 = 5_259_600;53pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;54pub const START_INFLATION_PERCENT: u32 = 10;55pub const END_INFLATION_PERCENT: u32 = 4;5657pub trait Config: system::Config {58	type Currency: Currency<Self::AccountId>;59	type TreasuryAccountId: Get<Self::AccountId>;60	type InflationBlockInterval: Get<Self::BlockNumber>;61}6263decl_storage! {64	trait Store for Module<T: Config> as Inflation {65		/// starting year total issuance66		pub StartingYearTotalIssuance get(fn starting_year_total_issuance): BalanceOf<T>;6768		/// Current block inflation69		pub BlockInflation get(fn block_inflation): BalanceOf<T>;70	}71}7273decl_module! {74	pub struct Module<T: Config> for enum Call 75	where 76		origin: T::Origin,77	{78		const InflationBlockInterval: T::BlockNumber = T::InflationBlockInterval::get();7980		fn on_initialize(now: T::BlockNumber) -> Weight 81		{82			let mut consumed_weight = 0;83			let mut add_weight = |reads, writes, weight| {84				consumed_weight += T::DbWeight::get().reads_writes(reads, writes);85				consumed_weight += weight;86			};8788			let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);8990			// Recalculate inflation on the first block of the year (or if it is not initialized yet)91			if (now % T::BlockNumber::from(YEAR)).is_zero() || <BlockInflation<T>>::get().is_zero() {92				let current_year: u32 = (now / T::BlockNumber::from(YEAR)).try_into().unwrap_or(0);9394				let one_percent = Perbill::from_percent(1);9596				if current_year <= TOTAL_YEARS_UNTIL_FLAT {97					let amount: BalanceOf<T> = Perbill::from_rational_approximation(98						block_interval * (START_INFLATION_PERCENT * TOTAL_YEARS_UNTIL_FLAT - current_year * (START_INFLATION_PERCENT - END_INFLATION_PERCENT)), 99						YEAR * TOTAL_YEARS_UNTIL_FLAT100					) * ( one_percent * T::Currency::total_issuance() );101					<BlockInflation<T>>::put(amount);102				}103				else {104					let amount: BalanceOf<T> = Perbill::from_rational_approximation(105						block_interval * END_INFLATION_PERCENT, 106						YEAR107					) * (one_percent * T::Currency::total_issuance());108					<BlockInflation<T>>::put(amount);109				}110				<StartingYearTotalIssuance<T>>::set(T::Currency::total_issuance());111112				// First time deposit113				T::Currency::deposit_creating(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get());114115				add_weight(7, 6, 28_300_000);116			}117118			// Apply inflation every InflationBlockInterval blocks and in the 1st block to initialize Treasury account119			else if (now % T::BlockNumber::from(block_interval)).is_zero() {120				T::Currency::deposit_into_existing(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get()).ok();121122				add_weight(3, 2, 12_900_000);123			}124125			consumed_weight126		}127128	}129}
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
--- 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};