difftreelog
cargo fmt
in: master
3 files changed
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -16,15 +16,13 @@
#![cfg_attr(not(feature = "std"), no_std)]
-use frame_support::{
- pallet_prelude::*,
- transactional,
- BoundedVec,
- dispatch::DispatchResult,
-};
+use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};
use frame_system::{pallet_prelude::*, ensure_signed};
use sp_runtime::{DispatchError, Permill, traits::StaticLookup};
-use sp_std::{vec::Vec, collections::{btree_set::BTreeSet, btree_map::BTreeMap}};
+use sp_std::{
+ vec::Vec,
+ collections::{btree_set::BTreeSet, btree_map::BTreeMap},
+};
use up_data_structs::{*, mapping::TokenAddressMapping};
use pallet_common::{
Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations,
@@ -500,7 +498,8 @@
collection_id,
nft_id,
RmrkProperty::PendingNftAccept
- )?.is_none(),
+ )?
+ .is_none(),
<Error<T>>::NoPermission
);
@@ -539,7 +538,7 @@
PropertyScope::Rmrk,
Self::rmrk_property::<Option<PendingTarget>>(
PendingNftAccept,
- &Some((target_collection_id, target_nft_id.into()))
+ &Some((target_collection_id, target_nft_id.into())),
)?,
)?;
@@ -642,7 +641,7 @@
let pending_target = Self::get_nft_property_decoded::<Option<PendingTarget>>(
collection_id,
nft_id,
- RmrkProperty::PendingNftAccept
+ RmrkProperty::PendingNftAccept,
)?;
if let Some(pending_target) = pending_target {
@@ -694,15 +693,16 @@
<Error<T>>::NoAvailableNftId
);
-
let pending_target = Self::get_nft_property_decoded::<Option<PendingTarget>>(
collection_id,
nft_id,
- RmrkProperty::PendingNftAccept
+ RmrkProperty::PendingNftAccept,
)?;
match pending_target {
- Some(pending_target) => Self::remove_pending_child(pending_target, (rmrk_collection_id, rmrk_nft_id))?,
+ Some(pending_target) => {
+ Self::remove_pending_child(pending_target, (rmrk_collection_id, rmrk_nft_id))?
+ }
None => return Err(<Error<T>>::CannotRejectNonPendingNft.into()),
}
@@ -995,14 +995,14 @@
|value| -> DispatchResult {
let mut bases: BasesMap = match value {
Some(value) => Self::decode_property(value)?,
- None => BasesMap::new()
+ None => BasesMap::new(),
};
-
+
*bases.entry(base_id).or_insert(0) += 1;
-
+
*value = Some(Self::encode_property(&bases)?);
Ok(())
- }
+ },
)?;
Self::deposit_event(Event::ResourceAdded {
@@ -1249,12 +1249,15 @@
)
}
- fn iterate_pending_children(collection_id: CollectionId, nft_id: TokenId) -> Result<impl Iterator<Item=PendingChild>, DispatchError> {
+ fn iterate_pending_children(
+ collection_id: CollectionId,
+ nft_id: TokenId,
+ ) -> Result<impl Iterator<Item = PendingChild>, DispatchError> {
let property = <PalletNft<T>>::token_aux_property((
collection_id,
nft_id,
PropertyScope::Rmrk,
- Self::rmrk_property_key(PendingChildren)?
+ Self::rmrk_property_key(PendingChildren)?,
));
let pending_children = match property {
@@ -1345,8 +1348,9 @@
collection_id,
nft_id,
scope,
- resource_id_key.clone()
- )).ok_or(<Error<T>>::ResourceDoesntExist)?;
+ resource_id_key.clone(),
+ ))
+ .ok_or(<Error<T>>::ResourceDoesntExist)?;
let resource_info: RmrkResourceInfo = Self::decode_property(&resource)?;
@@ -1392,7 +1396,7 @@
|value| -> DispatchResult {
let mut bases: BasesMap = match value {
Some(value) => Self::decode_property(value)?,
- None => BasesMap::new()
+ None => BasesMap::new(),
};
let remaining = bases.get(&base_id);
@@ -1405,7 +1409,7 @@
*value = Some(Self::encode_property(&bases)?);
Ok(())
- }
+ },
)
}
pallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/property.rs
+++ b/pallets/proxy-rmrk-core/src/property.rs
@@ -98,8 +98,11 @@
let key_prefix = PropertyKey::try_from(prefix.as_bytes().to_vec()).ok()?;
let key_prefix = PropertyScope::Rmrk.apply(key_prefix).ok()?;
- key.as_slice().strip_prefix(key_prefix.as_slice())?
- .to_vec().try_into().ok()
+ key.as_slice()
+ .strip_prefix(key_prefix.as_slice())?
+ .to_vec()
+ .try_into()
+ .ok()
}
pub fn is_valid_key_prefix(key: &PropertyKey, prefix: &str) -> bool {
pallets/proxy-rmrk-core/src/rpc.rsdiffbeforeafterboth1use super::*;23pub fn last_collection_idx<T: Config>() -> Result<RmrkCollectionId, DispatchError> {4 Ok(<Pallet<T>>::last_collection_idx())5}67pub fn collection_by_id<T: Config>(8 collection_id: RmrkCollectionId,9) -> Result<Option<RmrkCollectionInfo<T::AccountId>>, DispatchError> {10 let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(11 collection_id,12 misc::CollectionType::Regular,13 ) {14 Ok(c) => c,15 Err(_) => return Ok(None),16 };1718 let nfts_count = collection.total_supply();1920 Ok(Some(RmrkCollectionInfo {21 issuer: collection.owner.clone(),22 metadata: <Pallet<T>>::get_collection_property_decoded(23 collection_id,24 RmrkProperty::Metadata,25 )?,26 max: collection.limits.token_limit,27 symbol: <Pallet<T>>::rebind(&collection.token_prefix)?,28 nfts_count,29 }))30}3132pub fn nft_by_id<T: Config>(33 collection_id: RmrkCollectionId,34 nft_by_id: RmrkNftId,35) -> Result<Option<RmrkInstanceInfo<T::AccountId>>, DispatchError> {36 let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(37 collection_id,38 misc::CollectionType::Regular,39 ) {40 Ok(c) => c,41 Err(_) => return Ok(None),42 };4344 let nft_id = TokenId(nft_by_id);45 if !<Pallet<T>>::nft_exists(collection_id, nft_id) {46 return Ok(None);47 }4849 let owner = match collection.token_owner(nft_id) {50 Some(owner) => match T::CrossTokenAddressMapping::address_to_token(&owner) {51 Some((col, tok)) => {52 let rmrk_collection = <Pallet<T>>::rmrk_collection_id(col)?;5354 RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(rmrk_collection, tok.0)55 }56 None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone()),57 },58 None => return Ok(None),59 };6061 Ok(Some(RmrkInstanceInfo {62 owner: owner,63 royalty: <Pallet<T>>::get_nft_property_decoded(64 collection_id,65 nft_id,66 RmrkProperty::RoyaltyInfo,67 )?,68 metadata: <Pallet<T>>::get_nft_property_decoded(69 collection_id,70 nft_id,71 RmrkProperty::Metadata,72 )?,73 equipped: <Pallet<T>>::get_nft_property_decoded(74 collection_id,75 nft_id,76 RmrkProperty::Equipped,77 )?,78 pending: <Pallet<T>>::get_nft_property_decoded(79 collection_id,80 nft_id,81 RmrkProperty::PendingNftAccept,82 )?,83 }))84}8586pub fn account_tokens<T: Config>(87 account_id: T::AccountId,88 collection_id: RmrkCollectionId,89) -> Result<Vec<RmrkNftId>, DispatchError> {90 let cross_account_id = CrossAccountId::from_sub(account_id);9192 let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(93 collection_id,94 misc::CollectionType::Regular,95 ) {96 Ok(c) => c,97 Err(_) => return Ok(Vec::new()),98 };99100 let tokens = collection101 .account_tokens(cross_account_id)102 .into_iter()103 .filter(|token| {104 let is_pending = <Pallet<T>>::get_nft_property_decoded(105 collection_id,106 *token,107 RmrkProperty::PendingNftAccept,108 )109 .unwrap_or(true);110111 !is_pending112 })113 .map(|token| token.0)114 .collect();115116 Ok(tokens)117}118119pub fn nft_children<T: Config>(120 collection_id: RmrkCollectionId,121 nft_id: RmrkNftId,122) -> Result<Vec<RmrkNftChild>, DispatchError> {123 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {124 Ok(id) => id,125 Err(_) => return Ok(Vec::new()),126 };127 let nft_id = TokenId(nft_id);128 if !<Pallet<T>>::nft_exists(collection_id, nft_id) {129 return Ok(Vec::new());130 }131132 Ok(133 pallet_nonfungible::TokenChildren::<T>::iter_prefix((collection_id, nft_id))134 .filter_map(|((child_collection, child_token), _)| {135 let rmrk_child_collection =136 <Pallet<T>>::rmrk_collection_id(child_collection).ok()?;137138 Some(RmrkNftChild {139 collection_id: rmrk_child_collection,140 nft_id: child_token.0,141 })142 })143 .chain(144 <Pallet<T>>::iterate_pending_children(collection_id, nft_id)?145 .map(|(child_collection, child_nft_id)| RmrkNftChild {146 collection_id: child_collection,147 nft_id: child_nft_id,148 })149 )150 .collect(),151 )152}153154pub fn collection_properties<T: Config>(155 collection_id: RmrkCollectionId,156 filter_keys: Option<Vec<RmrkPropertyKey>>,157) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {158 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {159 Ok(id) => id,160 Err(_) => return Ok(Vec::new()),161 };162 if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {163 return Ok(Vec::new());164 }165166 let properties = <Pallet<T>>::filter_user_properties(167 collection_id,168 /* token_id = */ None,169 filter_keys,170 |key, value| RmrkPropertyInfo { key, value },171 )?;172173 Ok(properties)174}175176pub fn nft_properties<T: Config>(177 collection_id: RmrkCollectionId,178 nft_id: RmrkNftId,179 filter_keys: Option<Vec<RmrkPropertyKey>>,180) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {181 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {182 Ok(id) => id,183 Err(_) => return Ok(Vec::new()),184 };185 let token_id = TokenId(nft_id);186187 if <Pallet<T>>::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {188 return Ok(Vec::new());189 }190191 let properties = <Pallet<T>>::filter_user_properties(192 collection_id,193 Some(token_id),194 filter_keys,195 |key, value| RmrkPropertyInfo { key, value },196 )?;197198 Ok(properties)199}200201pub fn nft_resources<T: Config>(202 collection_id: RmrkCollectionId,203 nft_id: RmrkNftId,204) -> Result<Vec<RmrkResourceInfo>, DispatchError> {205 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {206 Ok(id) => id,207 Err(_) => return Ok(Vec::new()),208 };209 if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {210 return Ok(Vec::new());211 }212213 let nft_id = TokenId(nft_id);214 if <Pallet<T>>::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() {215 return Ok(Vec::new());216 }217218 let resources = <pallet_nonfungible::Pallet<T>>::iterate_token_aux_properties(219 collection_id,220 nft_id,221 PropertyScope::Rmrk,222 )223 .filter_map(|(key, value)| {224 if !is_valid_key_prefix(&key, RESOURCE_ID_PREFIX) {225 return None;226 }227228 let resource_info: RmrkResourceInfo = <Pallet<T>>::decode_property(&value).ok()?;229230 Some(resource_info)231 })232 .collect();233234 Ok(resources)235}236237pub fn nft_resource_priority<T: Config>(238 collection_id: RmrkCollectionId,239 nft_id: RmrkNftId,240 resource_id: RmrkResourceId,241) -> Result<Option<u32>, DispatchError> {242 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {243 Ok(id) => id,244 Err(_) => return Ok(None),245 };246 if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {247 return Ok(None);248 }249250 let nft_id = TokenId(nft_id);251 if <Pallet<T>>::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() {252 return Ok(None);253 }254255 let priorities: Vec<_> = <Pallet<T>>::get_nft_property_decoded(256 collection_id,257 nft_id,258 RmrkProperty::ResourcePriorities,259 )?;260 Ok(priorities261 .into_iter()262 .enumerate()263 .find(|(_, id)| *id == resource_id)264 .map(|(priority, _): (usize, RmrkResourceId)| priority as u32))265}1use super::*;23pub fn last_collection_idx<T: Config>() -> Result<RmrkCollectionId, DispatchError> {4 Ok(<Pallet<T>>::last_collection_idx())5}67pub fn collection_by_id<T: Config>(8 collection_id: RmrkCollectionId,9) -> Result<Option<RmrkCollectionInfo<T::AccountId>>, DispatchError> {10 let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(11 collection_id,12 misc::CollectionType::Regular,13 ) {14 Ok(c) => c,15 Err(_) => return Ok(None),16 };1718 let nfts_count = collection.total_supply();1920 Ok(Some(RmrkCollectionInfo {21 issuer: collection.owner.clone(),22 metadata: <Pallet<T>>::get_collection_property_decoded(23 collection_id,24 RmrkProperty::Metadata,25 )?,26 max: collection.limits.token_limit,27 symbol: <Pallet<T>>::rebind(&collection.token_prefix)?,28 nfts_count,29 }))30}3132pub fn nft_by_id<T: Config>(33 collection_id: RmrkCollectionId,34 nft_by_id: RmrkNftId,35) -> Result<Option<RmrkInstanceInfo<T::AccountId>>, DispatchError> {36 let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(37 collection_id,38 misc::CollectionType::Regular,39 ) {40 Ok(c) => c,41 Err(_) => return Ok(None),42 };4344 let nft_id = TokenId(nft_by_id);45 if !<Pallet<T>>::nft_exists(collection_id, nft_id) {46 return Ok(None);47 }4849 let owner = match collection.token_owner(nft_id) {50 Some(owner) => match T::CrossTokenAddressMapping::address_to_token(&owner) {51 Some((col, tok)) => {52 let rmrk_collection = <Pallet<T>>::rmrk_collection_id(col)?;5354 RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(rmrk_collection, tok.0)55 }56 None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone()),57 },58 None => return Ok(None),59 };6061 Ok(Some(RmrkInstanceInfo {62 owner: owner,63 royalty: <Pallet<T>>::get_nft_property_decoded(64 collection_id,65 nft_id,66 RmrkProperty::RoyaltyInfo,67 )?,68 metadata: <Pallet<T>>::get_nft_property_decoded(69 collection_id,70 nft_id,71 RmrkProperty::Metadata,72 )?,73 equipped: <Pallet<T>>::get_nft_property_decoded(74 collection_id,75 nft_id,76 RmrkProperty::Equipped,77 )?,78 pending: <Pallet<T>>::get_nft_property_decoded(79 collection_id,80 nft_id,81 RmrkProperty::PendingNftAccept,82 )?,83 }))84}8586pub fn account_tokens<T: Config>(87 account_id: T::AccountId,88 collection_id: RmrkCollectionId,89) -> Result<Vec<RmrkNftId>, DispatchError> {90 let cross_account_id = CrossAccountId::from_sub(account_id);9192 let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(93 collection_id,94 misc::CollectionType::Regular,95 ) {96 Ok(c) => c,97 Err(_) => return Ok(Vec::new()),98 };99100 let tokens = collection101 .account_tokens(cross_account_id)102 .into_iter()103 .filter(|token| {104 let is_pending = <Pallet<T>>::get_nft_property_decoded(105 collection_id,106 *token,107 RmrkProperty::PendingNftAccept,108 )109 .unwrap_or(true);110111 !is_pending112 })113 .map(|token| token.0)114 .collect();115116 Ok(tokens)117}118119pub fn nft_children<T: Config>(120 collection_id: RmrkCollectionId,121 nft_id: RmrkNftId,122) -> Result<Vec<RmrkNftChild>, DispatchError> {123 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {124 Ok(id) => id,125 Err(_) => return Ok(Vec::new()),126 };127 let nft_id = TokenId(nft_id);128 if !<Pallet<T>>::nft_exists(collection_id, nft_id) {129 return Ok(Vec::new());130 }131132 Ok(133 pallet_nonfungible::TokenChildren::<T>::iter_prefix((collection_id, nft_id))134 .filter_map(|((child_collection, child_token), _)| {135 let rmrk_child_collection =136 <Pallet<T>>::rmrk_collection_id(child_collection).ok()?;137138 Some(RmrkNftChild {139 collection_id: rmrk_child_collection,140 nft_id: child_token.0,141 })142 })143 .chain(144 <Pallet<T>>::iterate_pending_children(collection_id, nft_id)?.map(145 |(child_collection, child_nft_id)| RmrkNftChild {146 collection_id: child_collection,147 nft_id: child_nft_id,148 },149 ),150 )151 .collect(),152 )153}154155pub fn collection_properties<T: Config>(156 collection_id: RmrkCollectionId,157 filter_keys: Option<Vec<RmrkPropertyKey>>,158) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {159 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {160 Ok(id) => id,161 Err(_) => return Ok(Vec::new()),162 };163 if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {164 return Ok(Vec::new());165 }166167 let properties = <Pallet<T>>::filter_user_properties(168 collection_id,169 /* token_id = */ None,170 filter_keys,171 |key, value| RmrkPropertyInfo { key, value },172 )?;173174 Ok(properties)175}176177pub fn nft_properties<T: Config>(178 collection_id: RmrkCollectionId,179 nft_id: RmrkNftId,180 filter_keys: Option<Vec<RmrkPropertyKey>>,181) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {182 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {183 Ok(id) => id,184 Err(_) => return Ok(Vec::new()),185 };186 let token_id = TokenId(nft_id);187188 if <Pallet<T>>::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {189 return Ok(Vec::new());190 }191192 let properties = <Pallet<T>>::filter_user_properties(193 collection_id,194 Some(token_id),195 filter_keys,196 |key, value| RmrkPropertyInfo { key, value },197 )?;198199 Ok(properties)200}201202pub fn nft_resources<T: Config>(203 collection_id: RmrkCollectionId,204 nft_id: RmrkNftId,205) -> Result<Vec<RmrkResourceInfo>, DispatchError> {206 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {207 Ok(id) => id,208 Err(_) => return Ok(Vec::new()),209 };210 if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {211 return Ok(Vec::new());212 }213214 let nft_id = TokenId(nft_id);215 if <Pallet<T>>::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() {216 return Ok(Vec::new());217 }218219 let resources = <pallet_nonfungible::Pallet<T>>::iterate_token_aux_properties(220 collection_id,221 nft_id,222 PropertyScope::Rmrk,223 )224 .filter_map(|(key, value)| {225 if !is_valid_key_prefix(&key, RESOURCE_ID_PREFIX) {226 return None;227 }228229 let resource_info: RmrkResourceInfo = <Pallet<T>>::decode_property(&value).ok()?;230231 Some(resource_info)232 })233 .collect();234235 Ok(resources)236}237238pub fn nft_resource_priority<T: Config>(239 collection_id: RmrkCollectionId,240 nft_id: RmrkNftId,241 resource_id: RmrkResourceId,242) -> Result<Option<u32>, DispatchError> {243 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {244 Ok(id) => id,245 Err(_) => return Ok(None),246 };247 if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {248 return Ok(None);249 }250251 let nft_id = TokenId(nft_id);252 if <Pallet<T>>::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() {253 return Ok(None);254 }255256 let priorities: Vec<_> = <Pallet<T>>::get_nft_property_decoded(257 collection_id,258 nft_id,259 RmrkProperty::ResourcePriorities,260 )?;261 Ok(priorities262 .into_iter()263 .enumerate()264 .find(|(_, id)| *id == resource_id)265 .map(|(priority, _): (usize, RmrkResourceId)| priority as u32))266}