mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 05:21:08 +00:00
add query types to generate_storage_alias (#9659)
* add query types to generate_storage_alias * adjust comment * use ValueQuery explicitly for generate_storage_alias with generic value type * bump impl_version * adjust line width and add import * more compilation and formatting fixes * formatting
This commit is contained in:
@@ -118,7 +118,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
// implementation changes and behavior does not, then leave spec_version as
|
||||
// is and increment impl_version.
|
||||
spec_version: 267,
|
||||
impl_version: 0,
|
||||
impl_version: 1,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 2,
|
||||
};
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
use codec::{Decode, Encode, FullCodec};
|
||||
use frame_support::{
|
||||
pallet_prelude::ValueQuery,
|
||||
traits::{PalletInfoAccess, StorageVersion},
|
||||
weights::Weight,
|
||||
RuntimeDebug, Twox64Concat,
|
||||
@@ -52,13 +53,22 @@ pub trait V2ToV3 {
|
||||
}
|
||||
|
||||
frame_support::generate_storage_alias!(
|
||||
PhragmenElection, Candidates<T: V2ToV3> => Value<Vec<(T::AccountId, T::Balance)>>
|
||||
PhragmenElection, Candidates<T: V2ToV3> => Value<
|
||||
Vec<(T::AccountId, T::Balance)>,
|
||||
ValueQuery
|
||||
>
|
||||
);
|
||||
frame_support::generate_storage_alias!(
|
||||
PhragmenElection, Members<T: V2ToV3> => Value<Vec<SeatHolder<T::AccountId, T::Balance>>>
|
||||
PhragmenElection, Members<T: V2ToV3> => Value<
|
||||
Vec<SeatHolder<T::AccountId, T::Balance>>,
|
||||
ValueQuery
|
||||
>
|
||||
);
|
||||
frame_support::generate_storage_alias!(
|
||||
PhragmenElection, RunnersUp<T: V2ToV3> => Value<Vec<SeatHolder<T::AccountId, T::Balance>>>
|
||||
PhragmenElection, RunnersUp<T: V2ToV3> => Value<
|
||||
Vec<SeatHolder<T::AccountId, T::Balance>>,
|
||||
ValueQuery
|
||||
>
|
||||
);
|
||||
frame_support::generate_storage_alias!(
|
||||
PhragmenElection, Voting<T: V2ToV3> => Map<
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
// limitations under the License.
|
||||
|
||||
use super::{Config, OffenceDetails, Perbill, SessionIndex};
|
||||
use frame_support::{generate_storage_alias, traits::Get, weights::Weight};
|
||||
use frame_support::{
|
||||
generate_storage_alias, pallet_prelude::ValueQuery, traits::Get, weights::Weight,
|
||||
};
|
||||
use sp_staking::offence::OnOffenceHandler;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
@@ -31,7 +33,7 @@ type DeferredOffenceOf<T> = (
|
||||
// at a later time.
|
||||
generate_storage_alias!(
|
||||
Offences,
|
||||
DeferredOffences<T: Config> => Value<Vec<DeferredOffenceOf<T>>>
|
||||
DeferredOffences<T: Config> => Value<Vec<DeferredOffenceOf<T>>, ValueQuery>
|
||||
);
|
||||
|
||||
pub fn remove_deferred_storage<T: Config>() -> Weight {
|
||||
|
||||
@@ -130,6 +130,18 @@ impl TypeId for PalletId {
|
||||
/// >
|
||||
/// );
|
||||
///
|
||||
/// // optionally specify the query type
|
||||
/// use frame_support::pallet_prelude::{ValueQuery, OptionQuery};
|
||||
/// generate_storage_alias!(Prefix, ValueName => Value<u32, OptionQuery>);
|
||||
/// generate_storage_alias!(
|
||||
/// Prefix, SomeStorageName => DoubleMap<
|
||||
/// (u32, Twox64Concat),
|
||||
/// (u32, Twox64Concat),
|
||||
/// Vec<u8>,
|
||||
/// ValueQuery
|
||||
/// >
|
||||
/// );
|
||||
///
|
||||
/// // generate a map from `Config::AccountId` (with hasher `Twox64Concat`) to `Vec<u8>`
|
||||
/// trait Config { type AccountId: codec::FullCodec; }
|
||||
/// generate_storage_alias!(
|
||||
@@ -140,7 +152,7 @@ impl TypeId for PalletId {
|
||||
#[macro_export]
|
||||
macro_rules! generate_storage_alias {
|
||||
// without generic for $name.
|
||||
($pallet:ident, $name:ident => Map<($key:ty, $hasher:ty), $value:ty>) => {
|
||||
($pallet:ident, $name:ident => Map<($key:ty, $hasher:ty), $value:ty $(, $querytype:ty)?>) => {
|
||||
$crate::paste::paste! {
|
||||
$crate::generate_storage_alias!(@GENERATE_INSTANCE_STRUCT $pallet, $name);
|
||||
type $name = $crate::storage::types::StorageMap<
|
||||
@@ -148,10 +160,15 @@ macro_rules! generate_storage_alias {
|
||||
$hasher,
|
||||
$key,
|
||||
$value,
|
||||
$( $querytype )?
|
||||
>;
|
||||
}
|
||||
};
|
||||
($pallet:ident, $name:ident => DoubleMap<($key1:ty, $hasher1:ty), ($key2:ty, $hasher2:ty), $value:ty>) => {
|
||||
(
|
||||
$pallet:ident,
|
||||
$name:ident
|
||||
=> DoubleMap<($key1:ty, $hasher1:ty), ($key2:ty, $hasher2:ty), $value:ty $(, $querytype:ty)?>
|
||||
) => {
|
||||
$crate::paste::paste! {
|
||||
$crate::generate_storage_alias!(@GENERATE_INSTANCE_STRUCT $pallet, $name);
|
||||
type $name = $crate::storage::types::StorageDoubleMap<
|
||||
@@ -161,10 +178,15 @@ macro_rules! generate_storage_alias {
|
||||
$hasher2,
|
||||
$key2,
|
||||
$value,
|
||||
$( $querytype )?
|
||||
>;
|
||||
}
|
||||
};
|
||||
($pallet:ident, $name:ident => NMap<Key<$(($key:ty, $hasher:ty)),+>, $value:ty>) => {
|
||||
(
|
||||
$pallet:ident,
|
||||
$name:ident
|
||||
=> NMap<Key<$(($key:ty, $hasher:ty)),+>, $value:ty $(, $querytype:ty)?>
|
||||
) => {
|
||||
$crate::paste::paste! {
|
||||
$crate::generate_storage_alias!(@GENERATE_INSTANCE_STRUCT $pallet, $name);
|
||||
type $name = $crate::storage::types::StorageNMap<
|
||||
@@ -173,20 +195,26 @@ macro_rules! generate_storage_alias {
|
||||
$( $crate::storage::types::Key<$hasher, $key>, )+
|
||||
),
|
||||
$value,
|
||||
$( $querytype )?
|
||||
>;
|
||||
}
|
||||
};
|
||||
($pallet:ident, $name:ident => Value<$value:ty>) => {
|
||||
($pallet:ident, $name:ident => Value<$value:ty $(, $querytype:ty)?>) => {
|
||||
$crate::paste::paste! {
|
||||
$crate::generate_storage_alias!(@GENERATE_INSTANCE_STRUCT $pallet, $name);
|
||||
type $name = $crate::storage::types::StorageValue<
|
||||
[<$name Instance>],
|
||||
$value,
|
||||
$( $querytype )?
|
||||
>;
|
||||
}
|
||||
};
|
||||
// with generic for $name.
|
||||
($pallet:ident, $name:ident<$t:ident : $bounds:tt> => Map<($key:ty, $hasher:ty), $value:ty>) => {
|
||||
(
|
||||
$pallet:ident,
|
||||
$name:ident<$t:ident : $bounds:tt>
|
||||
=> Map<($key:ty, $hasher:ty), $value:ty $(, $querytype:ty)?>
|
||||
) => {
|
||||
$crate::paste::paste! {
|
||||
$crate::generate_storage_alias!(@GENERATE_INSTANCE_STRUCT $pallet, $name);
|
||||
#[allow(type_alias_bounds)]
|
||||
@@ -195,13 +223,15 @@ macro_rules! generate_storage_alias {
|
||||
$key,
|
||||
$hasher,
|
||||
$value,
|
||||
$( $querytype )?
|
||||
>;
|
||||
}
|
||||
};
|
||||
(
|
||||
$pallet:ident,
|
||||
$name:ident<$t:ident : $bounds:tt>
|
||||
=> DoubleMap<($key1:ty, $hasher1:ty), ($key2:ty, $hasher2:ty), $value:ty>) => {
|
||||
=> DoubleMap<($key1:ty, $hasher1:ty), ($key2:ty, $hasher2:ty), $value:ty $(, $querytype:ty)?>
|
||||
) => {
|
||||
$crate::paste::paste! {
|
||||
$crate::generate_storage_alias!(@GENERATE_INSTANCE_STRUCT $pallet, $name);
|
||||
#[allow(type_alias_bounds)]
|
||||
@@ -212,12 +242,14 @@ macro_rules! generate_storage_alias {
|
||||
$key2,
|
||||
$hasher2,
|
||||
$value,
|
||||
$( $querytype )?
|
||||
>;
|
||||
}
|
||||
};
|
||||
(
|
||||
$pallet:ident,
|
||||
$name:ident<$t:ident : $bounds:tt> => NMap<$(($key:ty, $hasher:ty),)+ $value:ty>
|
||||
$name:ident<$t:ident : $bounds:tt>
|
||||
=> NMap<$(($key:ty, $hasher:ty),)+ $value:ty $(, $querytype:ty)?>
|
||||
) => {
|
||||
$crate::paste::paste! {
|
||||
$crate::generate_storage_alias!(@GENERATE_INSTANCE_STRUCT $pallet, $name);
|
||||
@@ -228,17 +260,18 @@ macro_rules! generate_storage_alias {
|
||||
$( $crate::storage::types::Key<$hasher, $key>, )+
|
||||
),
|
||||
$value,
|
||||
$( $querytype )?
|
||||
>;
|
||||
}
|
||||
};
|
||||
($pallet:ident, $name:ident<$t:ident : $bounds:tt> => Value<$value:ty>) => {
|
||||
($pallet:ident, $name:ident<$t:ident : $bounds:tt> => Value<$value:ty $(, $querytype:ty)?>) => {
|
||||
$crate::paste::paste! {
|
||||
$crate::generate_storage_alias!(@GENERATE_INSTANCE_STRUCT $pallet, $name);
|
||||
#[allow(type_alias_bounds)]
|
||||
type $name<$t : $bounds> = $crate::storage::types::StorageValue<
|
||||
[<$name Instance>],
|
||||
$value,
|
||||
$crate::storage::types::ValueQuery,
|
||||
$( $querytype )?
|
||||
>;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user