-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add Storage Info to Various Pallets #10810
Changes from all commits
fd44f6b
2b8a6f1
96a45bb
f15aaa9
b77f47a
b71d213
7fbd9f7
71e93b4
c4d49bf
7c843d2
3256e41
7dbf890
65d0fad
8c81ce9
478fa94
fc1b40d
5b81940
a7a3d38
8e3dc00
455eea4
79d058b
9c50192
744e9b6
0c906bb
5adffa9
f9b441d
54dc434
8115108
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,7 @@ type PositiveImbalanceOf<T> = pallet_treasury::PositiveImbalanceOf<T>; | |
| pub type BountyIndex = u32; | ||
|
|
||
| /// A bounty proposal. | ||
| #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)] | ||
| #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] | ||
| pub struct Bounty<AccountId, Balance, BlockNumber> { | ||
| /// The account proposing it. | ||
| proposer: AccountId, | ||
|
|
@@ -133,7 +133,7 @@ impl<AccountId: PartialEq + Clone + Ord, Balance, BlockNumber: Clone> | |
| } | ||
|
|
||
| /// The status of a bounty proposal. | ||
| #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)] | ||
| #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] | ||
| pub enum BountyStatus<AccountId, BlockNumber> { | ||
| /// The bounty is proposed and waiting for approval. | ||
| Proposed, | ||
|
|
@@ -180,7 +180,6 @@ pub mod pallet { | |
|
|
||
| #[pallet::pallet] | ||
| #[pallet::generate_store(pub(super) trait Store)] | ||
| #[pallet::without_storage_info] | ||
| pub struct Pallet<T>(_); | ||
|
|
||
| #[pallet::config] | ||
|
|
@@ -249,6 +248,8 @@ pub mod pallet { | |
| Premature, | ||
| /// The bounty cannot be closed because it has active child-bounties. | ||
| HasActiveChildBounty, | ||
| /// Too many approvals are already queued. | ||
| TooManyQueued, | ||
| } | ||
|
|
||
| #[pallet::event] | ||
|
|
@@ -288,12 +289,14 @@ pub mod pallet { | |
| /// The description of each bounty. | ||
| #[pallet::storage] | ||
| #[pallet::getter(fn bounty_descriptions)] | ||
| pub type BountyDescriptions<T: Config> = StorageMap<_, Twox64Concat, BountyIndex, Vec<u8>>; | ||
| pub type BountyDescriptions<T: Config> = | ||
| StorageMap<_, Twox64Concat, BountyIndex, BoundedVec<u8, T::MaximumReasonLength>>; | ||
|
|
||
| /// Bounty indices that have been approved but not yet funded. | ||
| #[pallet::storage] | ||
| #[pallet::getter(fn bounty_approvals)] | ||
| pub type BountyApprovals<T: Config> = StorageValue<_, Vec<BountyIndex>, ValueQuery>; | ||
| pub type BountyApprovals<T: Config> = | ||
| StorageValue<_, BoundedVec<BountyIndex, T::MaxApprovals>, ValueQuery>; | ||
|
|
||
| #[pallet::call] | ||
| impl<T: Config> Pallet<T> { | ||
|
|
@@ -341,7 +344,8 @@ pub mod pallet { | |
|
|
||
| bounty.status = BountyStatus::Approved; | ||
|
|
||
| BountyApprovals::<T>::append(bounty_id); | ||
| BountyApprovals::<T>::try_append(bounty_id) | ||
| .map_err(|()| Error::<T>::TooManyQueued)?; | ||
|
|
||
| Ok(()) | ||
| })?; | ||
|
|
@@ -780,17 +784,15 @@ impl<T: Config> Pallet<T> { | |
| description: Vec<u8>, | ||
| value: BalanceOf<T>, | ||
| ) -> DispatchResult { | ||
| ensure!( | ||
| description.len() <= T::MaximumReasonLength::get() as usize, | ||
| Error::<T>::ReasonTooBig | ||
| ); | ||
| let bounded_description: BoundedVec<_, _> = | ||
| description.try_into().map_err(|()| Error::<T>::ReasonTooBig)?; | ||
| ensure!(value >= T::BountyValueMinimum::get(), Error::<T>::InvalidValue); | ||
|
Member
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. Seeing how the
Member
Author
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. Honestly, I find that |
||
|
|
||
| let index = Self::bounty_count(); | ||
|
|
||
| // reserve deposit for new bounty | ||
| let bond = T::BountyDepositBase::get() + | ||
| T::DataDepositPerByte::get() * (description.len() as u32).into(); | ||
| T::DataDepositPerByte::get() * (bounded_description.len() as u32).into(); | ||
| T::Currency::reserve(&proposer, bond) | ||
| .map_err(|_| Error::<T>::InsufficientProposersBalance)?; | ||
|
|
||
|
|
@@ -806,7 +808,7 @@ impl<T: Config> Pallet<T> { | |
| }; | ||
|
|
||
| Bounties::<T>::insert(index, &bounty); | ||
| BountyDescriptions::<T>::insert(index, description); | ||
| BountyDescriptions::<T>::insert(index, bounded_description); | ||
|
|
||
| Self::deposit_event(Event::<T>::BountyProposed { index }); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.