git.delta.rocks / unique-network / refs/commits / 2840b3d211f1

difftreelog

feat tokenId -> reserve asset instance mapping

Daniel Shiposha2023-11-01parent: #0fb6e3f.patch.diff
in: master

1 file changed

modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
126 QueryKind = OptionQuery,126 QueryKind = OptionQuery,
127 >;127 >;
128
129 /// The correponding reserve NFT of a token ID
130 #[pallet::storage]
131 #[pallet::getter(fn token_id_to_foreign_reserve_asset_instance)]
132 pub type TokenIdToForeignReserveAssetInstance<T: Config> = StorageDoubleMap<
133 Hasher1 = Twox64Concat,
134 Key1 = CollectionId,
135 Hasher2 = Twox64Concat,
136 Key2 = TokenId,
137 Value = staging_xcm::v3::AssetInstance,
138 QueryKind = OptionQuery,
139 >;
128140
129 #[pallet::pallet]141 #[pallet::pallet]
130 pub struct Pallet<T>(_);142 pub struct Pallet<T>(_);
279 .ok_or_else(|| XcmExecutorError::AssetIdConversionFailed.into())291 .ok_or_else(|| XcmExecutorError::AssetIdConversionFailed.into())
280 }292 }
281293
282 /// Converts an XCM asset instance to the Unique Network's token ID.294 /// Converts an XCM asset instance of local collection to the Unique Network's token ID.
283 ///295 ///
284 /// The asset instance corresponds to the Unique Network's token ID if it is in the following format:296 /// The asset instance corresponds to the Unique Network's token ID if it is in the following format:
285 /// `AssetInstance::Index(<token ID>)`.297 /// `AssetInstance::Index(<token ID>)`.
286 ///298 ///
287 /// If the asset instance is not in the valid format or the `<token ID>` can't fit into the valid token ID,299 /// If the asset instance is not in the valid format or the `<token ID>` can't fit into the valid token ID,
288 /// the `AssetNotFound` error will be returned.300 /// the `AssetNotFound` error will be returned.
289 fn native_asset_instance_to_token_id(301 fn local_asset_instance_to_token_id(
290 asset_instance: &AssetInstance,302 asset_instance: &AssetInstance,
291 ) -> Result<TokenId, XcmError> {303 ) -> Result<TokenId, XcmError> {
292 match asset_instance {304 match asset_instance {
318 asset_instance,330 asset_instance,
319 ))331 ))
320 } else {332 } else {
321 Self::native_asset_instance_to_token_id(asset_instance).map(Some)333 Self::local_asset_instance_to_token_id(asset_instance).map(Some)
322 }334 }
323 }335 }
324336
353 derivative_token_id,365 derivative_token_id,
354 );366 );
367
368 <TokenIdToForeignReserveAssetInstance<T>>::insert(
369 collection_id,
370 derivative_token_id,
371 asset_instance,
372 );
355373
356 Ok(())374 Ok(())
357 }375 }
399 let amount = 1;417 let amount = 1;
400 xcm_ext418 xcm_ext
401 .transfer_item(depositor, &from, &to, token_id, amount, &ZeroBudget)419 .transfer_item(depositor, &from, &to, token_id, amount, &ZeroBudget)
402 .map_err(|_| XcmError::FailedToTransactAsset("nonfungible item withdraw failed"))?;420 .map_err(|_| XcmError::FailedToTransactAsset("non-fungible item withdraw failed"))?;
403421
404 Ok(())422 Ok(())
405 }423 }
519 .ok_or(XcmError::AssetNotFound)?;537 .ok_or(XcmError::AssetNotFound)?;
520538
521 amount = 1;539 amount = 1;
522 map_error = |_| XcmError::FailedToTransactAsset("nonfungible item transfer failed")540 map_error = |_| XcmError::FailedToTransactAsset("non-fungible item transfer failed")
523 }541 }
524 }542 }
525543