difftreelog
refactor revert changing collection owner type
in: master
Not necessary yet, we don't have to support evm accounts create collections
3 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth167#[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 where641 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 created649 /// * 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),653654654 /// New item was created.655 /// New item was created.655 /// 656 /// 734 mode: CollectionMode) -> DispatchResult {735 mode: CollectionMode) -> DispatchResult {735736736 // Anyone can create a collection737 // Anyone can create a collection737 let who = T::CrossAccountId::from_sub(ensure_signed(origin)?);738 let who = ensure_signed(origin)?;738739739 // Take a (non-refundable) deposit of collection creation740 // Take a (non-refundable) deposit of collection creation740 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 {822823823 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) -> DispatchResult927 {928 {928 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);929 let sender = ensure_signed(origin)?;929930930 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) -> DispatchResult954 {955 {955 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);956 let sender = ensure_signed(origin)?;956957957 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 {979980980 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)?;106710681110 let sender = ensure_signed(origin)?;1111 let sender = ensure_signed(origin)?;111111121112 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)?;111411151115 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();165616572239 )2240 )2240 }2241 }224122422242 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>::NoPermission2249 }2250 }225022512251 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 }225422552255 fn check_owner_or_admin_permissions(2256 fn check_owner_or_admin_permissions(runtime_types.jsondiffbeforeafterboth45 }45 }46 },46 },47 "Collection": {47 "Collection": {48 "Owner": "CrossAccountId",48 "Owner": "AccountId",49 "Mode": "CollectionMode",49 "Mode": "CollectionMode",50 "Access": "AccessMode",50 "Access": "AccessMode",51 "DecimalPoints": "DecimalPoints",51 "DecimalPoints": "DecimalPoints",tests/src/util/helpers.tsdiffbeforeafterboth37 }37 }38 return input;38 return input;39}39}40export function toSubstrateAddress(input: CrossAccountId): string {40export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {41 input = normalizeAccountId(input);41 input = normalizeAccountId(input);42 if ('substrate' in input) {42 if ('substrate' in input) {43 return input.substrate;43 return input.substrate;273 // tslint:disable-next-line:no-unused-expression273 // tslint:disable-next-line:no-unused-expression274 expect(collection).to.be.not.null;274 expect(collection).to.be.not.null;275 expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');275 expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');276 expect(collection.Owner).to.be.deep.equal(normalizeAccountId(alicesPublicKey));276 expect(collection.Owner).to.be.equal(toSubstrateAddress(alicesPublicKey));277 expect(utf16ToStr(collection.Name)).to.be.equal(name);277 expect(utf16ToStr(collection.Name)).to.be.equal(name);278 expect(utf16ToStr(collection.Description)).to.be.equal(description);278 expect(utf16ToStr(collection.Description)).to.be.equal(description);279 expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);279 expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);