Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

update kill storage #13

Merged
merged 2 commits into from
Sep 22, 2023
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
5 changes: 4 additions & 1 deletion pallets/afloat/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,14 @@ 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 10b75e - 10b75e:

  • Modified the do_cancel_offer function to take an additional parameter who to identify the caller
  • Added a check to ensure that the caller is either an admin or the owner of the offer before allowing the offer to be cancelled

}

pub fn do_cancel_offer(order_id: StorageId) -> DispatchResult {
pub fn do_cancel_offer(who: T::AccountId, order_id: StorageId) -> DispatchResult {
// ensure offer exists
ensure!(<AfloatOffers<T>>::contains_key(order_id), Error::<T>::OfferNotFound);
//get offer details
let offer = <AfloatOffers<T>>::get(order_id).unwrap();
let is_admin_or_owner = Self::is_admin_or_owner(who.clone())?;
ensure!(is_admin_or_owner || offer.creator_id == who, Error::<T>::Unauthorized);

match offer.status {
OfferStatus::CREATED => {
<AfloatOffers<T>>::try_mutate(order_id, |offer| -> DispatchResult {
Expand Down
39 changes: 33 additions & 6 deletions pallets/afloat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,40 @@ 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 d1cb4c - d1cb4c:

  • Added a new argument args to kill_storage function
  • Removed the check for admin/owner from cancel_offer function
  • Added logic to kill_storage for different types of storage (user info, afloat market place id, afloat collection id, afloat asset id, afloat offers, afloat transactions)

#[pallet::call_index(1)]
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))]
pub fn kill_storage(origin: OriginFor<T>) -> DispatchResult {
pub fn kill_storage(origin: OriginFor<T>, args: KillStorageArgs) -> DispatchResult {
// ensure sudo origin
T::RemoveOrigin::ensure_origin(origin.clone())?;
Self::do_delete_all_users()?;
Ok(())
match args {
KillStorageArgs::All => {
Self::do_delete_all_users()?;
<AfloatMarketPlaceId<T>>::kill();
<AfloatCollectionId<T>>::kill();
<AfloatAssetId<T>>::kill();
let _ = <AfloatOffers<T>>::clear(1000, None);
let _ = <AfloatTransactions<T>>::clear(1000, None);
},
KillStorageArgs::UserInfo => {
Self::do_delete_all_users()?;
}
KillStorageArgs::AfloatMarketPlaceId => {
<AfloatMarketPlaceId<T>>::kill();
},
KillStorageArgs::AfloatCollectionId => {
<AfloatCollectionId<T>>::kill();
},
KillStorageArgs::AfloatAssetId => {
<AfloatAssetId<T>>::kill();
},
KillStorageArgs::AfloatOffers => {
let _ = <AfloatOffers<T>>::clear(1000, None);
},
KillStorageArgs::AfloatTransactions => {
let _ = <AfloatTransactions<T>>::clear(1000, None);
},

}

Ok(())
}

#[pallet::call_index(2)]
Expand Down Expand Up @@ -404,9 +433,7 @@ pub mod pallet {
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))]
pub fn cancel_offer(origin: OriginFor<T>, order_id: StorageId) -> 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);
Self::do_cancel_offer(order_id)
Self::do_cancel_offer(who, order_id)
}
}
}
11 changes: 11 additions & 0 deletions pallets/afloat/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ pub enum CreateOfferArgs<T: Config> {
},

Choose a reason for hiding this comment

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

GPT summary of a77fb3 - a77fb3:

  • Added a new enum KillStorageArgs with variants All, UserInfo, AfloatMarketPlaceId, AfloatCollectionId, AfloatAssetId, AfloatOffers, and AfloatTransactions.

}

#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebugNoBound, TypeInfo)]
pub enum KillStorageArgs {
All,
UserInfo,
AfloatMarketPlaceId,
AfloatCollectionId,
AfloatAssetId,
AfloatOffers,
AfloatTransactions,
}

// ! Transaction structures

#[derive(CloneNoBound, Encode, Decode, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen, PartialEq)]
Expand Down