git.delta.rocks / unique-network / refs/commits / e3aef6f9aee5

difftreelog

refactor revert changing collection owner type

Yaroslav Bolyukin2021-06-02parent: #1824786.patch.diff
in: master
Not necessary yet, we don't have to support evm accounts create
collections

3 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
167#[derive(Encode, Decode, Clone, PartialEq)]167#[derive(Encode, Decode, Clone, PartialEq)]
168#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]168#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
169pub struct Collection<T: Config> {169pub struct Collection<T: Config> {
170 pub owner: T::CrossAccountId,170 pub owner: T::AccountId,
171 pub mode: CollectionMode,171 pub mode: CollectionMode,
172 pub access: AccessMode,172 pub access: AccessMode,
173 pub decimal_points: DecimalPoints,173 pub decimal_points: DecimalPoints,
638decl_event!(638decl_event!(
639 pub enum Event<T>639 pub enum Event<T>
640 where640 where
641 AccountId = <T as frame_system::Config>::AccountId,
641 CrossAccountId = <T as Config>::CrossAccountId,642 CrossAccountId = <T as Config>::CrossAccountId,
642 {643 {
643 /// New collection was created644 /// New collection was created
649 /// * mode: [CollectionMode] converted into u8.650 /// * mode: [CollectionMode] converted into u8.
650 /// 651 ///
651 /// * account_id: Collection owner.652 /// * account_id: Collection owner.
652 CollectionCreated(CollectionId, u8, CrossAccountId),653 CollectionCreated(CollectionId, u8, AccountId),
653654
654 /// New item was created.655 /// New item was created.
655 /// 656 ///
734 mode: CollectionMode) -> DispatchResult {735 mode: CollectionMode) -> DispatchResult {
735736
736 // Anyone can create a collection737 // Anyone can create a collection
737 let who = T::CrossAccountId::from_sub(ensure_signed(origin)?);738 let who = ensure_signed(origin)?;
738739
739 // Take a (non-refundable) deposit of collection creation740 // Take a (non-refundable) deposit of collection creation
740 let mut imbalance = <<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();741 let mut imbalance = <<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();
743 T::CollectionCreationPrice::get(),744 T::CollectionCreationPrice::get(),
744 ));745 ));
745 <T as Config>::Currency::settle(746 <T as Config>::Currency::settle(
746 who.as_sub(),747 &who,
747 imbalance,748 imbalance,
748 WithdrawReasons::TRANSFER,749 WithdrawReasons::TRANSFER,
749 ExistenceRequirement::KeepAlive,750 ExistenceRequirement::KeepAlive,
820 #[transactional]821 #[transactional]
821 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {822 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {
822823
823 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);824 let sender = ensure_signed(origin)?;
824 let collection = Self::get_collection(collection_id)?;825 let collection = Self::get_collection(collection_id)?;
825 Self::check_owner_permissions(&collection, &sender)?;826 Self::check_owner_permissions(&collection, &sender)?;
826 if !collection.limits.owner_can_destroy {827 if !collection.limits.owner_can_destroy {
925 #[transactional]926 #[transactional]
926 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult927 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult
927 {928 {
928 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);929 let sender = ensure_signed(origin)?;
929930
930 let mut target_collection = Self::get_collection(collection_id)?;931 let mut target_collection = Self::get_collection(collection_id)?;
931 Self::check_owner_permissions(&target_collection, &sender)?;932 Self::check_owner_permissions(&target_collection, &sender)?;
952 #[transactional]953 #[transactional]
953 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult954 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult
954 {955 {
955 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);956 let sender = ensure_signed(origin)?;
956957
957 let mut target_collection = Self::get_collection(collection_id)?;958 let mut target_collection = Self::get_collection(collection_id)?;
958 Self::check_owner_permissions(&target_collection, &sender)?;959 Self::check_owner_permissions(&target_collection, &sender)?;
975 /// * new_owner.976 /// * new_owner.
976 #[weight = <T as Config>::WeightInfo::change_collection_owner()]977 #[weight = <T as Config>::WeightInfo::change_collection_owner()]
977 #[transactional]978 #[transactional]
978 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::CrossAccountId) -> DispatchResult {979 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {
979980
980 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);981 let sender = ensure_signed(origin)?;
981 let mut target_collection = Self::get_collection(collection_id)?;982 let mut target_collection = Self::get_collection(collection_id)?;
982 Self::check_owner_permissions(&target_collection, &sender)?;983 Self::check_owner_permissions(&target_collection, &sender)?;
983 target_collection.owner = new_owner;984 target_collection.owner = new_owner;
1061 #[weight = <T as Config>::WeightInfo::set_collection_sponsor()]1062 #[weight = <T as Config>::WeightInfo::set_collection_sponsor()]
1062 #[transactional]1063 #[transactional]
1063 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {1064 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {
1064 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1065 let sender = ensure_signed(origin)?;
1065 let mut target_collection = Self::get_collection(collection_id)?;1066 let mut target_collection = Self::get_collection(collection_id)?;
1066 Self::check_owner_permissions(&target_collection, &sender)?;1067 Self::check_owner_permissions(&target_collection, &sender)?;
10671068
1110 let sender = ensure_signed(origin)?;1111 let sender = ensure_signed(origin)?;
11111112
1112 let mut target_collection = Self::get_collection(collection_id)?;1113 let mut target_collection = Self::get_collection(collection_id)?;
1113 Self::check_owner_permissions(&target_collection, &T::CrossAccountId::from_sub(sender))?;1114 Self::check_owner_permissions(&target_collection, &sender)?;
11141115
1115 target_collection.sponsorship = SponsorshipState::Disabled;1116 target_collection.sponsorship = SponsorshipState::Disabled;
1116 Self::save_collection(target_collection);1117 Self::save_collection(target_collection);
1650 ) -> DispatchResult {1651 ) -> DispatchResult {
1651 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1652 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
1652 let mut target_collection = Self::get_collection(collection_id)?;1653 let mut target_collection = Self::get_collection(collection_id)?;
1653 Self::check_owner_permissions(&target_collection, &sender)?;1654 Self::check_owner_permissions(&target_collection, &sender.as_sub())?;
1654 let old_limits = &target_collection.limits;1655 let old_limits = &target_collection.limits;
1655 let chain_limits = ChainLimit::get();1656 let chain_limits = ChainLimit::get();
16561657
2239 )2240 )
2240 }2241 }
22412242
2242 fn check_owner_permissions(target_collection: &CollectionHandle<T>, subject: &T::CrossAccountId) -> DispatchResult {2243 fn check_owner_permissions(target_collection: &CollectionHandle<T>, subject: &T::AccountId) -> DispatchResult {
2243 ensure!(2244 ensure!(
2244 *subject == target_collection.owner,2245 *subject == target_collection.owner,
2245 Error::<T>::NoPermission2246 Error::<T>::NoPermission
2249 }2250 }
22502251
2251 fn is_owner_or_admin_permissions(collection: &CollectionHandle<T>, subject: &T::CrossAccountId) -> bool {2252 fn is_owner_or_admin_permissions(collection: &CollectionHandle<T>, subject: &T::CrossAccountId) -> bool {
2252 *subject == collection.owner || <AdminList<T>>::get(collection.id).contains(&subject)2253 *subject.as_sub() == collection.owner || <AdminList<T>>::get(collection.id).contains(&subject)
2253 }2254 }
22542255
2255 fn check_owner_or_admin_permissions(2256 fn check_owner_or_admin_permissions(
modifiedruntime_types.jsondiffbeforeafterboth
--- a/runtime_types.json
+++ b/runtime_types.json
@@ -45,7 +45,7 @@
       }
     },
     "Collection": {
-      "Owner": "CrossAccountId",
+      "Owner": "AccountId",
       "Mode": "CollectionMode",
       "Access": "AccessMode",
       "DecimalPoints": "DecimalPoints",
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- 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);