Skip to content

Commit 087341c

Browse files
committed
implement DecodeWithMemTracking for frame pallets
paritytech/polkadot-sdk#7598
1 parent abab6e6 commit 087341c

File tree

1 file changed

+122
-15
lines changed

1 file changed

+122
-15
lines changed

pallets/nfts/src/types.rs

Lines changed: 122 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
use alloc::{vec, vec::Vec};
2121

22-
use codec::EncodeLike;
22+
use codec::{DecodeWithMemTracking, EncodeLike};
2323
use enumflags2::{bitflags, BitFlags};
2424
use frame_support::{
2525
pallet_prelude::{BoundedVec, MaxEncodedLen},
@@ -113,7 +113,18 @@ pub struct CollectionDetails<AccountId, DepositBalance> {
113113
}
114114

115115
/// Witness data for the destroy transactions.
116-
#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
116+
#[derive(
117+
Copy,
118+
Clone,
119+
Encode,
120+
Decode,
121+
DecodeWithMemTracking,
122+
Eq,
123+
PartialEq,
124+
RuntimeDebug,
125+
TypeInfo,
126+
MaxEncodedLen,
127+
)]
117128
pub struct DestroyWitness {
118129
/// The total number of items in this collection that have outstanding item metadata.
119130
#[codec(compact)]
@@ -137,7 +148,9 @@ impl<AccountId, DepositBalance> CollectionDetails<AccountId, DepositBalance> {
137148
}
138149

139150
/// Witness data for items mint transactions.
140-
#[derive(Clone, Encode, Decode, Default, Eq, PartialEq, RuntimeDebug, TypeInfo)]
151+
#[derive(
152+
Clone, Encode, Decode, DecodeWithMemTracking, Default, Eq, PartialEq, RuntimeDebug, TypeInfo,
153+
)]
141154
pub struct MintWitness<ItemId, Balance> {
142155
/// Provide the id of the item in a required collection.
143156
pub owned_item: Option<ItemId>,
@@ -196,7 +209,17 @@ pub struct ItemMetadata<Deposit, StringLimit: Get<u32>> {
196209
}
197210

198211
/// Information about the tip.
199-
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
212+
#[derive(
213+
Clone,
214+
Encode,
215+
Decode,
216+
DecodeWithMemTracking,
217+
Eq,
218+
PartialEq,
219+
RuntimeDebug,
220+
TypeInfo,
221+
MaxEncodedLen,
222+
)]
200223
pub struct ItemTip<CollectionId, ItemId, AccountId, Amount> {
201224
/// The collection of the item.
202225
pub collection: CollectionId,
@@ -240,7 +263,17 @@ pub struct ItemMetadataDeposit<DepositBalance, AccountId> {
240263
}
241264

242265
/// Specifies whether the tokens will be sent or received.
243-
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
266+
#[derive(
267+
Clone,
268+
Encode,
269+
Decode,
270+
DecodeWithMemTracking,
271+
Eq,
272+
PartialEq,
273+
RuntimeDebug,
274+
TypeInfo,
275+
MaxEncodedLen,
276+
)]
244277
pub enum PriceDirection {
245278
/// Tokens will be sent.
246279
Send,
@@ -249,7 +282,17 @@ pub enum PriceDirection {
249282
}
250283

251284
/// Holds the details about the price.
252-
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
285+
#[derive(
286+
Clone,
287+
Encode,
288+
Decode,
289+
DecodeWithMemTracking,
290+
Eq,
291+
PartialEq,
292+
RuntimeDebug,
293+
TypeInfo,
294+
MaxEncodedLen,
295+
)]
253296
pub struct PriceWithDirection<Amount> {
254297
/// An amount.
255298
pub amount: Amount,
@@ -297,11 +340,25 @@ impl CollectionSettings {
297340
}
298341

299342
impl_codec_bitflags!(CollectionSettings, u64, CollectionSetting);
343+
// We can implement `DecodeWithMemTracking` for `CollectionSettings`
344+
// since `u64` also implements `DecodeWithMemTracking`.
345+
impl DecodeWithMemTracking for CollectionSettings {}
300346

301347
/// Mint type. Can the NFT be create by anyone, or only the creator of the collection,
302348
/// or only by wallets that already hold an NFT from a certain collection?
303349
/// The ownership of a privately minted NFT is still publicly visible.
304-
#[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
350+
#[derive(
351+
Clone,
352+
Copy,
353+
Encode,
354+
Decode,
355+
DecodeWithMemTracking,
356+
Eq,
357+
PartialEq,
358+
RuntimeDebug,
359+
TypeInfo,
360+
MaxEncodedLen,
361+
)]
305362
pub enum MintType<CollectionId> {
306363
/// Only an `Issuer` could mint items.
307364
Issuer,
@@ -312,7 +369,18 @@ pub enum MintType<CollectionId> {
312369
}
313370

314371
/// Holds the information about minting.
315-
#[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
372+
#[derive(
373+
Clone,
374+
Copy,
375+
Encode,
376+
Decode,
377+
DecodeWithMemTracking,
378+
Eq,
379+
PartialEq,
380+
RuntimeDebug,
381+
TypeInfo,
382+
MaxEncodedLen,
383+
)]
316384
pub struct MintSettings<Price, BlockNumber, CollectionId> {
317385
/// Whether anyone can mint or if minters are restricted to some subset.
318386
pub mint_type: MintType<CollectionId>,
@@ -340,7 +408,15 @@ impl<Price, BlockNumber, CollectionId> Default for MintSettings<Price, BlockNumb
340408

341409
/// Attribute namespaces for non-fungible tokens.
342410
#[derive(
343-
Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, scale_info::TypeInfo, MaxEncodedLen,
411+
Clone,
412+
Encode,
413+
Decode,
414+
DecodeWithMemTracking,
415+
Eq,
416+
PartialEq,
417+
RuntimeDebug,
418+
scale_info::TypeInfo,
419+
MaxEncodedLen,
344420
)]
345421
pub enum AttributeNamespace<AccountId> {
346422
/// An attribute was set by the pallet.
@@ -354,14 +430,24 @@ pub enum AttributeNamespace<AccountId> {
354430
}
355431

356432
/// A witness data to cancel attributes approval operation.
357-
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
433+
#[derive(Clone, Encode, Decode, DecodeWithMemTracking, Eq, PartialEq, RuntimeDebug, TypeInfo)]
358434
pub struct CancelAttributesApprovalWitness {
359435
/// An amount of attributes previously created by account.
360436
pub account_attributes: u32,
361437
}
362438

363439
/// A list of possible pallet-level attributes.
364-
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
440+
#[derive(
441+
Clone,
442+
Encode,
443+
Decode,
444+
DecodeWithMemTracking,
445+
Eq,
446+
PartialEq,
447+
RuntimeDebug,
448+
TypeInfo,
449+
MaxEncodedLen,
450+
)]
365451
pub enum PalletAttributes<CollectionId> {
366452
/// Marks an item as being used in order to claim another item.
367453
UsedToClaim(CollectionId),
@@ -371,7 +457,16 @@ pub enum PalletAttributes<CollectionId> {
371457

372458
/// Collection's configuration.
373459
#[derive(
374-
Clone, Copy, Decode, Default, Encode, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo,
460+
Clone,
461+
Copy,
462+
Decode,
463+
DecodeWithMemTracking,
464+
Default,
465+
Encode,
466+
MaxEncodedLen,
467+
PartialEq,
468+
RuntimeDebug,
469+
TypeInfo,
375470
)]
376471
pub struct CollectionConfig<Price, BlockNumber, CollectionId> {
377472
/// Collection's settings.
@@ -436,10 +531,22 @@ impl ItemSettings {
436531
}
437532

438533
impl_codec_bitflags!(ItemSettings, u64, ItemSetting);
534+
// We can implement `DecodeWithMemTracking` for `ItemSettings`
535+
// since `u64` also implements `DecodeWithMemTracking`.
536+
impl DecodeWithMemTracking for ItemSettings {}
439537

440538
/// Item's configuration.
441539
#[derive(
442-
Encode, Decode, Default, PartialEq, RuntimeDebug, Clone, Copy, MaxEncodedLen, TypeInfo,
540+
Encode,
541+
Decode,
542+
DecodeWithMemTracking,
543+
Default,
544+
PartialEq,
545+
RuntimeDebug,
546+
Clone,
547+
Copy,
548+
MaxEncodedLen,
549+
TypeInfo,
443550
)]
444551
pub struct ItemConfig {
445552
/// Item's settings.
@@ -539,7 +646,7 @@ impl CollectionRoles {
539646
}
540647
impl_codec_bitflags!(CollectionRoles, u8, CollectionRole);
541648

542-
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
649+
#[derive(Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, TypeInfo)]
543650
pub struct PreSignedMint<CollectionId, ItemId, AccountId, Deadline, Balance> {
544651
/// A collection of the item to be minted.
545652
pub collection: CollectionId,
@@ -557,7 +664,7 @@ pub struct PreSignedMint<CollectionId, ItemId, AccountId, Deadline, Balance> {
557664
pub mint_price: Option<Balance>,
558665
}
559666

560-
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
667+
#[derive(Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, TypeInfo)]
561668
pub struct PreSignedAttributes<CollectionId, ItemId, AccountId, Deadline> {
562669
/// Collection's ID.
563670
pub collection: CollectionId,

0 commit comments

Comments
 (0)