mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 19:37:56 +00:00
Add Storage Info to Various Pallets (#10810)
* atomic swap * bounties * bounties fmt * gilt * indices * nicks * randomness-collective-flip * recovery * reuse maxapprovals * Update tests.rs * Update frame/randomness-collective-flip/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * use the correct bound * complete recovery * use `bounded_vec` macro * Update tests.rs * transaction payment * uniques * mmr * example offchain worker * beefy-mmr * Update frame/recovery/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use BoundedVec instead of a type-parameterized BoundedString * cargo fmt * Update frame/atomic-swap/src/lib.rs * use config const * Update lib.rs * update mel_bound * fmt Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -154,11 +154,14 @@ pub mod pallet {
|
||||
/// multiple pallets send unsigned transactions.
|
||||
#[pallet::constant]
|
||||
type UnsignedPriority: Get<TransactionPriority>;
|
||||
|
||||
/// Maximum number of prices.
|
||||
#[pallet::constant]
|
||||
type MaxPrices: Get<u32>;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
@@ -330,7 +333,7 @@ pub mod pallet {
|
||||
/// This is used to calculate average price, should have bounded size.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn prices)]
|
||||
pub(super) type Prices<T: Config> = StorageValue<_, Vec<u32>, ValueQuery>;
|
||||
pub(super) type Prices<T: Config> = StorageValue<_, BoundedVec<u32, T::MaxPrices>, ValueQuery>;
|
||||
|
||||
/// Defines the block when next unsigned transaction will be accepted.
|
||||
///
|
||||
@@ -645,12 +648,8 @@ impl<T: Config> Pallet<T> {
|
||||
fn add_price(maybe_who: Option<T::AccountId>, price: u32) {
|
||||
log::info!("Adding to the average: {}", price);
|
||||
<Prices<T>>::mutate(|prices| {
|
||||
const MAX_LEN: usize = 64;
|
||||
|
||||
if prices.len() < MAX_LEN {
|
||||
prices.push(price);
|
||||
} else {
|
||||
prices[price as usize % MAX_LEN] = price;
|
||||
if prices.try_push(price).is_err() {
|
||||
prices[(price % T::MaxPrices::get()) as usize] = price;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user