mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-01 12:27:23 +00:00
Ensure correct variant count in Runtime[Hold/Freeze]Reason (#1900)
closes https://github.com/paritytech/polkadot-sdk/issues/1882 ## Breaking Changes This PR introduces a new item to `pallet_balances::Config`: ```diff trait Config { ++ type RuntimeFreezeReasons; } ``` This value is only used to check it against `type MaxFreeze`. A similar check has been added for `MaxHolds` against `RuntimeHoldReasons`, which is already given to `pallet_balances`. In all contexts, you should pass the real `RuntimeFreezeReasons` generated by `construct_runtime` to `type RuntimeFreezeReasons`. Passing `()` would also work, but it would imply that the runtime uses no freezes at all. --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -46,6 +46,7 @@ pub fn expand_outer_freeze_reason(pallet_decls: &[Pallet], scrate: &TokenStream)
|
||||
));
|
||||
}
|
||||
}
|
||||
let freeze_reason_variants_count = freeze_reason_variants.len() as u32;
|
||||
|
||||
quote! {
|
||||
/// A reason for placing a freeze on funds.
|
||||
@@ -59,6 +60,10 @@ pub fn expand_outer_freeze_reason(pallet_decls: &[Pallet], scrate: &TokenStream)
|
||||
#( #freeze_reason_variants )*
|
||||
}
|
||||
|
||||
impl #scrate::traits::VariantCount for RuntimeFreezeReason {
|
||||
const VARIANT_COUNT: u32 = #freeze_reason_variants_count;
|
||||
}
|
||||
|
||||
#( #conversion_fns )*
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ pub fn expand_outer_hold_reason(pallet_decls: &[Pallet], scrate: &TokenStream) -
|
||||
));
|
||||
}
|
||||
}
|
||||
let hold_reason_variants_count = hold_reason_variants.len() as u32;
|
||||
|
||||
quote! {
|
||||
/// A reason for placing a hold on funds.
|
||||
@@ -59,6 +60,10 @@ pub fn expand_outer_hold_reason(pallet_decls: &[Pallet], scrate: &TokenStream) -
|
||||
#( #hold_reason_variants )*
|
||||
}
|
||||
|
||||
impl #scrate::traits::VariantCount for RuntimeHoldReason {
|
||||
const VARIANT_COUNT: u32 = #hold_reason_variants_count;
|
||||
}
|
||||
|
||||
#( #conversion_fns )*
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ pub use misc::{
|
||||
DefensiveTruncateFrom, EnsureInherentsAreFirst, EqualPrivilegeOnly, EstimateCallFee,
|
||||
ExecuteBlock, ExtrinsicCall, Get, GetBacking, GetDefault, HandleLifetime, IsSubType, IsType,
|
||||
Len, OffchainWorker, OnKilledAccount, OnNewAccount, PrivilegeCmp, SameOrOther, Time,
|
||||
TryCollect, TryDrop, TypedGet, UnixTime, WrapperKeepOpaque, WrapperOpaque,
|
||||
TryCollect, TryDrop, TypedGet, UnixTime, VariantCount, WrapperKeepOpaque, WrapperOpaque,
|
||||
};
|
||||
#[allow(deprecated)]
|
||||
pub use misc::{PreimageProvider, PreimageRecipient};
|
||||
|
||||
@@ -36,6 +36,18 @@ pub const DEFENSIVE_OP_PUBLIC_ERROR: &str = "a defensive failure has been trigge
|
||||
#[doc(hidden)]
|
||||
pub const DEFENSIVE_OP_INTERNAL_ERROR: &str = "Defensive failure has been triggered!";
|
||||
|
||||
/// Trait to get the number of variants in any enum.
|
||||
///
|
||||
/// NOTE: can be removed once <https://doc.rust-lang.org/std/mem/fn.variant_count.html> is stable.
|
||||
pub trait VariantCount {
|
||||
/// Get the number of variants.
|
||||
const VARIANT_COUNT: u32;
|
||||
}
|
||||
|
||||
impl VariantCount for () {
|
||||
const VARIANT_COUNT: u32 = 0;
|
||||
}
|
||||
|
||||
/// Generic function to mark an execution path as ONLY defensive.
|
||||
///
|
||||
/// Similar to mark a match arm or `if/else` branch as `unreachable!`.
|
||||
|
||||
Reference in New Issue
Block a user