Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
rename BoundedEncodedLen -> MaxEncodedLen
Browse files Browse the repository at this point in the history
  • Loading branch information
coriolinus committed May 4, 2021
1 parent f18183a commit af0b814
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions 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, BoundedEncodedLen},
traits::{Get, MaxEncodedLen},
storage::{generator, StorageDecodeLength, StorageValue, StorageMap, StorageDoubleMap},
};

Expand Down Expand Up @@ -319,9 +319,9 @@ impl<
}
}

impl<T, S> BoundedEncodedLen for BoundedVec<T, S>
impl<T, S> MaxEncodedLen for BoundedVec<T, S>
where
T: BoundedVecValue + BoundedEncodedLen,
T: BoundedVecValue + MaxEncodedLen,
S: Get<u32>,
BoundedVec<T, S>: Encode,
{
Expand Down
4 changes: 2 additions & 2 deletions frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ pub use dispatch::{EnsureOrigin, OriginTrait, UnfilteredDispatchable};
mod voting;
pub use voting::{CurrencyToVote, SaturatingCurrencyToVote, U128CurrencyToVote};

mod bounded_encoded_length;
pub use bounded_encoded_length::BoundedEncodedLen;
mod max_encoded_len;
pub use max_encoded_len::MaxEncodedLen;
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ use codec::{Compact, Encode};
use impl_trait_for_tuples::impl_for_tuples;
use sp_std::{mem, marker::PhantomData};

/// Items implementing `BoundedEncodedLen` have a statically known maximum encoded size.
/// Items implementing `MaxEncodedLen` have a statically known maximum encoded size.
///
/// Some containers, such as `BoundedVec`, have enforced size limits and this trait
/// can be implemented accurately. Other containers, such as `StorageMap`, do not have enforced size
/// limits. For those containers, it is necessary to make a documented assumption about the maximum
/// usage, and compute the max encoded length based on that assumption.
pub trait BoundedEncodedLen: Encode {
pub trait MaxEncodedLen: Encode {
/// Upper bound, in bytes, of the maximum encoded size of this item.
fn max_encoded_len() -> usize;
}

macro_rules! impl_primitives {
( $($t:ty),+ ) => {
$(
impl BoundedEncodedLen for $t {
impl MaxEncodedLen for $t {
fn max_encoded_len() -> usize {
mem::size_of::<$t>()
}
Expand All @@ -47,7 +47,7 @@ impl_primitives!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, bool);
macro_rules! impl_compact {
($( $t:ty => $e:expr; )*) => {
$(
impl BoundedEncodedLen for Compact<$t> {
impl MaxEncodedLen for Compact<$t> {
fn max_encoded_len() -> usize {
$e
}
Expand All @@ -71,37 +71,37 @@ impl_compact!(

// impl_for_tuples for values 19 and higher fails because that's where the WrapperTypeEncode impl stops.
#[impl_for_tuples(18)]
impl BoundedEncodedLen for Tuple {
impl MaxEncodedLen for Tuple {
fn max_encoded_len() -> usize {
let mut len: usize = 0;
for_tuples!( #( len = len.saturating_add(Tuple::max_encoded_len()); )* );
len
}
}

impl<T: BoundedEncodedLen, const N: usize> BoundedEncodedLen for [T; N] {
impl<T: MaxEncodedLen, const N: usize> MaxEncodedLen for [T; N] {
fn max_encoded_len() -> usize {
T::max_encoded_len().saturating_mul(N)
}
}

impl<T: BoundedEncodedLen> BoundedEncodedLen for Option<T> {
impl<T: MaxEncodedLen> MaxEncodedLen for Option<T> {
fn max_encoded_len() -> usize {
T::max_encoded_len().saturating_add(1)
}
}

impl<T, E> BoundedEncodedLen for Result<T, E>
impl<T, E> MaxEncodedLen for Result<T, E>
where
T: BoundedEncodedLen,
E: BoundedEncodedLen,
T: MaxEncodedLen,
E: MaxEncodedLen,
{
fn max_encoded_len() -> usize {
T::max_encoded_len().max(E::max_encoded_len()).saturating_add(1)
}
}

impl<T> BoundedEncodedLen for PhantomData<T> {
impl<T> MaxEncodedLen for PhantomData<T> {
fn max_encoded_len() -> usize {
0
}
Expand Down

0 comments on commit af0b814

Please sign in to comment.