staging_xcm_builder/unique_instances/mod.rs
1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
16
17//! XCM utilities to work with NFT-like entities (unique instances).
18//! The adapters and other utility types use the
19//! [`asset_ops`](frame_support::traits::tokens::asset_ops) traits.
20
21use sp_runtime::{traits::Convert, DispatchError};
22use xcm::latest::prelude::*;
23
24pub mod adapter;
25pub use adapter::*;
26
27/// An XCM ID for unique instances (non-fungible assets).
28pub type NonFungibleAsset = (AssetId, AssetInstance);
29
30/// Gets the XCM [AssetId] (i.e., extracts the NFT collection ID) from the [NonFungibleAsset].
31pub struct ExtractAssetId;
32impl Convert<NonFungibleAsset, AssetId> for ExtractAssetId {
33 fn convert((asset_id, _): NonFungibleAsset) -> AssetId {
34 asset_id
35 }
36}
37impl Convert<NonFungibleAsset, Result<AssetId, DispatchError>> for ExtractAssetId {
38 fn convert((asset_id, _): NonFungibleAsset) -> Result<AssetId, DispatchError> {
39 Ok(asset_id)
40 }
41}