Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions pallets/afloat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ pub mod types;
pub mod pallet {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT summary of 93b888 - 6a74f5:

  • Added NewUser, UserEdited, UserDeleted, SellOrderCreated, BuyOrderCreated, SellOrderTaken, BuyOrderTaken, AfloatBalanceSet, AdminAdded events
  • Added assign_user_to_role call which assigns a user to a role and emits UserAssignedToRoleAdded event

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::*;
Expand Down Expand Up @@ -56,16 +54,26 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
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.
Expand Down Expand Up @@ -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<T>,
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::<T>::Unauthorized);
ensure!(UserInfo::<T>::contains_key(user_address.clone()), Error::<T>::UserNotFound);
Self::give_role_to_user(user_address.clone(), role.clone())?;
Self::deposit_event(Event::UserAssignedToRoleAdded(who, user_address, role));
Ok(())
}
}
}
13 changes: 3 additions & 10 deletions pallets/gated-marketplace/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ impl<T: Config> Pallet<T> {
Ok(())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT summary of 977293 - f6924d:

  • Added a function do_create_marketplace to create a new marketplace.
  • The owner and admin are added to the marketplace as authorities.
  • Ensured the generated id is unique.
  • Inserted on marketplaces and marketplaces by auth.

}

/// 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<T>,
admin: T::AccountId,
Expand All @@ -53,22 +56,12 @@ impl<T: Config> Pallet<T> {
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!(
!<Marketplaces<T>>::contains_key(marketplace_id),
Error::<T>::MarketplaceAlreadyExists
);
// Create asset
// pallet_mapped_assets::Pallet::<T>::create(
// origin,
// asset_id,
// T::Lookup::unlookup(owner.clone()),
// min_balance,
// )?;
//Insert on marketplaces and marketplaces by auth
<T as pallet::Config>::Rbac::create_scope(Self::pallet_id(), marketplace_id)?;
Self::insert_in_auth_market_lists(owner.clone(), MarketplaceRole::Owner, marketplace_id)?;
Expand Down