From e3aef6f9aee550b6c720a2014aea3ea433c814df Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 02 Jun 2021 17:40:00 +0000 Subject: [PATCH] refactor: revert changing collection owner type Not necessary yet, we don't have to support evm accounts create collections --- --- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -167,7 +167,7 @@ #[derive(Encode, Decode, Clone, PartialEq)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct Collection { - pub owner: T::CrossAccountId, + pub owner: T::AccountId, pub mode: CollectionMode, pub access: AccessMode, pub decimal_points: DecimalPoints, @@ -638,6 +638,7 @@ decl_event!( pub enum Event where + AccountId = ::AccountId, CrossAccountId = ::CrossAccountId, { /// New collection was created @@ -649,7 +650,7 @@ /// * mode: [CollectionMode] converted into u8. /// /// * account_id: Collection owner. - CollectionCreated(CollectionId, u8, CrossAccountId), + CollectionCreated(CollectionId, u8, AccountId), /// New item was created. /// @@ -734,7 +735,7 @@ mode: CollectionMode) -> DispatchResult { // Anyone can create a collection - let who = T::CrossAccountId::from_sub(ensure_signed(origin)?); + let who = ensure_signed(origin)?; // Take a (non-refundable) deposit of collection creation let mut imbalance = <<::Currency as Currency>::PositiveImbalance>::zero(); @@ -743,7 +744,7 @@ T::CollectionCreationPrice::get(), )); ::Currency::settle( - who.as_sub(), + &who, imbalance, WithdrawReasons::TRANSFER, ExistenceRequirement::KeepAlive, @@ -820,7 +821,7 @@ #[transactional] pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult { - let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); + let sender = ensure_signed(origin)?; let collection = Self::get_collection(collection_id)?; Self::check_owner_permissions(&collection, &sender)?; if !collection.limits.owner_can_destroy { @@ -925,7 +926,7 @@ #[transactional] pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult { - let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); + let sender = ensure_signed(origin)?; let mut target_collection = Self::get_collection(collection_id)?; Self::check_owner_permissions(&target_collection, &sender)?; @@ -952,7 +953,7 @@ #[transactional] pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult { - let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); + let sender = ensure_signed(origin)?; let mut target_collection = Self::get_collection(collection_id)?; Self::check_owner_permissions(&target_collection, &sender)?; @@ -975,9 +976,9 @@ /// * new_owner. #[weight = ::WeightInfo::change_collection_owner()] #[transactional] - pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::CrossAccountId) -> DispatchResult { + pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult { - let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); + let sender = ensure_signed(origin)?; let mut target_collection = Self::get_collection(collection_id)?; Self::check_owner_permissions(&target_collection, &sender)?; target_collection.owner = new_owner; @@ -1061,7 +1062,7 @@ #[weight = ::WeightInfo::set_collection_sponsor()] #[transactional] pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult { - let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); + let sender = ensure_signed(origin)?; let mut target_collection = Self::get_collection(collection_id)?; Self::check_owner_permissions(&target_collection, &sender)?; @@ -1110,7 +1111,7 @@ let sender = ensure_signed(origin)?; let mut target_collection = Self::get_collection(collection_id)?; - Self::check_owner_permissions(&target_collection, &T::CrossAccountId::from_sub(sender))?; + Self::check_owner_permissions(&target_collection, &sender)?; target_collection.sponsorship = SponsorshipState::Disabled; Self::save_collection(target_collection); @@ -1650,7 +1651,7 @@ ) -> DispatchResult { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let mut target_collection = Self::get_collection(collection_id)?; - Self::check_owner_permissions(&target_collection, &sender)?; + Self::check_owner_permissions(&target_collection, &sender.as_sub())?; let old_limits = &target_collection.limits; let chain_limits = ChainLimit::get(); @@ -2239,7 +2240,7 @@ ) } - fn check_owner_permissions(target_collection: &CollectionHandle, subject: &T::CrossAccountId) -> DispatchResult { + fn check_owner_permissions(target_collection: &CollectionHandle, subject: &T::AccountId) -> DispatchResult { ensure!( *subject == target_collection.owner, Error::::NoPermission @@ -2249,7 +2250,7 @@ } fn is_owner_or_admin_permissions(collection: &CollectionHandle, subject: &T::CrossAccountId) -> bool { - *subject == collection.owner || >::get(collection.id).contains(&subject) + *subject.as_sub() == collection.owner || >::get(collection.id).contains(&subject) } fn check_owner_or_admin_permissions( --- a/runtime_types.json +++ b/runtime_types.json @@ -45,7 +45,7 @@ } }, "Collection": { - "Owner": "CrossAccountId", + "Owner": "AccountId", "Mode": "CollectionMode", "Access": "AccessMode", "DecimalPoints": "DecimalPoints", --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -37,7 +37,7 @@ } return input; } -export function toSubstrateAddress(input: CrossAccountId): string { +export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string { input = normalizeAccountId(input); if ('substrate' in input) { return input.substrate; @@ -273,7 +273,7 @@ // tslint:disable-next-line:no-unused-expression expect(collection).to.be.not.null; expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.'); - expect(collection.Owner).to.be.deep.equal(normalizeAccountId(alicesPublicKey)); + expect(collection.Owner).to.be.equal(toSubstrateAddress(alicesPublicKey)); expect(utf16ToStr(collection.Name)).to.be.equal(name); expect(utf16ToStr(collection.Description)).to.be.equal(description); expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix); -- gitstuff