difftreelog
refactor move RMRK rpc impl to proxy pallets
in: master
6 files changed
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth35pub mod benchmarking;35pub mod benchmarking;36pub mod misc;36pub mod misc;37pub mod property;37pub mod property;38pub mod rpc;38pub mod weights;39pub mod weights;394040pub type SelfWeightOf<T> = <T as Config>::WeightInfo;41pub type SelfWeightOf<T> = <T as Config>::WeightInfo;pallets/proxy-rmrk-core/src/rpc.rsdiffbeforeafterbothno changes
pallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth343435#[cfg(feature = "runtime-benchmarks")]35#[cfg(feature = "runtime-benchmarks")]36pub mod benchmarking;36pub mod benchmarking;37pub mod rpc;37pub mod weights;38pub mod weights;383939pub type SelfWeightOf<T> = <T as Config>::WeightInfo;40pub type SelfWeightOf<T> = <T as Config>::WeightInfo;pallets/proxy-rmrk-equip/src/rpc.rsdiffbeforeafterbothno changes
runtime/opal/src/lib.rsdiffbeforeafterboth74 CollectionStats, RpcCollection,74 CollectionStats, RpcCollection,75 mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},75 mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},76 TokenChild, RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo,76 TokenChild, RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo,77 RmrkBaseInfo, RmrkPartType, RmrkTheme, RmrkThemeName, RmrkThemeProperty, RmrkCollectionId,77 RmrkBaseInfo, RmrkPartType, RmrkTheme, RmrkThemeName, RmrkCollectionId, RmrkNftId,78 RmrkNftId, RmrkAccountIdOrCollectionNftTuple, RmrkNftChild, RmrkPropertyKey, RmrkResourceId,78 RmrkNftChild, RmrkPropertyKey, RmrkResourceId, RmrkBaseId,79 RmrkBaseId, RmrkFixedPart, RmrkSlotPart, RmrkString,80};79};818082// use pallet_contracts::weights::WeightInfo;81// use pallet_contracts::weights::WeightInfo;1330 RmrkTheme1329 RmrkTheme1331 > for Runtime {1330 > for Runtime {1332 fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {1331 fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {1333 Ok(RmrkCore::last_collection_idx())1332 pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>()1334 }1333 }133513341336 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {1335 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {1337 use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};1336 pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id)1338 use pallet_common::CommonCollectionOperations;13391340 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {1341 Ok(c) => c,1342 Err(_) => return Ok(None),1343 };13441345 let nfts_count = collection.total_supply();13461347 Ok(Some(RmrkCollectionInfo {1348 issuer: collection.owner.clone(),1349 metadata: RmrkCore::get_collection_property_decoded(collection_id, RmrkProperty::Metadata)?,1350 max: collection.limits.token_limit,1351 symbol: RmrkCore::rebind(&collection.token_prefix)?,1352 nfts_count1353 }))1354 }1337 }135513381356 fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {1339 fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {1357 use up_data_structs::mapping::TokenAddressMapping;1358 use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};1340 pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id)1359 use pallet_common::CommonCollectionOperations;13601361 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {1362 Ok(c) => c,1363 Err(_) => return Ok(None),1364 };13651366 let nft_id = TokenId(nft_by_id);1367 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(None); }13681369 let owner = match collection.token_owner(nft_id) {1370 Some(owner) => match <Runtime as pallet_common::Config>::CrossTokenAddressMapping::address_to_token(&owner) {1371 Some((col, tok)) => {1372 let rmrk_collection = RmrkCore::rmrk_collection_id(col)?;13731374 RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(rmrk_collection, tok.0)1375 }1376 None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone())1377 },1378 None => return Ok(None)1379 };13801381 Ok(Some(RmrkInstanceInfo {1382 owner: owner,1383 royalty: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::RoyaltyInfo)?,1384 metadata: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Metadata)?,1385 equipped: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Equipped)?,1386 pending: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::PendingNftAccept)?,1387 }))1388 }1341 }138913421390 fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {1343 fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {1391 use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};1344 pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id)1392 use pallet_common::CommonCollectionOperations;13931394 let cross_account_id = CrossAccountId::from_sub(account_id);13951396 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {1397 Ok(c) => c,1398 Err(_) => return Ok(Vec::new()),1399 };14001401 let tokens = collection.account_tokens(cross_account_id)1402 .into_iter()1403 .filter(|token| {1404 let is_pending = RmrkCore::get_nft_property_decoded(1405 collection_id,1406 *token,1407 RmrkProperty::PendingNftAccept1408 ).unwrap_or(true);14091410 !is_pending1411 })1412 .map(|token| token.0)1413 .collect();14141415 Ok(tokens)1416 }1345 }141713461418 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {1347 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {1419 use pallet_proxy_rmrk_core::RmrkProperty;1348 pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id)14201421 let collection_id = match RmrkCore::unique_collection_id(collection_id) {1422 Ok(id) => id,1423 Err(_) => return Ok(Vec::new())1424 };1425 let nft_id = TokenId(nft_id);1426 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(Vec::new()); }14271428 Ok(1429 pallet_nonfungible::TokenChildren::<Runtime>::iter_prefix((collection_id, nft_id))1430 .filter_map(|((child_collection, child_token), _)| {1431 let is_pending = RmrkCore::get_nft_property_decoded(1432 child_collection,1433 child_token,1434 RmrkProperty::PendingNftAccept1435 ).ok()?;14361437 if is_pending {1438 return None;1439 }14401441 let rmrk_child_collection = RmrkCore::rmrk_collection_id(1442 child_collection1443 ).ok()?;14441445 Some(RmrkNftChild {1446 collection_id: rmrk_child_collection,1447 nft_id: child_token.0,1448 })1449 }).collect()1450 )1451 }1349 }145213501453 fn collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {1351 fn collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {1454 use pallet_proxy_rmrk_core::misc::CollectionType;1352 pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys)14551456 let collection_id = match RmrkCore::unique_collection_id(collection_id) {1457 Ok(id) => id,1458 Err(_) => return Ok(Vec::new())1459 };1460 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() {1461 return Ok(Vec::new());1462 }14631464 let properties = RmrkCore::filter_user_properties(1465 collection_id,1466 /* token_id = */ None,1467 filter_keys,1468 |key, value| RmrkPropertyInfo {1469 key,1470 value1471 }1472 )?;14731474 Ok(properties)1475 }1353 }147613541477 fn nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {1355 fn nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {1478 use pallet_proxy_rmrk_core::misc::NftType;1356 pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys)14791480 let collection_id = match RmrkCore::unique_collection_id(collection_id) {1481 Ok(id) => id,1482 Err(_) => return Ok(Vec::new())1483 };1484 let token_id = TokenId(nft_id);14851486 if RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {1487 return Ok(Vec::new());1488 }14891490 let properties = RmrkCore::filter_user_properties(1491 collection_id,1492 Some(token_id),1493 filter_keys,1494 |key, value| RmrkPropertyInfo {1495 key,1496 value1497 }1498 )?;14991500 Ok(properties)1501 }1357 }150213581503 fn nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {1359 fn nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {1504 use pallet_proxy_rmrk_core::misc::{CollectionType, NftType};1360 pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id)1505 use up_data_structs::PropertyScope;15061507 let collection_id = match RmrkCore::unique_collection_id(collection_id) {1508 Ok(id) => id,1509 Err(_) => return Ok(Vec::new())1510 };1511 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() { return Ok(Vec::new()); }15121513 let nft_id = TokenId(nft_id);1514 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(Vec::new()); }15151516 let resources = <pallet_nonfungible::Pallet<Runtime>>::iterate_token_aux_properties(1517 collection_id, nft_id, PropertyScope::Rmrk1518 ).filter_map(|(_, value)| {1519 let resource_info: RmrkResourceInfo = RmrkCore::decode_property(&value).ok()?;15201521 Some(resource_info)1522 }).collect();15231524 Ok(resources)1525 }1361 }152613621527 fn nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Result<Option<u32>, DispatchError> {1363 fn nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Result<Option<u32>, DispatchError> {1528 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType}};1364 pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id)15291530 let collection_id = match RmrkCore::unique_collection_id(collection_id) {1531 Ok(id) => id,1532 Err(_) => return Ok(None)1533 };1534 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() { return Ok(None); }15351536 let nft_id = TokenId(nft_id);1537 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(None); }15381539 let priorities: Vec<_> = RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::ResourcePriorities)?;1540 Ok(1541 priorities.into_iter()1542 .enumerate()1543 .find(|(_, id)| *id == resource_id)1544 .map(|(priority, _): (usize, RmrkResourceId)| priority as u32)1545 )1546 }1365 }154713661548 fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {1367 fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {1549 use pallet_proxy_rmrk_core::{1368 pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id)1550 RmrkProperty, misc::{CollectionType},1551 };15521553 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {1554 Ok(c) => c,1555 Err(_) => return Ok(None),1556 };15571558 Ok(Some(RmrkBaseInfo {1559 issuer: collection.owner.clone(),1560 base_type: RmrkCore::get_collection_property_decoded(collection_id, RmrkProperty::BaseType)?,1561 symbol: RmrkCore::rebind(&collection.token_prefix)?,1562 }))1563 }1369 }156413701565 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {1371 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {1566 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType}};1372 pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id)1567 use pallet_common::CommonCollectionOperations;15681569 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {1570 Ok(c) => c,1571 Err(_) => return Ok(Vec::new()),1572 };15731574 let parts = collection.collection_tokens()1575 .into_iter()1576 .filter_map(|token_id| {1577 let nft_type = RmrkCore::get_nft_type(collection_id, token_id).ok()?;15781579 match nft_type {1580 NftType::FixedPart => Some(RmrkPartType::FixedPart(RmrkFixedPart {1581 id: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ExternalPartId).ok()?,1582 src: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::Src).ok()?,1583 z: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ZIndex).ok()?,1584 })),1585 NftType::SlotPart => Some(RmrkPartType::SlotPart(RmrkSlotPart {1586 id: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ExternalPartId).ok()?,1587 src: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::Src).ok()?,1588 z: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ZIndex).ok()?,1589 equippable: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::EquippableList).ok()?,1590 })),1591 _ => None1592 }1593 })1594 .collect();15951596 Ok(parts)1597 }1373 }159813741599 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {1375 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {1600 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{NftType, CollectionType}};1376 pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id)1601 use pallet_common::CommonCollectionOperations;16021603 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {1604 Ok(c) => c,1605 Err(_) => return Ok(Vec::new()),1606 };16071608 let theme_names = collection.collection_tokens()1609 .iter()1610 .filter_map(|token_id| {1611 let nft_type = RmrkCore::get_nft_type(collection_id, *token_id).ok()?;16121613 match nft_type {1614 NftType::Theme => RmrkCore::get_nft_property_decoded(collection_id, *token_id, RmrkProperty::ThemeName).ok(),1615 _ => None1616 }1617 })1618 .collect();16191620 Ok(theme_names)1621 }1377 }162213781623 fn theme(base_id: RmrkBaseId, theme_name: RmrkThemeName, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Option<RmrkTheme>, DispatchError> {1379 fn theme(base_id: RmrkBaseId, theme_name: RmrkThemeName, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Option<RmrkTheme>, DispatchError> {1624 use pallet_proxy_rmrk_core::{1380 pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys)1625 RmrkProperty,1626 misc::{CollectionType, NftType}1627 };1628 use pallet_common::CommonCollectionOperations;16291630 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {1631 Ok(c) => c,1632 Err(_) => return Ok(None),1633 };16341635 let theme_info = collection.collection_tokens()1636 .into_iter()1637 .find_map(|token_id| {1638 RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Theme).ok()?;16391640 let name: RmrkString = RmrkCore::get_nft_property_decoded(1641 collection_id, token_id, RmrkProperty::ThemeName1642 ).ok()?;16431644 if name == theme_name {1645 Some((name, token_id))1646 } else {1647 None1648 }1649 });16501651 let (name, theme_id) = match theme_info {1652 Some((name, theme_id)) => (name, theme_id),1653 None => return Ok(None)1654 };16551656 let properties = RmrkCore::filter_user_properties(1657 collection_id,1658 Some(theme_id),1659 filter_keys,1660 |key, value| RmrkThemeProperty {1661 key,1662 value1663 }1664 )?;16651666 let inherit = RmrkCore::get_nft_property_decoded(1667 collection_id,1668 theme_id,1669 RmrkProperty::ThemeInherit1670 )?;16711672 let theme = RmrkTheme {1673 name,1674 properties,1675 inherit,1676 };16771678 Ok(Some(theme))1679 }1381 }1680 }1382 }1681}1383}runtime/quartz/src/lib.rsdiffbeforeafterboth74 CollectionStats, RpcCollection,74 CollectionStats, RpcCollection,75 mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},75 mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},76 TokenChild, RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo,76 TokenChild, RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo,77 RmrkBaseInfo, RmrkPartType, RmrkTheme, RmrkThemeName, RmrkThemeProperty, RmrkCollectionId,77 RmrkBaseInfo, RmrkPartType, RmrkTheme, RmrkThemeName, RmrkCollectionId, RmrkNftId,78 RmrkNftId, RmrkAccountIdOrCollectionNftTuple, RmrkNftChild, RmrkPropertyKey, RmrkResourceId,78 RmrkNftChild, RmrkPropertyKey, RmrkResourceId, RmrkBaseId,79 RmrkBaseId, RmrkFixedPart, RmrkSlotPart, RmrkString,80};79};818082// use pallet_contracts::weights::WeightInfo;81// use pallet_contracts::weights::WeightInfo;1330 RmrkTheme1329 RmrkTheme1331 > for Runtime {1330 > for Runtime {1332 fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {1331 fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {1333 Ok(RmrkCore::last_collection_idx())1332 pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>()1334 }1333 }133513341336 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {1335 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {1337 use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};1336 pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id)1338 use pallet_common::CommonCollectionOperations;13391340 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {1341 Ok(c) => c,1342 Err(_) => return Ok(None),1343 };13441345 let nfts_count = collection.total_supply();13461347 Ok(Some(RmrkCollectionInfo {1348 issuer: collection.owner.clone(),1349 metadata: RmrkCore::get_collection_property_decoded(collection_id, RmrkProperty::Metadata)?,1350 max: collection.limits.token_limit,1351 symbol: RmrkCore::rebind(&collection.token_prefix)?,1352 nfts_count1353 }))1354 }1337 }135513381356 fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {1339 fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {1357 use up_data_structs::mapping::TokenAddressMapping;1358 use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};1340 pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id)1359 use pallet_common::CommonCollectionOperations;13601361 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {1362 Ok(c) => c,1363 Err(_) => return Ok(None),1364 };13651366 let nft_id = TokenId(nft_by_id);1367 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(None); }13681369 let owner = match collection.token_owner(nft_id) {1370 Some(owner) => match <Runtime as pallet_common::Config>::CrossTokenAddressMapping::address_to_token(&owner) {1371 Some((col, tok)) => {1372 let rmrk_collection = RmrkCore::rmrk_collection_id(col)?;13731374 RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(rmrk_collection, tok.0)1375 }1376 None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone())1377 },1378 None => return Ok(None)1379 };13801381 Ok(Some(RmrkInstanceInfo {1382 owner: owner,1383 royalty: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::RoyaltyInfo)?,1384 metadata: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Metadata)?,1385 equipped: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Equipped)?,1386 pending: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::PendingNftAccept)?,1387 }))1388 }1341 }138913421390 fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {1343 fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {1391 use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};1344 pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id)1392 use pallet_common::CommonCollectionOperations;13931394 let cross_account_id = CrossAccountId::from_sub(account_id);13951396 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {1397 Ok(c) => c,1398 Err(_) => return Ok(Vec::new()),1399 };14001401 let tokens = collection.account_tokens(cross_account_id)1402 .into_iter()1403 .filter(|token| {1404 let is_pending = RmrkCore::get_nft_property_decoded(1405 collection_id,1406 *token,1407 RmrkProperty::PendingNftAccept1408 ).unwrap_or(true);14091410 !is_pending1411 })1412 .map(|token| token.0)1413 .collect();14141415 Ok(tokens)1416 }1345 }141713461418 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {1347 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {1419 use pallet_proxy_rmrk_core::RmrkProperty;1348 pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id)14201421 let collection_id = match RmrkCore::unique_collection_id(collection_id) {1422 Ok(id) => id,1423 Err(_) => return Ok(Vec::new())1424 };1425 let nft_id = TokenId(nft_id);1426 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(Vec::new()); }14271428 Ok(1429 pallet_nonfungible::TokenChildren::<Runtime>::iter_prefix((collection_id, nft_id))1430 .filter_map(|((child_collection, child_token), _)| {1431 let is_pending = RmrkCore::get_nft_property_decoded(1432 child_collection,1433 child_token,1434 RmrkProperty::PendingNftAccept1435 ).ok()?;14361437 if is_pending {1438 return None;1439 }14401441 let rmrk_child_collection = RmrkCore::rmrk_collection_id(1442 child_collection1443 ).ok()?;14441445 Some(RmrkNftChild {1446 collection_id: rmrk_child_collection,1447 nft_id: child_token.0,1448 })1449 }).collect()1450 )1451 }1349 }145213501453 fn collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {1351 fn collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {1454 use pallet_proxy_rmrk_core::misc::CollectionType;1352 pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys)14551456 let collection_id = match RmrkCore::unique_collection_id(collection_id) {1457 Ok(id) => id,1458 Err(_) => return Ok(Vec::new())1459 };1460 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() {1461 return Ok(Vec::new());1462 }14631464 let properties = RmrkCore::filter_user_properties(1465 collection_id,1466 /* token_id = */ None,1467 filter_keys,1468 |key, value| RmrkPropertyInfo {1469 key,1470 value1471 }1472 )?;14731474 Ok(properties)1475 }1353 }147613541477 fn nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {1355 fn nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {1478 use pallet_proxy_rmrk_core::misc::NftType;1356 pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys)14791480 let collection_id = match RmrkCore::unique_collection_id(collection_id) {1481 Ok(id) => id,1482 Err(_) => return Ok(Vec::new())1483 };1484 let token_id = TokenId(nft_id);14851486 if RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {1487 return Ok(Vec::new());1488 }14891490 let properties = RmrkCore::filter_user_properties(1491 collection_id,1492 Some(token_id),1493 filter_keys,1494 |key, value| RmrkPropertyInfo {1495 key,1496 value1497 }1498 )?;14991500 Ok(properties)1501 }1357 }150213581503 fn nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {1359 fn nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {1504 use pallet_proxy_rmrk_core::misc::{CollectionType, NftType};1360 pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id)1505 use up_data_structs::PropertyScope;15061507 let collection_id = match RmrkCore::unique_collection_id(collection_id) {1508 Ok(id) => id,1509 Err(_) => return Ok(Vec::new())1510 };1511 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() { return Ok(Vec::new()); }15121513 let nft_id = TokenId(nft_id);1514 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(Vec::new()); }15151516 let resources = <pallet_nonfungible::Pallet<Runtime>>::iterate_token_aux_properties(1517 collection_id, nft_id, PropertyScope::Rmrk1518 ).filter_map(|(_, value)| {1519 let resource_info: RmrkResourceInfo = RmrkCore::decode_property(&value).ok()?;15201521 Some(resource_info)1522 }).collect();15231524 Ok(resources)1525 }1361 }152613621527 fn nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Result<Option<u32>, DispatchError> {1363 fn nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Result<Option<u32>, DispatchError> {1528 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType}};1364 pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id)15291530 let collection_id = match RmrkCore::unique_collection_id(collection_id) {1531 Ok(id) => id,1532 Err(_) => return Ok(None)1533 };1534 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() { return Ok(None); }15351536 let nft_id = TokenId(nft_id);1537 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(None); }15381539 let priorities: Vec<_> = RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::ResourcePriorities)?;1540 Ok(1541 priorities.into_iter()1542 .enumerate()1543 .find(|(_, id)| *id == resource_id)1544 .map(|(priority, _): (usize, RmrkResourceId)| priority as u32)1545 )1546 }1365 }154713661548 fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {1367 fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {1549 use pallet_proxy_rmrk_core::{1368 pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id)1550 RmrkProperty, misc::{CollectionType},1551 };15521553 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {1554 Ok(c) => c,1555 Err(_) => return Ok(None),1556 };15571558 Ok(Some(RmrkBaseInfo {1559 issuer: collection.owner.clone(),1560 base_type: RmrkCore::get_collection_property_decoded(collection_id, RmrkProperty::BaseType)?,1561 symbol: RmrkCore::rebind(&collection.token_prefix)?,1562 }))1563 }1369 }156413701565 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {1371 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {1566 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType}};1372 pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id)1567 use pallet_common::CommonCollectionOperations;15681569 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {1570 Ok(c) => c,1571 Err(_) => return Ok(Vec::new()),1572 };15731574 let parts = collection.collection_tokens()1575 .into_iter()1576 .filter_map(|token_id| {1577 let nft_type = RmrkCore::get_nft_type(collection_id, token_id).ok()?;15781579 match nft_type {1580 NftType::FixedPart => Some(RmrkPartType::FixedPart(RmrkFixedPart {1581 id: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ExternalPartId).ok()?,1582 src: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::Src).ok()?,1583 z: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ZIndex).ok()?,1584 })),1585 NftType::SlotPart => Some(RmrkPartType::SlotPart(RmrkSlotPart {1586 id: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ExternalPartId).ok()?,1587 src: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::Src).ok()?,1588 z: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ZIndex).ok()?,1589 equippable: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::EquippableList).ok()?,1590 })),1591 _ => None1592 }1593 })1594 .collect();15951596 Ok(parts)1597 }1373 }159813741599 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {1375 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {1600 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{NftType, CollectionType}};1376 pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id)1601 use pallet_common::CommonCollectionOperations;16021603 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {1604 Ok(c) => c,1605 Err(_) => return Ok(Vec::new()),1606 };16071608 let theme_names = collection.collection_tokens()1609 .iter()1610 .filter_map(|token_id| {1611 let nft_type = RmrkCore::get_nft_type(collection_id, *token_id).ok()?;16121613 match nft_type {1614 NftType::Theme => RmrkCore::get_nft_property_decoded(collection_id, *token_id, RmrkProperty::ThemeName).ok(),1615 _ => None1616 }1617 })1618 .collect();16191620 Ok(theme_names)1621 }1377 }162213781623 fn theme(base_id: RmrkBaseId, theme_name: RmrkThemeName, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Option<RmrkTheme>, DispatchError> {1379 fn theme(base_id: RmrkBaseId, theme_name: RmrkThemeName, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Option<RmrkTheme>, DispatchError> {1624 use pallet_proxy_rmrk_core::{1380 pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys)1625 RmrkProperty,1626 misc::{CollectionType, NftType}1627 };1628 use pallet_common::CommonCollectionOperations;16291630 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {1631 Ok(c) => c,1632 Err(_) => return Ok(None),1633 };16341635 let theme_info = collection.collection_tokens()1636 .into_iter()1637 .find_map(|token_id| {1638 RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Theme).ok()?;16391640 let name: RmrkString = RmrkCore::get_nft_property_decoded(1641 collection_id, token_id, RmrkProperty::ThemeName1642 ).ok()?;16431644 if name == theme_name {1645 Some((name, token_id))1646 } else {1647 None1648 }1649 });16501651 let (name, theme_id) = match theme_info {1652 Some((name, theme_id)) => (name, theme_id),1653 None => return Ok(None)1654 };16551656 let properties = RmrkCore::filter_user_properties(1657 collection_id,1658 Some(theme_id),1659 filter_keys,1660 |key, value| RmrkThemeProperty {1661 key,1662 value1663 }1664 )?;16651666 let inherit = RmrkCore::get_nft_property_decoded(1667 collection_id,1668 theme_id,1669 RmrkProperty::ThemeInherit1670 )?;16711672 let theme = RmrkTheme {1673 name,1674 properties,1675 inherit,1676 };16771678 Ok(Some(theme))1679 }1381 }1680 }1382 }1681}1383}