-
Notifications
You must be signed in to change notification settings - Fork 0
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
update pallets #12
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,11 +255,40 @@ pub mod pallet { | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
#[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)] | ||
|
@@ -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) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,6 +161,17 @@ pub enum CreateOfferArgs<T: Config> { | |
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
#[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)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"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"] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ pub mod pallet { | |
use frame_support::traits::Time; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GPT summary of 937974 - c6aced:
|
||
|
||
use crate::types::*; | ||
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
|
@@ -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 ---*/ | ||
|
@@ -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, | ||
|
@@ -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>, | ||
|
@@ -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{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use crate::{mock::*, types::*, Records, Error}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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 { | ||
|
@@ -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() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,7 @@ parameter_types! { | |
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
impl pallet_rbac::Config for Test { | ||
type RuntimeEvent = RuntimeEvent; | ||
type RemoveOrigin = EnsureRoot<Self::AccountId>; | ||
type MaxScopesPerPallet = MaxScopesPerPallet; | ||
type MaxRolesPerPallet = MaxRolesPerPallet; | ||
type RoleMaxLen = RoleMaxLen; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use crate as pallet_gated_marketplace; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
use frame_support::{ | ||
construct_runtime, parameter_types, | ||
parameter_types, | ||
traits::{AsEnsureOriginWithArg, ConstU32, ConstU64, GenesisBuild}, | ||
}; | ||
use frame_system as system; | ||
|
@@ -253,4 +253,4 @@ impl pallet_mapped_assets::Config for Test { | |
type RemoveItemsLimit = ConstU32<5>; | ||
type MaxReserves = MaxReserves; | ||
type ReserveIdentifier = u32; | ||
} | ||
C} |
There was a problem hiding this comment.
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:
do_cancel_offer()
to include anAccountId
argumentCREATED
before attempting to cancel