From a5075eaae1f312f92f41a66703b60f01568667ec Mon Sep 17 00:00:00 2001 From: kozyrevdev <73348153+kozyrevdev@users.noreply.github.com> Date: Thu, 02 Dec 2021 21:24:15 +0000 Subject: [PATCH] Merge pull request #250 from UniqueNetwork/feature/CORE-221 CORE-221 --- --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -187,6 +187,13 @@ /// * account_id: Collection owner. CollectionCreated(CollectionId, u8, T::AccountId), + /// New collection was destroyed + /// + /// # Arguments + /// + /// * collection_id: Globally unique identifier of collection. + CollectionDestroyed(CollectionId), + /// New item was created. /// /// # Arguments @@ -467,6 +474,8 @@ >::remove(collection.id); >::remove_prefix((collection.id,), None); >::remove_prefix((collection.id,), None); + + >::deposit_event(Event::CollectionDestroyed(collection.id)); Ok(()) } --- a/pallets/unique/src/lib.rs +++ b/pallets/unique/src/lib.rs @@ -16,7 +16,7 @@ pub use serde::{Serialize, Deserialize}; pub use frame_support::{ - construct_runtime, decl_module, decl_storage, decl_error, + construct_runtime, decl_module, decl_storage, decl_error, decl_event, dispatch::DispatchResult, ensure, fail, parameter_types, traits::{ @@ -87,6 +87,7 @@ OwnerPermissionsCantBeReverted, } } + pub trait Config: system::Config + pallet_evm_coder_substrate::Config @@ -97,10 +98,141 @@ + Sized + TypeInfo { + type Event: From> + Into<::Event>; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; } +decl_event! { + pub enum Event + where + ::AccountId, + ::CrossAccountId, + { + /// Collection sponsor was removed + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + CollectionSponsorRemoved(CollectionId), + + /// Collection admin was added + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + /// + /// * admin: Admin address. + CollectionAdminAdded(CollectionId, CrossAccountId), + + /// Collection owned was change + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + /// + /// * owner: New owner address. + CollectionOwnedChanged(CollectionId, AccountId), + + /// Collection sponsor was set + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + /// + /// * owner: New sponsor address. + CollectionSponsorSet(CollectionId, AccountId), + + /// const on chain schema was set + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + ConstOnChainSchemaSet(CollectionId), + + /// New sponsor was confirm + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + /// + /// * sponsor: New sponsor address. + SponsorshipConfirmed(CollectionId, AccountId), + + /// Collection admin was removed + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + /// + /// * admin: Admin address. + CollectionAdminRemoved(CollectionId, CrossAccountId), + + /// Address was remove from allow list + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + /// + /// * user: Address. + AllowListAddressRemoved(CollectionId, CrossAccountId), + + /// Address was add to allow list + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + /// + /// * user: Address. + AllowListAddressAdded(CollectionId, CrossAccountId), + + /// Collection limits was set + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + CollectionLimitSet(CollectionId), + + /// Mint permission was set + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + MintPermissionSet(CollectionId), + + /// Offchain schema was set + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + OffchainSchemaSet(CollectionId), + + /// Public access mode was set + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + /// + /// * mode: New access state. + PublicAccessModeSet(CollectionId, AccessMode), + + /// Schema version was set + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + SchemaVersionSet(CollectionId), + + /// Variable on chain schema was set + /// + /// # Arguments + /// + /// * collection_id: Globally unique collection identifier. + VariableOnChainSchemaSet(CollectionId), + } +} + type SelfWeightOf = ::WeightInfo; // # Used definitions @@ -162,6 +294,8 @@ { type Error = Error; + fn deposit_event() = default; + fn on_initialize(_now: T::BlockNumber) -> Weight { 0 } @@ -289,6 +423,11 @@ true, )?; + Self::deposit_event(Event::::AllowListAddressAdded( + collection_id, + address + )); + Ok(()) } @@ -318,6 +457,11 @@ false, )?; + >::deposit_event(Event::::AllowListAddressRemoved( + collection_id, + address + )); + Ok(()) } @@ -341,7 +485,13 @@ let mut target_collection = >::try_get(collection_id)?; target_collection.check_is_owner(&sender)?; - target_collection.access = mode; + target_collection.access = mode.clone(); + + >::deposit_event(Event::::PublicAccessModeSet( + collection_id, + mode + )); + target_collection.save() } @@ -368,6 +518,11 @@ target_collection.check_is_owner(&sender)?; target_collection.mint_mode = mint_permission; + + >::deposit_event(Event::::MintPermissionSet( + collection_id + )); + target_collection.save() } @@ -391,7 +546,12 @@ let mut target_collection = >::try_get(collection_id)?; target_collection.check_is_owner(&sender)?; - target_collection.owner = new_owner; + target_collection.owner = new_owner.clone(); + >::deposit_event(Event::::CollectionOwnedChanged( + collection_id, + new_owner + )); + target_collection.save() } @@ -414,6 +574,11 @@ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let collection = >::try_get(collection_id)?; + >::deposit_event(Event::::CollectionAdminAdded( + collection_id, + new_admin_id.clone() + )); + >::toggle_admin(&collection, &sender, &new_admin_id, true) } @@ -435,6 +600,11 @@ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let collection = >::try_get(collection_id)?; + >::deposit_event(Event::::CollectionAdminRemoved( + collection_id, + account_id.clone() + )); + >::toggle_admin(&collection, &sender, &account_id, false) } @@ -455,7 +625,13 @@ let mut target_collection = >::try_get(collection_id)?; target_collection.check_is_owner(&sender)?; - target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor); + target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone()); + + >::deposit_event(Event::::CollectionSponsorSet( + collection_id, + new_sponsor + )); + target_collection.save() } @@ -477,7 +653,13 @@ Error::::ConfirmUnsetSponsorFail ); - target_collection.sponsorship = SponsorshipState::Confirmed(sender); + target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone()); + + >::deposit_event(Event::::SponsorshipConfirmed( + collection_id, + sender + )); + target_collection.save() } @@ -499,6 +681,10 @@ target_collection.check_is_owner(&sender)?; target_collection.sponsorship = SponsorshipState::Disabled; + + >::deposit_event(Event::::CollectionSponsorRemoved( + collection_id + )); target_collection.save() } @@ -793,6 +979,11 @@ let mut target_collection = >::try_get(collection_id)?; target_collection.check_is_owner_or_admin(&sender)?; target_collection.schema_version = version; + + >::deposit_event(Event::::SchemaVersionSet( + collection_id + )); + target_collection.save() } @@ -823,6 +1014,11 @@ ensure!(schema.len() as u32 <= OFFCHAIN_SCHEMA_LIMIT, ""); target_collection.offchain_schema = schema; + + >::deposit_event(Event::::OffchainSchemaSet( + collection_id + )); + target_collection.save() } @@ -853,6 +1049,11 @@ ensure!(schema.len() as u32 <= CONST_ON_CHAIN_SCHEMA_LIMIT, ""); target_collection.const_on_chain_schema = schema; + + >::deposit_event(Event::::ConstOnChainSchemaSet( + collection_id + )); + target_collection.save() } @@ -883,6 +1084,11 @@ ensure!(schema.len() as u32 <= VARIABLE_ON_CHAIN_SCHEMA_LIMIT, ""); target_collection.variable_on_chain_schema = schema; + + >::deposit_event(Event::::VariableOnChainSchemaSet( + collection_id + )); + target_collection.save() } @@ -949,6 +1155,10 @@ target_collection.limits = new_limit; + >::deposit_event(Event::::CollectionLimitSet( + collection_id + )); + target_collection.save() } } --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -781,6 +781,7 @@ } impl pallet_unique::Config for Runtime { + type Event = Event; type WeightInfo = pallet_unique::weights::SubstrateWeight; } @@ -881,7 +882,7 @@ // Unique Pallets Inflation: pallet_inflation::{Pallet, Call, Storage} = 60, - Unique: pallet_unique::{Pallet, Call, Storage} = 61, + Unique: pallet_unique::{Pallet, Call, Storage, Event} = 61, // Scheduler: pallet_unq_scheduler::{Pallet, Call, Storage, Event} = 62, // free = 63 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64, -- gitstuff