diff --git a/pallets/afloat/src/lib.rs b/pallets/afloat/src/lib.rs index 93b8885e..6a74f517 100644 --- a/pallets/afloat/src/lib.rs +++ b/pallets/afloat/src/lib.rs @@ -15,13 +15,11 @@ pub mod types; pub mod pallet { use frame_support::{ pallet_prelude::*, - sp_io::hashing::blake2_256, traits::{Currency, UnixTime}, }; use frame_system::{pallet_prelude::*, RawOrigin}; use pallet_fruniques::types::{Attributes, CollectionDescription, FruniqueRole, ParentInfo}; use pallet_gated_marketplace::types::*; - use sp_runtime::{traits::StaticLookup, Permill}; const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); use crate::types::*; @@ -56,16 +54,26 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { - SomethingStored(u32, T::AccountId), + // New user created NewUser(T::AccountId), + // User edited UserEdited(T::AccountId), + // User deleted UserDeleted(T::AccountId), + // A sell created taken by an user SellOrderCreated(T::AccountId), + // A buy created taken by an user BuyOrderCreated(T::AccountId), + // A ell order taken by an user SellOrderTaken(T::AccountId), + // A buy order taken by an user BuyOrderTaken(T::AccountId), + // Updated balance to an account (who updated the balance, the account, the balance) AfloatBalanceSet(T::AccountId, T::AccountId, T::Balance), + // A new admin is added (who added the admin, the admin) AdminAdded(T::AccountId, T::AccountId), + // A user is assigned to a role (who assigned the role, the user, the role) + UserAssignedToRoleAdded(T::AccountId, T::AccountId, AfloatRole), } // Errors inform users that something went wrong. @@ -399,5 +407,21 @@ pub mod pallet { let who = ensure_signed(origin.clone())?; Self::do_cancel_offer(who, order_id) } + + #[pallet::call_index(12)] + #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + pub fn assign_user_to_role( + origin: OriginFor, + user_address: T::AccountId, + role: AfloatRole, + ) -> DispatchResult { + let who = ensure_signed(origin.clone())?; + let is_admin_or_owner = Self::is_admin_or_owner(who.clone())?; + ensure!(is_admin_or_owner, Error::::Unauthorized); + ensure!(UserInfo::::contains_key(user_address.clone()), Error::::UserNotFound); + Self::give_role_to_user(user_address.clone(), role.clone())?; + Self::deposit_event(Event::UserAssignedToRoleAdded(who, user_address, role)); + Ok(()) + } } } diff --git a/pallets/gated-marketplace/src/functions.rs b/pallets/gated-marketplace/src/functions.rs index 977293f2..f6924d9e 100644 --- a/pallets/gated-marketplace/src/functions.rs +++ b/pallets/gated-marketplace/src/functions.rs @@ -45,6 +45,9 @@ impl Pallet { Ok(()) } + /// Creates a new marketplace + /// The owner and admin are added to the marketplace as authorities + /// The asset_id is the currency of the marketplace and it's assumed to exist pub fn do_create_marketplace( origin: OriginFor, admin: T::AccountId, @@ -53,22 +56,12 @@ impl Pallet { let owner = ensure_signed(origin.clone())?; // Gen market id let marketplace_id = marketplace.using_encoded(blake2_256); - //Get asset id - let asset_id = marketplace.asset_id; - let min_balance: T::Balance = T::Balance::from(1u32); // ensure the generated id is unique ensure!( !>::contains_key(marketplace_id), Error::::MarketplaceAlreadyExists ); - // Create asset - // pallet_mapped_assets::Pallet::::create( - // origin, - // asset_id, - // T::Lookup::unlookup(owner.clone()), - // min_balance, - // )?; //Insert on marketplaces and marketplaces by auth ::Rbac::create_scope(Self::pallet_id(), marketplace_id)?; Self::insert_in_auth_market_lists(owner.clone(), MarketplaceRole::Owner, marketplace_id)?;