mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
Generate storage info for pallet im_online (#9654)
* Integrating WrapperOpaque from PR #9738 * Adding storage_info to pallet im-online Changing some `Vec` to `WeakBoundedVec` Adding the following bounds: * `MaxKeys * `MaxPeerInHeartbeats` * `MaxPeerDataEncodingSize` to limit the size of `WeakBoundedVec` * Fix syntax * Need to clone keys * Changes in formatting
This commit is contained in:
@@ -52,7 +52,7 @@ mod misc;
|
||||
pub use misc::{
|
||||
Backing, ConstU32, EnsureInherentsAreFirst, EstimateCallFee, ExecuteBlock, ExtrinsicCall, Get,
|
||||
GetBacking, GetDefault, HandleLifetime, IsSubType, IsType, Len, OffchainWorker,
|
||||
OnKilledAccount, OnNewAccount, SameOrOther, Time, TryDrop, UnixTime,
|
||||
OnKilledAccount, OnNewAccount, SameOrOther, Time, TryDrop, UnixTime, WrapperOpaque,
|
||||
};
|
||||
|
||||
mod stored_map;
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
|
||||
//! Smaller traits used in FRAME which don't need their own file.
|
||||
|
||||
use crate::dispatch::Parameter;
|
||||
use crate::{dispatch::Parameter, TypeInfo};
|
||||
use codec::{Decode, Encode, EncodeLike, Input, MaxEncodedLen};
|
||||
use sp_runtime::{traits::Block as BlockT, DispatchError};
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
/// Anything that can have a `::len()` method.
|
||||
pub trait Len {
|
||||
@@ -377,3 +379,48 @@ impl<Call, Balance: From<u32>, const T: u32> EstimateCallFee<Call, Balance> for
|
||||
T.into()
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper for any type `T` which implement encode/decode in a way compatible with `Vec<u8>`.
|
||||
///
|
||||
/// The encoding is the encoding of `T` prepended with the compact encoding of its size in bytes.
|
||||
/// Thus the encoded value can be decoded as a `Vec<u8>`.
|
||||
#[derive(Debug, Eq, PartialEq, Default, Clone, MaxEncodedLen, TypeInfo)]
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct WrapperOpaque<T>(pub T);
|
||||
|
||||
impl<T: Encode> EncodeLike for WrapperOpaque<T> {}
|
||||
|
||||
impl<T: Encode> Encode for WrapperOpaque<T> {
|
||||
fn size_hint(&self) -> usize {
|
||||
// Compact<u32> usually takes at most 4 bytes
|
||||
self.0.size_hint().saturating_add(4)
|
||||
}
|
||||
|
||||
fn encode_to<O: codec::Output + ?Sized>(&self, dest: &mut O) {
|
||||
self.0.encode().encode_to(dest);
|
||||
}
|
||||
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
self.0.encode().encode()
|
||||
}
|
||||
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.encode().using_encoded(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Decode> Decode for WrapperOpaque<T> {
|
||||
fn decode<I: Input>(input: &mut I) -> Result<Self, codec::Error> {
|
||||
Ok(Self(T::decode(&mut &<Vec<u8>>::decode(input)?[..])?))
|
||||
}
|
||||
|
||||
fn skip<I: Input>(input: &mut I) -> Result<(), codec::Error> {
|
||||
<Vec<u8>>::skip(input)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<T> for WrapperOpaque<T> {
|
||||
fn from(t: T) -> Self {
|
||||
Self(t)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//! Traits for dealing with validation and validators.
|
||||
|
||||
use crate::{dispatch::Parameter, weights::Weight};
|
||||
use codec::{Codec, Decode};
|
||||
use codec::{Codec, Decode, MaxEncodedLen};
|
||||
use sp_runtime::{
|
||||
traits::{Convert, Zero},
|
||||
BoundToRuntimeAppPublic, ConsensusEngineId, Permill, RuntimeAppPublic,
|
||||
@@ -31,7 +31,7 @@ use sp_std::prelude::*;
|
||||
/// Something that can give information about the current validator set.
|
||||
pub trait ValidatorSet<AccountId> {
|
||||
/// Type for representing validator id in a session.
|
||||
type ValidatorId: Parameter;
|
||||
type ValidatorId: Parameter + MaxEncodedLen;
|
||||
/// A type for converting `AccountId` to `ValidatorId`.
|
||||
type ValidatorIdOf: Convert<AccountId, Option<Self::ValidatorId>>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user