|
@@ -54,8 +54,11 @@ mod types;
|
|
|
use frame_support::dispatch::{DispatchError, DispatchResult};
|
|
|
use frame_support::sp_runtime::SaturatedConversion;
|
|
|
use frame_support::traits::Get;
|
|
|
-use frame_support::{decl_error, decl_event, decl_module, decl_storage, ensure, Parameter};
|
|
|
+use frame_support::{
|
|
|
+ decl_error, decl_event, decl_module, decl_storage, ensure, weights::Weight, Parameter,
|
|
|
+};
|
|
|
use sp_std::clone::Clone;
|
|
|
+use sp_std::convert::TryInto;
|
|
|
use sp_std::vec::Vec;
|
|
|
|
|
|
use common::origin::ActorOriginValidator;
|
|
@@ -65,6 +68,12 @@ pub use types::ThreadMode;
|
|
|
|
|
|
type MemberId<T> = <T as membership::Trait>::MemberId;
|
|
|
|
|
|
+pub trait WeightInfo {
|
|
|
+ fn add_post(i: u32, j: u32) -> Weight;
|
|
|
+ fn update_post() -> Weight; // Note: since parameter doesn't affect weight it's discarded
|
|
|
+ fn change_thread_mode(i: u32) -> Weight;
|
|
|
+}
|
|
|
+
|
|
|
decl_event!(
|
|
|
/// Proposals engine events
|
|
|
pub enum Event<T>
|
|
@@ -112,6 +121,9 @@ pub trait Trait: frame_system::Trait + membership::Trait {
|
|
|
|
|
|
/// Defines author list size limit for the Closed discussion.
|
|
|
type MaxWhiteListSize: Get<u32>;
|
|
|
+
|
|
|
+ /// Weight information for extrinsics in this pallet.
|
|
|
+ type WeightInfo: WeightInfo;
|
|
|
}
|
|
|
|
|
|
decl_error! {
|
|
@@ -170,7 +182,10 @@ decl_module! {
|
|
|
fn deposit_event() = default;
|
|
|
|
|
|
/// Adds a post with author origin check.
|
|
|
- #[weight = 10_000_000] // TODO: adjust weight
|
|
|
+ #[weight = <T as Trait>::WeightInfo::add_post(
|
|
|
+ T::MaxWhiteListSize::get(),
|
|
|
+ _text.len().try_into().unwrap()
|
|
|
+ )]
|
|
|
pub fn add_post(
|
|
|
origin,
|
|
|
post_author_id: MemberId<T>,
|
|
@@ -202,7 +217,7 @@ decl_module! {
|
|
|
}
|
|
|
|
|
|
/// Updates a post with author origin check. Update attempts number is limited.
|
|
|
- #[weight = 10_000_000] // TODO: adjust weight
|
|
|
+ #[weight = <T as Trait>::WeightInfo::update_post()]
|
|
|
pub fn update_post(
|
|
|
origin,
|
|
|
post_author_id: MemberId<T>,
|
|
@@ -228,7 +243,13 @@ decl_module! {
|
|
|
}
|
|
|
|
|
|
/// Changes thread permission mode.
|
|
|
- #[weight = 10_000_000] // TODO: adjust weight
|
|
|
+ #[weight = <T as Trait>::WeightInfo::change_thread_mode(
|
|
|
+ if let ThreadMode::Closed(ref list) = mode {
|
|
|
+ list.len().try_into().unwrap()
|
|
|
+ } else {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ )]
|
|
|
pub fn change_thread_mode(
|
|
|
origin,
|
|
|
member_id: MemberId<T>,
|
|
@@ -260,6 +281,7 @@ decl_module! {
|
|
|
<ThreadById<T>>::mutate(thread_id, |thread| {
|
|
|
thread.mode = mode.clone();
|
|
|
});
|
|
|
+
|
|
|
Self::deposit_event(RawEvent::ThreadModeChanged(thread_id, mode));
|
|
|
}
|
|
|
}
|