subspace_runtime_primitives/
utility.rsuse core::marker::PhantomData;
use frame_support::pallet_prelude::TypeInfo;
use frame_system::pallet_prelude::RuntimeCallFor;
use scale_info::prelude::collections::VecDeque;
use sp_runtime::traits::{BlockNumberProvider, Get};
pub trait MaybeIntoUtilityCall<Runtime>
where
Runtime: pallet_utility::Config,
{
fn maybe_into_utility_call(&self) -> Option<&pallet_utility::Call<Runtime>>;
}
pub fn nested_utility_call_iter<Runtime>(
call: &RuntimeCallFor<Runtime>,
) -> impl Iterator<Item = &RuntimeCallFor<Runtime>>
where
Runtime: frame_system::Config + pallet_utility::Config,
RuntimeCallFor<Runtime>: MaybeIntoUtilityCall<Runtime>,
for<'block> &'block RuntimeCallFor<Runtime>:
From<&'block <Runtime as pallet_utility::Config>::RuntimeCall>,
{
let mut new_calls = VecDeque::from([call]);
core::iter::from_fn(move || {
let call = new_calls.pop_front()?;
if let Some(call) = call.maybe_into_utility_call() {
match call {
pallet_utility::Call::batch { calls }
| pallet_utility::Call::batch_all { calls }
| pallet_utility::Call::force_batch { calls } => calls.iter().for_each(|call| {
new_calls.push_front(call.into());
}),
pallet_utility::Call::as_derivative { call, .. }
| pallet_utility::Call::dispatch_as { call, .. }
| pallet_utility::Call::with_weight { call, .. } => {
new_calls.push_front(call.as_ref().into())
}
pallet_utility::Call::__Ignore(..) => {}
}
}
Some(call)
})
}
#[derive(Debug, TypeInfo)]
pub struct DefaultNonceProvider<T, N>(PhantomData<(T, N)>);
impl<N, T: BlockNumberProvider<BlockNumber = N>> Get<N> for DefaultNonceProvider<T, N> {
fn get() -> N {
T::current_block_number()
}
}