Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

update pallets #12

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1,319 changes: 219 additions & 1,100 deletions Cargo.lock

Large diffs are not rendered by default.

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 c00078 - 10b75e:

  • Changed the signature of do_cancel_offer() to include an AccountId argument
  • Added a check to ensure that the caller is either an admin or the owner of the offer
  • Added a check to ensure that the offer exists
  • Added a check to ensure that the offer status is CREATED before attempting to cancel

}

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 ea5b04 - d1cb4c:

  • Added an argument to the kill_storage function, allowing for more granular control over what is deleted from storage
  • Added a check to ensure that only an admin or owner can cancel an offer

#[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 bafac0 - a77fb3:

  • Added new KillStorageArgs enum with 8 variants.
  • Updated CreateOfferArgs struct.

}

#[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
14 changes: 7 additions & 7 deletions pallets/fund-admin-records/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
scale-info = { version = "2.0.1", default-features = false, features = [

Choose a reason for hiding this comment

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

GPT summary of c61877 - 5a11db:

  • Updated the version of codec, scale-info, frame-support, frame-system, frame-benchmarking, sp-runtime, pallet-timestamp, sp-core, and sp-io to polkadot-v0.9.40.

"derive"
] }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", optional = true }
sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
pallet-timestamp = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", optional = true }
sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
pallet-timestamp = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }

[dev-dependencies]
sp-core = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38" }
sp-core = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }

[features]
default = ["std"]
Expand Down
9 changes: 5 additions & 4 deletions pallets/fund-admin-records/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod pallet {
use frame_support::traits::Time;

Choose a reason for hiding this comment

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

GPT summary of 937974 - c6aced:

  • Added a constant STORAGE_VERSION
  • Updated pallet annotation to include storage_version
  • Updated weight annotations to use Weight::from_parts
  • Added a function set_signer_account to set the account id of the signer
  • Added a function add_record to add a record to the storage
  • Added a function kill_storage to clear the storage


use crate::types::*;
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::config]
pub trait Config: frame_system::Config {
Expand All @@ -45,7 +46,7 @@ pub mod pallet {
}

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

/*--- Onchain storage section ---*/
Expand Down Expand Up @@ -113,7 +114,7 @@ pub mod pallet {
/// * `signer_account` - The account id of the signer
/// Returns `Ok` if the operation is successful, `Err` otherwise.
#[pallet::call_index(1)]
#[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().writes(10))]
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(10))]
pub fn set_signer_account(
origin: OriginFor<T>,
account: T::AccountId,
Expand All @@ -136,7 +137,7 @@ pub mod pallet {
/// If the function executes successfully without any error, it will return `Ok(())`.
/// If there is an error, it will return `Err(error)`, where `error` is an instance of the `DispatchError` class.
#[pallet::call_index(2)]
#[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().writes(10))]
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(10))]
pub fn add_record(
origin: OriginFor<T>,
records: RecordCollection<T>,
Expand All @@ -163,7 +164,7 @@ pub mod pallet {
/// ### Considerations:
/// - This function is only available to the `admin` with sudo access.
#[pallet::call_index(3)]
#[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().writes(10))]
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(10))]
pub fn kill_storage(
origin: OriginFor<T>,
) -> DispatchResult{
Expand Down
42 changes: 21 additions & 21 deletions pallets/fund-admin-records/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{mock::*, types::*, Records, Error};

Choose a reason for hiding this comment

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

GPT summary of b54509 - e1cf0a:

  • Imported frame_support and removed BoundedVec and ConstU32 traits from it
  • Commented out make_default_record_collection() and make_array_record_collection() functions

use frame_support::{assert_ok, assert_noop, bounded_vec, BoundedVec, traits::ConstU32};
use frame_support::{assert_ok, assert_noop, bounded_vec};


fn make_project_id(v: &str) -> ProjectId {
Expand Down Expand Up @@ -28,27 +28,27 @@ fn make_record_collection(
record_collection
}

fn make_default_record_collection() -> RecordCollection<Test> {
make_record_collection(
make_project_id("project_id"),
make_hashed_info("hashed_info"),
TableType::Drawdown,
RecordType::Creation,
)
}
// fn make_default_record_collection() -> RecordCollection<Test> {
// make_record_collection(
// make_project_id("project_id"),
// make_hashed_info("hashed_info"),
// TableType::Drawdown,
// RecordType::Creation,
// )
// }

fn make_array_record_collection(num: u16) -> RecordCollection<Test> {
let mut record_collection: RecordCollection<Test> = bounded_vec![];
for i in 0..num {
record_collection.try_push((
make_project_id(&format!("project_id_{}", i)),
make_hashed_info(&format!("hashed_info_{}", i)),
TableType::Drawdown,
RecordType::Creation,
)).unwrap_or_default();
}
record_collection
}
// fn make_array_record_collection(num: u16) -> RecordCollection<Test> {
// let mut record_collection: RecordCollection<Test> = bounded_vec![];
// for i in 0..num {
// record_collection.try_push((
// make_project_id(&format!("project_id_{}", i)),
// make_hashed_info(&format!("hashed_info_{}", i)),
// TableType::Drawdown,
// RecordType::Creation,
// )).unwrap_or_default();
// }
// record_collection
// }

#[test]
fn set_signer_account_works() {
Expand Down
1 change: 1 addition & 0 deletions pallets/fund-admin/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ parameter_types! {
}

Choose a reason for hiding this comment

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

GPT summary of c0f871 - d9ec11:

  • Added a new type RemoveOrigin to the pallet_rbac::Config implementation for Test
  • RemoveOrigin is set to EnsureRoot<Self::AccountId>

impl pallet_rbac::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RemoveOrigin = EnsureRoot<Self::AccountId>;
type MaxScopesPerPallet = MaxScopesPerPallet;
type MaxRolesPerPallet = MaxRolesPerPallet;
type RoleMaxLen = RoleMaxLen;
Expand Down
4 changes: 2 additions & 2 deletions pallets/gated-marketplace/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate as pallet_gated_marketplace;

Choose a reason for hiding this comment

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

GPT summary of 4a9270 - 89fc58:

  • Updated the use statements in the beginning of the file
  • Updated the type statements at the end of the file

use frame_support::{
construct_runtime, parameter_types,
parameter_types,
traits::{AsEnsureOriginWithArg, ConstU32, ConstU64, GenesisBuild},
};
use frame_system as system;
Expand Down Expand Up @@ -253,4 +253,4 @@ impl pallet_mapped_assets::Config for Test {
type RemoveItemsLimit = ConstU32<5>;
type MaxReserves = MaxReserves;
type ReserveIdentifier = u32;
}
C}
Loading
Loading