1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Various basic types for use in the Uniques pallet.
use super::*;
use frame_support::{
pallet_prelude::{BoundedVec, MaxEncodedLen},
traits::Get,
};
use scale_info::TypeInfo;
/// A type alias for handling balance deposits.
pub(super) type DepositBalanceOf<T, I = ()> =
<<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
/// A type alias representing the details of a collection.
pub(super) type CollectionDetailsFor<T, I> =
CollectionDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>;
/// A type alias for the details of a single item.
pub(super) type ItemDetailsFor<T, I> =
ItemDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>;
/// A type alias to represent the price of an item.
pub(super) type ItemPrice<T, I = ()> =
<<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct CollectionDetails<AccountId, DepositBalance> {
/// Can change `owner`, `issuer`, `freezer` and `admin` accounts.
pub owner: AccountId,
/// Can mint tokens.
pub issuer: AccountId,
/// Can thaw tokens, force transfers and burn tokens from any account.
pub admin: AccountId,
/// Can freeze tokens.
pub freezer: AccountId,
/// The total balance deposited for the all storage associated with this collection.
/// Used by `destroy`.
pub total_deposit: DepositBalance,
/// If `true`, then no deposit is needed to hold items of this collection.
pub free_holding: bool,
/// The total number of outstanding items of this collection.
pub items: u32,
/// The total number of outstanding item metadata of this collection.
pub item_metadatas: u32,
/// The total number of attributes for this collection.
pub attributes: u32,
/// Whether the collection is frozen for non-admin transfers.
pub is_frozen: bool,
}
/// Witness data for the destroy transactions.
#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct DestroyWitness {
/// The total number of outstanding items of this collection.
#[codec(compact)]
pub items: u32,
/// The total number of items in this collection that have outstanding item metadata.
#[codec(compact)]
pub item_metadatas: u32,
#[codec(compact)]
/// The total number of attributes for this collection.
pub attributes: u32,
}
impl<AccountId, DepositBalance> CollectionDetails<AccountId, DepositBalance> {
pub fn destroy_witness(&self) -> DestroyWitness {
DestroyWitness {
items: self.items,
item_metadatas: self.item_metadatas,
attributes: self.attributes,
}
}
}
/// Information concerning the ownership of a single unique item.
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
pub struct ItemDetails<AccountId, DepositBalance> {
/// The owner of this item.
pub owner: AccountId,
/// The approved transferrer of this item, if one is set.
pub approved: Option<AccountId>,
/// Whether the item can be transferred or not.
pub is_frozen: bool,
/// The amount held in the pallet's default account for this item. Free-hold items will have
/// this as zero.
pub deposit: DepositBalance,
}
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
#[scale_info(skip_type_params(StringLimit))]
#[codec(mel_bound(DepositBalance: MaxEncodedLen))]
pub struct CollectionMetadata<DepositBalance, StringLimit: Get<u32>> {
/// The balance deposited for this metadata.
///
/// This pays for the data stored in this struct.
pub deposit: DepositBalance,
/// General information concerning this collection. Limited in length by `StringLimit`. This
/// will generally be either a JSON dump or the hash of some JSON which can be found on a
/// hash-addressable global publication system such as IPFS.
pub data: BoundedVec<u8, StringLimit>,
/// Whether the collection's metadata may be changed by a non Force origin.
pub is_frozen: bool,
}
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
#[scale_info(skip_type_params(StringLimit))]
#[codec(mel_bound(DepositBalance: MaxEncodedLen))]
pub struct ItemMetadata<DepositBalance, StringLimit: Get<u32>> {
/// The balance deposited for this metadata.
///
/// This pays for the data stored in this struct.
pub deposit: DepositBalance,
/// General information concerning this item. Limited in length by `StringLimit`. This will
/// generally be either a JSON dump or the hash of some JSON which can be found on a
/// hash-addressable global publication system such as IPFS.
pub data: BoundedVec<u8, StringLimit>,
/// Whether the item metadata may be changed by a non Force origin.
pub is_frozen: bool,
}