referrerpolicy=no-referrer-when-downgrade

pallet_nft_fractionalization/
types.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Various basic types for use in the Nft fractionalization pallet.
19
20use super::*;
21use codec::{Decode, Encode, MaxEncodedLen};
22use fungible::Inspect as FunInspect;
23use fungibles::Inspect;
24use scale_info::TypeInfo;
25
26pub type AssetIdOf<T> = <<T as Config>::Assets as Inspect<<T as SystemConfig>::AccountId>>::AssetId;
27pub type AssetBalanceOf<T> =
28	<<T as Config>::Assets as Inspect<<T as SystemConfig>::AccountId>>::Balance;
29pub type DepositOf<T> =
30	<<T as Config>::Currency as FunInspect<<T as SystemConfig>::AccountId>>::Balance;
31pub type AccountIdLookupOf<T> = <<T as SystemConfig>::Lookup as StaticLookup>::Source;
32
33/// Stores the details of a fractionalized item.
34#[derive(Decode, Encode, Default, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
35pub struct Details<AssetId, Fractions, Deposit, AccountId> {
36	/// Minted asset.
37	pub asset: AssetId,
38
39	/// Number of fractions minted.
40	pub fractions: Fractions,
41
42	/// Reserved deposit for creating a new asset.
43	pub deposit: Deposit,
44
45	/// Account that fractionalized an item.
46	pub asset_creator: AccountId,
47}
48
49/// Benchmark Helper
50#[cfg(feature = "runtime-benchmarks")]
51pub trait BenchmarkHelper<AssetId, CollectionId, ItemId> {
52	/// Returns an asset id from a given integer.
53	fn asset(id: u32) -> AssetId;
54	/// Returns a collection id from a given integer.
55	fn collection(id: u32) -> CollectionId;
56	/// Returns an nft id from a given integer.
57	fn nft(id: u32) -> ItemId;
58}
59
60#[cfg(feature = "runtime-benchmarks")]
61impl<AssetId, CollectionId, ItemId> BenchmarkHelper<AssetId, CollectionId, ItemId> for ()
62where
63	AssetId: From<u32>,
64	CollectionId: From<u32>,
65	ItemId: From<u32>,
66{
67	fn asset(id: u32) -> AssetId {
68		id.into()
69	}
70	fn collection(id: u32) -> CollectionId {
71		id.into()
72	}
73	fn nft(id: u32) -> ItemId {
74		id.into()
75	}
76}