Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from all 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
17 changes: 16 additions & 1 deletion frame/support/src/storage/bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sp_std::prelude::*;
use sp_std::{convert::TryFrom, marker::PhantomData};
use codec::{FullCodec, Encode, EncodeLike, Decode};
use crate::{
traits::Get,
traits::{Get, BoundedEncodedLen},
storage::{generator, StorageDecodeLength, StorageValue, StorageMap, StorageDoubleMap},
};

Expand Down Expand Up @@ -319,6 +319,21 @@ impl<
}
}

impl<T, S> BoundedEncodedLen for BoundedVec<T, S>
where
T: BoundedVecValue + BoundedEncodedLen,
S: Get<u32>,
BoundedVec<T, S>: Encode,
{
fn max_encoded_len() -> usize {
// BoundedVec<T, S> encodes like Vec<T> which encodes like [T], which is a compact u32
// plus each item in the slice:
// https://substrate.dev/rustdocs/v3.0.0/src/parity_scale_codec/codec.rs.html#798-808
codec::Compact::<u32>::max_encoded_len()
.saturating_add(Self::bound().saturating_mul(T::max_encoded_len()))
}
}

#[cfg(test)]
pub mod test {
use super::*;
Expand Down