From 8ca602bca3512a2b93b52eea6b6e2f323b6b693d Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Tue, 5 Aug 2025 08:47:45 +0800 Subject: [PATCH 1/6] add DecodeWithMemTracking features --- nft/src/lib.rs | 6 +++--- oracle/src/lib.rs | 17 +++++++++++++++-- payments/src/types.rs | 10 +++++----- rewards/src/lib.rs | 2 +- tokens/src/lib.rs | 8 +++++--- traits/src/auction.rs | 4 ++-- traits/src/lib.rs | 6 +++--- xtokens/src/mock/mod.rs | 3 ++- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/nft/src/lib.rs b/nft/src/lib.rs index 2b8bf2891..bc527e437 100644 --- a/nft/src/lib.rs +++ b/nft/src/lib.rs @@ -23,7 +23,7 @@ use frame_support::{ensure, pallet_prelude::*, traits::Get, BoundedVec, Parameter}; use frame_system::pallet_prelude::*; -use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::{ traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedSub, MaybeSerializeDeserialize, Member, One, Zero}, @@ -35,7 +35,7 @@ mod mock; mod tests; /// Class info -#[derive(Encode, Decode, Clone, Eq, PartialEq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, MaxEncodedLen, RuntimeDebug, TypeInfo)] pub struct ClassInfo { /// Class metadata pub metadata: ClassMetadataOf, @@ -48,7 +48,7 @@ pub struct ClassInfo { } /// Token info -#[derive(Encode, Decode, Clone, Eq, PartialEq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, MaxEncodedLen, RuntimeDebug, TypeInfo)] pub struct TokenInfo { /// Token metadata pub metadata: TokenMetadataOf, diff --git a/oracle/src/lib.rs b/oracle/src/lib.rs index 3c51dde96..c0c9faf9c 100644 --- a/oracle/src/lib.rs +++ b/oracle/src/lib.rs @@ -19,7 +19,7 @@ #![allow(clippy::string_lit_as_bytes)] #![allow(clippy::unused_unit)] -use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; @@ -77,7 +77,20 @@ pub mod module { pub(crate) type MomentOf = <>::Time as Time>::Moment; pub(crate) type TimestampedValueOf = TimestampedValue<>::OracleValue, MomentOf>; - #[derive(Encode, Decode, RuntimeDebug, Eq, PartialEq, Clone, Copy, Ord, PartialOrd, TypeInfo, MaxEncodedLen)] + #[derive( + Encode, + Decode, + DecodeWithMemTracking, + RuntimeDebug, + Eq, + PartialEq, + Clone, + Copy, + Ord, + PartialOrd, + TypeInfo, + MaxEncodedLen, + )] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct TimestampedValue { pub value: Value, diff --git a/payments/src/types.rs b/payments/src/types.rs index 2dd780066..06c87e9d6 100644 --- a/payments/src/types.rs +++ b/payments/src/types.rs @@ -1,7 +1,7 @@ #![allow(unused_qualifications)] use crate::{pallet, AssetIdOf, BalanceOf}; use frame_system::pallet_prelude::*; -use parity_scale_codec::{Decode, Encode, HasCompact, MaxEncodedLen}; +use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, HasCompact, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::{DispatchResult, Percent}; @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize}; /// guarantee proof of funds and can be released once an agreed upon condition /// has reached between the payment creator and recipient. The payment lifecycle /// is tracked using the state field. -#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)] #[scale_info(skip_type_params(T))] #[codec(mel_bound(T: pallet::Config))] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] @@ -38,7 +38,7 @@ pub struct PaymentDetail { /// The `PaymentState` enum tracks the possible states that a payment can be in. /// When a payment is 'completed' or 'cancelled' it is removed from storage and /// hence not tracked by a state. -#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)] #[scale_info(skip_type_params(T))] #[codec(mel_bound(T: pallet::Config))] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] @@ -109,14 +109,14 @@ pub trait FeeHandler { } /// Types of Tasks that can be scheduled in the pallet -#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] +#[derive(PartialEq, Eq, Clone, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen)] pub enum Task { // payment `from` to `to` has to be cancelled Cancel, } /// The details of a scheduled task -#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] +#[derive(PartialEq, Eq, Clone, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen)] pub struct ScheduledTask { /// the type of scheduled task pub task: Task, diff --git a/rewards/src/lib.rs b/rewards/src/lib.rs index ab33f8683..5a7f78d95 100644 --- a/rewards/src/lib.rs +++ b/rewards/src/lib.rs @@ -17,7 +17,7 @@ use sp_runtime::{ use sp_std::{borrow::ToOwned, collections::btree_map::BTreeMap, fmt::Debug, prelude::*}; /// The Reward Pool Info. -#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, Eq, RuntimeDebug, TypeInfo)] pub struct PoolInfo { /// Total shares amount pub total_shares: Share, diff --git a/tokens/src/lib.rs b/tokens/src/lib.rs index 3bb23e767..27ffc844e 100644 --- a/tokens/src/lib.rs +++ b/tokens/src/lib.rs @@ -114,7 +114,7 @@ impl OnDust for BurnDust /// A single lock on a balance. There can be many of these on an account and /// they "overlap", so the same balance is frozen by multiple locks. -#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] pub struct BalanceLock { /// An identifier for this lock. Only one lock may be in existence for /// each identifier. @@ -125,7 +125,7 @@ pub struct BalanceLock { } /// Store named reserved balance. -#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)] pub struct ReserveData { /// The identifier for the named reserve. pub id: ReserveIdentifier, @@ -134,7 +134,9 @@ pub struct ReserveData { } /// balance information for an account. -#[derive(Encode, Decode, Clone, PartialEq, Eq, Default, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[derive( + Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, Default, MaxEncodedLen, RuntimeDebug, TypeInfo, +)] pub struct AccountData { /// Non-reserved part of the balance. There may still be restrictions on /// this, but it is the total pool what may in principle be transferred, diff --git a/traits/src/auction.rs b/traits/src/auction.rs index 7096129f3..2531ef8da 100644 --- a/traits/src/auction.rs +++ b/traits/src/auction.rs @@ -1,5 +1,5 @@ use crate::Change; -use parity_scale_codec::{Decode, Encode, FullCodec, MaxEncodedLen}; +use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, FullCodec, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::{ traits::{AtLeast32Bit, Bounded, MaybeSerializeDeserialize}, @@ -13,7 +13,7 @@ use sp_std::{ /// Auction info. #[cfg_attr(feature = "std", derive(PartialEq, Eq))] -#[derive(Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +#[derive(Encode, Decode, DecodeWithMemTracking, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct AuctionInfo { /// Current bidder and bid price. pub bid: Option<(AccountId, Balance)>, diff --git a/traits/src/lib.rs b/traits/src/lib.rs index c59e7340b..53f2e05e8 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use impl_trait_for_tuples::impl_for_tuples; -use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use sp_runtime::{DispatchResult, RuntimeDebug}; use sp_std::{ cmp::{Eq, PartialEq}, @@ -60,7 +60,7 @@ pub trait CombineData { } /// Indicate if should change a value -#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] +#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub enum Change { /// No change. NoChange, @@ -68,7 +68,7 @@ pub enum Change { NewValue(Value), } -#[derive(Encode, Decode, RuntimeDebug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)] +#[derive(Encode, Decode, DecodeWithMemTracking, RuntimeDebug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct TimestampedValue { pub value: Value, diff --git a/xtokens/src/mock/mod.rs b/xtokens/src/mock/mod.rs index 2da76c071..2bcdc5490 100644 --- a/xtokens/src/mock/mod.rs +++ b/xtokens/src/mock/mod.rs @@ -26,6 +26,7 @@ pub const CHARLIE: AccountId32 = AccountId32::new([2u8; 32]); #[derive( Encode, Decode, + DecodeWithMemTracking, Eq, PartialEq, Copy, @@ -36,7 +37,7 @@ pub const CHARLIE: AccountId32 = AccountId32::new([2u8; 32]); parity_scale_codec::MaxEncodedLen, TypeInfo, )] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize, DecodeWithMemTracking))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum CurrencyId { /// Relay chain token. R, From b115390ad7d68aaa8bf0d0c419401efa83d41327 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Tue, 5 Aug 2025 09:05:33 +0800 Subject: [PATCH 2/6] fix clippy --- payments/src/types.rs | 5 ++++- rewards/src/lib.rs | 7 ++++++- traits/src/lib.rs | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/payments/src/types.rs b/payments/src/types.rs index 06c87e9d6..da6091d06 100644 --- a/payments/src/types.rs +++ b/payments/src/types.rs @@ -117,7 +117,10 @@ pub enum Task { /// The details of a scheduled task #[derive(PartialEq, Eq, Clone, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen)] -pub struct ScheduledTask { +pub struct ScheduledTask