From 2b03ee1d72b274e6fe77202a1712ec200c05316a Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Fri, 30 Apr 2021 15:16:26 +0000 Subject: [PATCH] feat: access control manipulation from evm --- --- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -176,7 +176,7 @@ pub mint_mode: bool, pub offchain_schema: Vec, pub schema_version: SchemaVersion, - pub sponsorship: SponsorshipState, + pub sponsorship: SponsorshipState, pub limits: CollectionLimits, // Collection private restrictions pub variable_on_chain_schema: Vec, // pub const_on_chain_schema: Vec, // @@ -845,13 +845,13 @@ /// * address. #[weight = ::WeightInfo::add_to_white_list()] #[transactional] - pub fn add_to_white_list(origin, collection_id: CollectionId, address: T::AccountId) -> DispatchResult{ + pub fn add_to_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{ - let sender = ensure_signed(origin)?; + let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let collection = Self::get_collection(collection_id)?; Self::check_owner_or_admin_permissions(&collection, sender)?; - >::insert(collection_id, address, true); + >::insert(collection_id, address.as_sub(), true); Ok(()) } @@ -870,13 +870,13 @@ /// * address. #[weight = ::WeightInfo::remove_from_white_list()] #[transactional] - pub fn remove_from_white_list(origin, collection_id: CollectionId, address: T::AccountId) -> DispatchResult{ + pub fn remove_from_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{ - let sender = ensure_signed(origin)?; + let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let collection = Self::get_collection(collection_id)?; Self::check_owner_or_admin_permissions(&collection, sender)?; - >::remove(collection_id, address); + >::remove(collection_id, address.as_sub()); Ok(()) } @@ -896,7 +896,7 @@ #[transactional] pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult { - let sender = ensure_signed(origin)?; + 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)?; @@ -923,7 +923,7 @@ #[transactional] pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult { - let sender = ensure_signed(origin)?; + 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)?; @@ -946,9 +946,9 @@ /// * new_owner. #[weight = ::WeightInfo::change_collection_owner()] #[transactional] - pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult { + pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::CrossAccountId) -> DispatchResult { - let sender = ensure_signed(origin)?; + 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)?; target_collection.owner = new_owner; @@ -972,9 +972,9 @@ /// * new_admin_id: Address of new admin to add. #[weight = ::WeightInfo::add_collection_admin()] #[transactional] - pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::AccountId) -> DispatchResult { + pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult { - let sender = ensure_signed(origin)?; + let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let collection = Self::get_collection(collection_id)?; Self::check_owner_or_admin_permissions(&collection, sender)?; let mut admin_arr = >::get(collection_id); @@ -1005,9 +1005,9 @@ /// * account_id: Address of admin to remove. #[weight = ::WeightInfo::remove_collection_admin()] #[transactional] - pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::AccountId) -> DispatchResult { + pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult { - let sender = ensure_signed(origin)?; + let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let collection = Self::get_collection(collection_id)?; Self::check_owner_or_admin_permissions(&collection, sender)?; let mut admin_arr = >::get(collection_id); @@ -1034,10 +1034,9 @@ #[weight = ::WeightInfo::set_collection_sponsor()] #[transactional] pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult { - - let sender = ensure_signed(origin)?; + 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)?; target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor); Self::save_collection(target_collection); @@ -1055,7 +1054,6 @@ #[weight = ::WeightInfo::confirm_sponsorship()] #[transactional] pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult { - let sender = ensure_signed(origin)?; let mut target_collection = Self::get_collection(collection_id)?; @@ -1082,7 +1080,6 @@ #[weight = ::WeightInfo::remove_collection_sponsor()] #[transactional] pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult { - let sender = ensure_signed(origin)?; let mut target_collection = Self::get_collection(collection_id)?; @@ -1739,7 +1736,7 @@ collection_id: u32, new_limits: CollectionLimits, ) -> DispatchResult { - let sender = ensure_signed(origin)?; + 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.clone())?; let old_limits = &target_collection.limits; -- gitstuff