git.delta.rocks / unique-network / refs/commits / 960c1089697d

difftreelog

refactor move RMRK rpc impl to proxy pallets

Daniel Shiposha2022-06-17parent: #a8df50d.patch.diff
in: master

6 files changed

modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
35pub 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;
3940
40pub type SelfWeightOf<T> = <T as Config>::WeightInfo;41pub type SelfWeightOf<T> = <T as Config>::WeightInfo;
addedpallets/proxy-rmrk-core/src/rpc.rsdiffbeforeafterboth

no changes

modifiedpallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth
3434
35#[cfg(feature = "runtime-benchmarks")]35#[cfg(feature = "runtime-benchmarks")]
36pub mod benchmarking;36pub mod benchmarking;
37pub mod rpc;
37pub mod weights;38pub mod weights;
3839
39pub type SelfWeightOf<T> = <T as Config>::WeightInfo;40pub type SelfWeightOf<T> = <T as Config>::WeightInfo;
addedpallets/proxy-rmrk-equip/src/rpc.rsdiffbeforeafterboth

no changes

modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
74 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};
8180
82// use pallet_contracts::weights::WeightInfo;81// use pallet_contracts::weights::WeightInfo;
1330 RmrkTheme1329 RmrkTheme
1331 > 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 }
13351334
1336 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;
1339
1340 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 };
1344
1345 let nfts_count = collection.total_supply();
1346
1347 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_count
1353 }))
1354 }1337 }
13551338
1356 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;
1360
1361 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 };
1365
1366 let nft_id = TokenId(nft_by_id);
1367 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(None); }
1368
1369 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)?;
1373
1374 RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(rmrk_collection, tok.0)
1375 }
1376 None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone())
1377 },
1378 None => return Ok(None)
1379 };
1380
1381 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 }
13891342
1390 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;
1393
1394 let cross_account_id = CrossAccountId::from_sub(account_id);
1395
1396 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 };
1400
1401 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::PendingNftAccept
1408 ).unwrap_or(true);
1409
1410 !is_pending
1411 })
1412 .map(|token| token.0)
1413 .collect();
1414
1415 Ok(tokens)
1416 }1345 }
14171346
1418 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)
1420
1421 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()); }
1427
1428 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::PendingNftAccept
1435 ).ok()?;
1436
1437 if is_pending {
1438 return None;
1439 }
1440
1441 let rmrk_child_collection = RmrkCore::rmrk_collection_id(
1442 child_collection
1443 ).ok()?;
1444
1445 Some(RmrkNftChild {
1446 collection_id: rmrk_child_collection,
1447 nft_id: child_token.0,
1448 })
1449 }).collect()
1450 )
1451 }1349 }
14521350
1453 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)
1455
1456 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 }
1463
1464 let properties = RmrkCore::filter_user_properties(
1465 collection_id,
1466 /* token_id = */ None,
1467 filter_keys,
1468 |key, value| RmrkPropertyInfo {
1469 key,
1470 value
1471 }
1472 )?;
1473
1474 Ok(properties)
1475 }1353 }
14761354
1477 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)
1479
1480 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);
1485
1486 if RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {
1487 return Ok(Vec::new());
1488 }
1489
1490 let properties = RmrkCore::filter_user_properties(
1491 collection_id,
1492 Some(token_id),
1493 filter_keys,
1494 |key, value| RmrkPropertyInfo {
1495 key,
1496 value
1497 }
1498 )?;
1499
1500 Ok(properties)
1501 }1357 }
15021358
1503 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;
1506
1507 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()); }
1512
1513 let nft_id = TokenId(nft_id);
1514 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(Vec::new()); }
1515
1516 let resources = <pallet_nonfungible::Pallet<Runtime>>::iterate_token_aux_properties(
1517 collection_id, nft_id, PropertyScope::Rmrk
1518 ).filter_map(|(_, value)| {
1519 let resource_info: RmrkResourceInfo = RmrkCore::decode_property(&value).ok()?;
1520
1521 Some(resource_info)
1522 }).collect();
1523
1524 Ok(resources)
1525 }1361 }
15261362
1527 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)
1529
1530 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); }
1535
1536 let nft_id = TokenId(nft_id);
1537 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(None); }
1538
1539 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 }
15471366
1548 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 };
1552
1553 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 };
1557
1558 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 }
15641370
1565 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;
1568
1569 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 };
1573
1574 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()?;
1578
1579 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 _ => None
1592 }
1593 })
1594 .collect();
1595
1596 Ok(parts)
1597 }1373 }
15981374
1599 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;
1602
1603 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 };
1607
1608 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()?;
1612
1613 match nft_type {
1614 NftType::Theme => RmrkCore::get_nft_property_decoded(collection_id, *token_id, RmrkProperty::ThemeName).ok(),
1615 _ => None
1616 }
1617 })
1618 .collect();
1619
1620 Ok(theme_names)
1621 }1377 }
16221378
1623 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;
1629
1630 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 };
1634
1635 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()?;
1639
1640 let name: RmrkString = RmrkCore::get_nft_property_decoded(
1641 collection_id, token_id, RmrkProperty::ThemeName
1642 ).ok()?;
1643
1644 if name == theme_name {
1645 Some((name, token_id))
1646 } else {
1647 None
1648 }
1649 });
1650
1651 let (name, theme_id) = match theme_info {
1652 Some((name, theme_id)) => (name, theme_id),
1653 None => return Ok(None)
1654 };
1655
1656 let properties = RmrkCore::filter_user_properties(
1657 collection_id,
1658 Some(theme_id),
1659 filter_keys,
1660 |key, value| RmrkThemeProperty {
1661 key,
1662 value
1663 }
1664 )?;
1665
1666 let inherit = RmrkCore::get_nft_property_decoded(
1667 collection_id,
1668 theme_id,
1669 RmrkProperty::ThemeInherit
1670 )?;
1671
1672 let theme = RmrkTheme {
1673 name,
1674 properties,
1675 inherit,
1676 };
1677
1678 Ok(Some(theme))
1679 }1381 }
1680 }1382 }
1681}1383}
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
74 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};
8180
82// use pallet_contracts::weights::WeightInfo;81// use pallet_contracts::weights::WeightInfo;
1330 RmrkTheme1329 RmrkTheme
1331 > 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 }
13351334
1336 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;
1339
1340 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 };
1344
1345 let nfts_count = collection.total_supply();
1346
1347 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_count
1353 }))
1354 }1337 }
13551338
1356 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;
1360
1361 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 };
1365
1366 let nft_id = TokenId(nft_by_id);
1367 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(None); }
1368
1369 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)?;
1373
1374 RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(rmrk_collection, tok.0)
1375 }
1376 None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone())
1377 },
1378 None => return Ok(None)
1379 };
1380
1381 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 }
13891342
1390 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;
1393
1394 let cross_account_id = CrossAccountId::from_sub(account_id);
1395
1396 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 };
1400
1401 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::PendingNftAccept
1408 ).unwrap_or(true);
1409
1410 !is_pending
1411 })
1412 .map(|token| token.0)
1413 .collect();
1414
1415 Ok(tokens)
1416 }1345 }
14171346
1418 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)
1420
1421 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()); }
1427
1428 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::PendingNftAccept
1435 ).ok()?;
1436
1437 if is_pending {
1438 return None;
1439 }
1440
1441 let rmrk_child_collection = RmrkCore::rmrk_collection_id(
1442 child_collection
1443 ).ok()?;
1444
1445 Some(RmrkNftChild {
1446 collection_id: rmrk_child_collection,
1447 nft_id: child_token.0,
1448 })
1449 }).collect()
1450 )
1451 }1349 }
14521350
1453 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)
1455
1456 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 }
1463
1464 let properties = RmrkCore::filter_user_properties(
1465 collection_id,
1466 /* token_id = */ None,
1467 filter_keys,
1468 |key, value| RmrkPropertyInfo {
1469 key,
1470 value
1471 }
1472 )?;
1473
1474 Ok(properties)
1475 }1353 }
14761354
1477 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)
1479
1480 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);
1485
1486 if RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {
1487 return Ok(Vec::new());
1488 }
1489
1490 let properties = RmrkCore::filter_user_properties(
1491 collection_id,
1492 Some(token_id),
1493 filter_keys,
1494 |key, value| RmrkPropertyInfo {
1495 key,
1496 value
1497 }
1498 )?;
1499
1500 Ok(properties)
1501 }1357 }
15021358
1503 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;
1506
1507 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()); }
1512
1513 let nft_id = TokenId(nft_id);
1514 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(Vec::new()); }
1515
1516 let resources = <pallet_nonfungible::Pallet<Runtime>>::iterate_token_aux_properties(
1517 collection_id, nft_id, PropertyScope::Rmrk
1518 ).filter_map(|(_, value)| {
1519 let resource_info: RmrkResourceInfo = RmrkCore::decode_property(&value).ok()?;
1520
1521 Some(resource_info)
1522 }).collect();
1523
1524 Ok(resources)
1525 }1361 }
15261362
1527 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)
1529
1530 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); }
1535
1536 let nft_id = TokenId(nft_id);
1537 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(None); }
1538
1539 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 }
15471366
1548 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 };
1552
1553 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 };
1557
1558 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 }
15641370
1565 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;
1568
1569 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 };
1573
1574 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()?;
1578
1579 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 _ => None
1592 }
1593 })
1594 .collect();
1595
1596 Ok(parts)
1597 }1373 }
15981374
1599 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;
1602
1603 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 };
1607
1608 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()?;
1612
1613 match nft_type {
1614 NftType::Theme => RmrkCore::get_nft_property_decoded(collection_id, *token_id, RmrkProperty::ThemeName).ok(),
1615 _ => None
1616 }
1617 })
1618 .collect();
1619
1620 Ok(theme_names)
1621 }1377 }
16221378
1623 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;
1629
1630 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 };
1634
1635 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()?;
1639
1640 let name: RmrkString = RmrkCore::get_nft_property_decoded(
1641 collection_id, token_id, RmrkProperty::ThemeName
1642 ).ok()?;
1643
1644 if name == theme_name {
1645 Some((name, token_id))
1646 } else {
1647 None
1648 }
1649 });
1650
1651 let (name, theme_id) = match theme_info {
1652 Some((name, theme_id)) => (name, theme_id),
1653 None => return Ok(None)
1654 };
1655
1656 let properties = RmrkCore::filter_user_properties(
1657 collection_id,
1658 Some(theme_id),
1659 filter_keys,
1660 |key, value| RmrkThemeProperty {
1661 key,
1662 value
1663 }
1664 )?;
1665
1666 let inherit = RmrkCore::get_nft_property_decoded(
1667 collection_id,
1668 theme_id,
1669 RmrkProperty::ThemeInherit
1670 )?;
1671
1672 let theme = RmrkTheme {
1673 name,
1674 properties,
1675 inherit,
1676 };
1677
1678 Ok(Some(theme))
1679 }1381 }
1680 }1382 }
1681}1383}