difftreelog
fix(rmrk) sending nft
in: master
5 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
@@ -25,7 +25,7 @@
Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations,
};
use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle, TokenData};
-use pallet_structure::Pallet as PalletStructure;
+use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
use pallet_evm::account::CrossAccountId;
use core::convert::AsRef;
@@ -128,8 +128,10 @@
NoAvailableNftId,
CollectionUnknown,
NoPermission,
+ NonTransferable,
CollectionFullOrLocked,
ResourceDoesntExist,
+ CannotSendToDescendentOrSelf,
}
#[pallet::call]
@@ -207,7 +209,7 @@
);
<PalletNft<T>>::destroy_collection(collection, &cross_sender)
- .map_err(Self::map_common_err_to_proxy)?;
+ .map_err(Self::map_unique_err_to_proxy)?;
Self::deposit_event(Event::CollectionDestroyed {
issuer: sender,
@@ -283,6 +285,7 @@
recipient: Option<T::AccountId>,
royalty_amount: Option<Permill>,
metadata: RmrkString,
+ transferable: bool,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
let sender = T::CrossAccountId::from_sub(sender);
@@ -304,6 +307,8 @@
&collection,
[
Self::rmrk_property(TokenType, &NftType::Regular)?,
+ Self::rmrk_property(Transferable, &transferable)?,
+ Self::rmrk_property(PendingNftAccept, &false)?,
Self::rmrk_property(RoyaltyInfo, &royalty_info)?,
Self::rmrk_property(Metadata, &metadata)?,
Self::rmrk_property(Equipped, &false)?,
@@ -327,7 +332,7 @@
)
.map_err(|err| match err {
DispatchError::Arithmetic(_) => <Error<T>>::NoAvailableNftId.into(),
- err => Self::map_common_err_to_proxy(err),
+ err => Self::map_unique_err_to_proxy(err),
})?;
Self::deposit_event(Event::NftMinted {
@@ -373,7 +378,7 @@
new_owner: RmrkAccountIdOrCollectionNftTuple<T::AccountId>,
) -> DispatchResult {
let sender = ensure_signed(origin.clone())?;
- let cross_sender = T::CrossAccountId::from_sub(sender.clone());
+ let cross_sender = T::CrossAccountId::from_sub(sender);
let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
let nft_id = rmrk_nft_id.into();
@@ -388,8 +393,14 @@
misc::CollectionType::Regular,
)?;
- let budget = budget::Value::new(NESTING_BUDGET);
+ if !Self::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Transferable)? {
+ return Err(<Error<T>>::NonTransferable.into());
+ }
+ if Self::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::PendingNftAccept)? {
+ return Err(<Error<T>>::NoPermission.into());
+ }
+
let target_owner;
match new_owner {
@@ -399,43 +410,45 @@
RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(target_collection_id, target_nft_id) => {
let target_collection_id = Self::unique_collection_id(target_collection_id)?;
- target_owner = T::CrossTokenAddressMapping::token_to_address(
- target_collection_id,
- target_nft_id.into(),
- );
+ let target_nft_budget = budget::Value::new(NESTING_BUDGET);
- let spender = <PalletStructure<T>>::get_indirect_owner(
+ let target_nft_owner = <PalletStructure<T>>::get_checked_indirect_owner(
target_collection_id,
target_nft_id.into(),
Some((collection_id, nft_id)),
- &budget,
- )?;
+ &target_nft_budget,
+ ).map_err(Self::map_unique_err_to_proxy)?;
- let is_approval_required = cross_sender != spender;
+ let is_approval_required = cross_sender != target_nft_owner;
if is_approval_required {
- // FIXME
- // <PalletNft<T>>::set_allowance(
- // &collection,
- // &cross_sender,
- // nft_id,
- // Some(&spender),
- // &budget
- // ).map_err(Self::map_common_err_to_proxy)?;
+ target_owner = target_nft_owner;
- return Ok(());
+ <PalletNft<T>>::set_scoped_token_property(
+ collection.id,
+ nft_id,
+ PropertyScope::Rmrk,
+ Self::rmrk_property(PendingNftAccept, &is_approval_required)?,
+ )?;
+ } else {
+ target_owner = T::CrossTokenAddressMapping::token_to_address(
+ target_collection_id,
+ target_nft_id.into(),
+ );
}
}
}
+ let src_nft_budget = budget::Value::new(NESTING_BUDGET);
+
<PalletNft<T>>::transfer_from(
&collection,
&cross_sender,
&from,
&target_owner,
nft_id,
- &budget
- ).map_err(Self::map_common_err_to_proxy)?;
+ &src_nft_budget
+ ).map_err(Self::map_unique_err_to_proxy)?;
Ok(())
}
@@ -719,7 +732,7 @@
let collection = Self::get_typed_nft_collection(collection_id, collection_type)?;
<PalletNft<T>>::burn(&collection, &sender, token_id)
- .map_err(Self::map_common_err_to_proxy)?;
+ .map_err(Self::map_unique_err_to_proxy)?;
Ok(())
}
@@ -762,7 +775,7 @@
)
.map_err(|err| match err {
DispatchError::Arithmetic(_) => <Error<T>>::NoAvailableNftId.into(),
- err => Self::map_common_err_to_proxy(err),
+ err => Self::map_unique_err_to_proxy(err),
})?;
Ok(resource_id.0)
@@ -794,7 +807,7 @@
let sender = T::CrossAccountId::from_sub(sender);
if topmost_owner == sender {
<PalletNft<T>>::burn(&resource_collection, &sender, resource_id)
- .map_err(Self::map_common_err_to_proxy)?;
+ .map_err(Self::map_unique_err_to_proxy)?;
} else {
<PalletNft<T>>::set_scoped_token_property(
resource_collection_id,
@@ -828,7 +841,7 @@
) -> DispatchResult {
collection
.check_is_owner(account)
- .map_err(Self::map_common_err_to_proxy)
+ .map_err(Self::map_unique_err_to_proxy)
}
pub fn last_collection_idx() -> RmrkCollectionId {
@@ -1064,14 +1077,16 @@
Ok(properties)
}
- fn map_common_err_to_proxy(err: DispatchError) -> DispatchError {
- map_common_err_to_proxy! {
+ fn map_unique_err_to_proxy(err: DispatchError) -> DispatchError {
+ map_unique_err_to_proxy! {
match err {
- NoPermission => NoPermission,
- CollectionTokenLimitExceeded => CollectionFullOrLocked,
- PublicMintingNotAllowed => NoPermission,
- TokenNotFound => NoAvailableNftId,
- ApprovedValueTooLow => NoPermission
+ CommonError::NoPermission => NoPermission,
+ CommonError::CollectionTokenLimitExceeded => CollectionFullOrLocked,
+ CommonError::PublicMintingNotAllowed => NoPermission,
+ CommonError::TokenNotFound => NoAvailableNftId,
+ CommonError::ApprovedValueTooLow => NoPermission,
+ StructureError::TokenNotFound => NoAvailableNftId,
+ StructureError::OuroborosDetected => CannotSendToDescendentOrSelf
}
}
}
pallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/misc.rs
+++ b/pallets/proxy-rmrk-core/src/misc.rs
@@ -2,10 +2,10 @@
use codec::{Encode, Decode, Error};
#[macro_export]
-macro_rules! map_common_err_to_proxy {
- (match $err:ident { $($common_err:ident => $proxy_err:ident),+ }) => {
+macro_rules! map_unique_err_to_proxy {
+ (match $err:ident { $($unique_err_ty:ident :: $unique_err:ident => $proxy_err:ident),+ }) => {
$(
- if $err == <CommonError<T>>::$common_err.into() {
+ if $err == <$unique_err_ty<T>>::$unique_err.into() {
return <Error<T>>::$proxy_err.into()
} else
)+ {
pallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth1use super::*;2use core::convert::AsRef;34pub enum RmrkProperty<'r> {5 Metadata,6 CollectionType,7 TokenType,8 RoyaltyInfo,9 Equipped,10 ResourceCollection,11 ResourcePriorities,12 ResourceType,13 PendingResourceAccept,14 PendingResourceRemoval,15 Parts,16 Base,17 Src,18 Slot,19 License,20 Thumb,21 EquippedNft,22 BaseType,23 ExternalPartId,24 EquippableList,25 ZIndex,26 ThemeName,27 ThemeInherit,28 UserProperty(&'r [u8]),29}3031impl<'r> RmrkProperty<'r> {32 pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {33 fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {34 container.as_ref()35 }3637 macro_rules! key {38 ($($component:expr),+) => {39 PropertyKey::try_from([$(key!(@ &$component)),+].concat())40 .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)41 };4243 (@ $key:expr) => {44 get_bytes($key)45 };46 }4748 match self {49 Self::Metadata => key!("metadata"),50 Self::CollectionType => key!("collection-type"),51 Self::TokenType => key!("token-type"),52 Self::RoyaltyInfo => key!("royalty-info"),53 Self::Equipped => key!("equipped"),54 Self::ResourceCollection => key!("resource-collection"),55 Self::ResourcePriorities => key!("resource-priorities"),56 Self::ResourceType => key!("resource-type"),57 Self::PendingResourceAccept => key!("pending-accept"),58 Self::PendingResourceRemoval => key!("pending-removal"),59 Self::Parts => key!("parts"),60 Self::Base => key!("base"),61 Self::Src => key!("src"),62 Self::Slot => key!("slot"),63 Self::License => key!("license"),64 Self::Thumb => key!("thumb"),65 Self::EquippedNft => key!("equipped-nft"),66 Self::BaseType => key!("base-type"),67 Self::ExternalPartId => key!("ext-part-id"),68 Self::EquippableList => key!("equippable-list"),69 Self::ZIndex => key!("z-index"),70 Self::ThemeName => key!("theme-name"),71 Self::ThemeInherit => key!("theme-inherit"),72 Self::UserProperty(name) => key!("userprop-", name),73 }74 }75}pallets/structure/src/lib.rsdiffbeforeafterboth--- a/pallets/structure/src/lib.rs
+++ b/pallets/structure/src/lib.rs
@@ -149,7 +149,7 @@
})
}
- pub fn get_indirect_owner(
+ pub fn get_checked_indirect_owner(
collection: CollectionId,
token: TokenId,
for_nest: Option<(CollectionId, TokenId)>,
@@ -203,7 +203,7 @@
None => user,
};
- Self::get_indirect_owner(
+ Self::get_checked_indirect_owner(
collection,
token,
for_nest,
runtime/common/src/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -188,19 +188,17 @@
None => return Ok(None)
};
- let allowance = pallet_nonfungible::Allowance::<Runtime>::get((collection_id, nft_id));
-
Ok(Some(RmrkInstanceInfo {
owner: owner,
royalty: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::RoyaltyInfo)?,
metadata: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Metadata)?,
equipped: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Equipped)?,
- pending: allowance.is_some(),
+ pending: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::PendingNftAccept)?,
}))
}
fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {
- use pallet_proxy_rmrk_core::misc::CollectionType;
+ use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};
use pallet_common::CommonCollectionOperations;
let cross_account_id = CrossAccountId::from_sub(account_id);
@@ -210,15 +208,26 @@
Err(_) => return Ok(Vec::new()),
};
- Ok(
- collection.account_tokens(cross_account_id)
- .into_iter()
- .map(|token| token.0)
- .collect()
- )
+ let tokens = collection.account_tokens(cross_account_id)
+ .into_iter()
+ .filter(|token| {
+ let is_pending = RmrkCore::get_nft_property_decoded(
+ collection_id,
+ *token,
+ RmrkProperty::PendingNftAccept
+ ).unwrap_or(true);
+
+ !is_pending
+ })
+ .map(|token| token.0)
+ .collect();
+
+ Ok(tokens)
}
fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {
+ use pallet_proxy_rmrk_core::RmrkProperty;
+
let collection_id = match RmrkCore::unique_collection_id(collection_id) {
Ok(id) => id,
Err(_) => return Ok(Vec::new())
@@ -229,6 +238,16 @@
Ok(
pallet_nonfungible::TokenChildren::<Runtime>::iter_prefix((collection_id, nft_id))
.filter_map(|((child_collection, child_token), _)| {
+ let is_pending = RmrkCore::get_nft_property_decoded(
+ child_collection,
+ child_token,
+ RmrkProperty::PendingNftAccept
+ ).ok()?;
+
+ if is_pending {
+ return None;
+ }
+
let rmrk_child_collection = RmrkCore::rmrk_collection_id(
child_collection
).ok()?;
@@ -398,7 +417,7 @@
Ok(c) => c,
Err(_) => return Ok(Vec::new()),
};
-
+
let parts = collection.collection_tokens()
.into_iter()
.filter_map(|token_id| {