Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Start
  • Loading branch information
bkchr committed May 11, 2020
commit 1cd30443be57cd4219d20dedff7e4c38c01e7e9f
2 changes: 1 addition & 1 deletion frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ pub trait Trait: frame_system::Trait + pallet_transaction_payment::Trait {
type Call:
Parameter +
Dispatchable<PostInfo=PostDispatchInfo, Origin=<Self as frame_system::Trait>::Origin> +
IsSubType<Module<Self>, Self> + GetDispatchInfo;
IsSubType<Call<Self>> + GetDispatchInfo;

/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
Expand Down
2 changes: 1 addition & 1 deletion frame/grandpa/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl From<ReportEquivocationValidityError> for TransactionValidityError {

impl<T: super::Trait + Send + Sync> SignedExtension for ValidateEquivocationReport<T>
where
<T as frame_system::Trait>::Call: IsSubType<super::Module<T>, T>,
<T as frame_system::Trait>::Call: IsSubType<super::Call<T>>,
{
const IDENTIFIER: &'static str = "ValidateEquivocationReport";
type AccountId = T::AccountId;
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ pub trait Trait: frame_system::Trait + SendTransactionTypes<Call<Self>> {
type ElectionLookahead: Get<Self::BlockNumber>;

/// The overarching call type.
type Call: Dispatchable + From<Call<Self>> + IsSubType<Module<Self>, Self> + Clone;
type Call: Dispatchable + From<Call<Self>> + IsSubType<Call<Self>> + Clone;

/// Maximum number of equalise iterations to run in the offchain submission. If set to 0,
/// equalize will not be executed at all.
Expand Down
14 changes: 12 additions & 2 deletions frame/support/procedural/src/construct_runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ fn construct_runtime_parsed(definition: RuntimeDefinition) -> Result<TokenStream
let dispatch = decl_outer_dispatch(&name, modules.iter(), &scrate);
let metadata = decl_runtime_metadata(&name, modules.iter(), &scrate, &unchecked_extrinsic);
let outer_config = decl_outer_config(&name, modules.iter(), &scrate);
let inherent = decl_outer_inherent(&block, &unchecked_extrinsic, modules.iter(), &scrate);
let inherent = decl_outer_inherent(
&name,
&block,
&unchecked_extrinsic,
modules.iter(),
&scrate,
);
let validate_unsigned = decl_validate_unsigned(&name, modules.iter(), &scrate);

let res = quote!(
Expand Down Expand Up @@ -142,6 +148,7 @@ fn decl_validate_unsigned<'a>(
}

fn decl_outer_inherent<'a>(
runtime: &'a Ident,
block: &'a syn::TypePath,
unchecked_extrinsic: &'a syn::TypePath,
module_declarations: impl Iterator<Item = &'a ModuleDeclaration>,
Expand All @@ -161,7 +168,10 @@ fn decl_outer_inherent<'a>(
});
quote!(
#scrate::impl_outer_inherent!(
impl Inherents where Block = #block, UncheckedExtrinsic = #unchecked_extrinsic {
impl Inherents for #runtime where
Block = #block,
UncheckedExtrinsic = #unchecked_extrinsic
{
#(#modules_tokens)*
}
);
Expand Down
10 changes: 5 additions & 5 deletions frame/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ pub type DispatchErrorWithPostInfo =

/// Serializable version of Dispatchable.
/// This value can be used as a "function" in an extrinsic.
pub trait Callable<T> {
pub trait Callable<R> {
type Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo> + Codec + Clone + PartialEq + Eq;
}

// dirty hack to work around serde_derive issue
// https://github.com/rust-lang/rust/issues/51331
pub type CallableCallFor<A, T> = <A as Callable<T>>::Call;
pub type CallableCallFor<A, R> = <A as Callable<R>>::Call;

/// A type that can be used as a parameter in a dispatchable function.
///
Expand Down Expand Up @@ -1611,8 +1611,8 @@ macro_rules! decl_module {
}
}

pub trait IsSubType<T: Callable<R>, R> {
fn is_sub_type(&self) -> Option<&CallableCallFor<T, R>>;
pub trait IsSubType<T> {
fn is_sub_type(&self) -> Option<&T>;
}

/// Implement a meta-dispatch module to dispatch to other dispatchers.
Expand Down Expand Up @@ -1696,7 +1696,7 @@ macro_rules! impl_outer_dispatch {
}
}
$(
impl $crate::dispatch::IsSubType<$camelcase, $runtime> for $call_type {
impl $crate::dispatch::IsSubType<$crate::dispatch::CallableCallFor<$camelcase, $runtime>> for $call_type {
#[allow(unreachable_patterns)]
fn is_sub_type(&self) -> Option<&$crate::dispatch::CallableCallFor<$camelcase, $runtime>> {
match *self {
Expand Down
39 changes: 19 additions & 20 deletions frame/support/src/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ pub use sp_inherents::{InherentData, ProvideInherent, CheckInherentsResult, IsFa
#[macro_export]
macro_rules! impl_outer_inherent {
(
impl Inherents where Block = $block:ident, UncheckedExtrinsic = $uncheckedextrinsic:ident
impl Inherents for $runtime:ident where
Block = $block:ident,
UncheckedExtrinsic = $uncheckedextrinsic:ident
{
$( $module:ident: $call:ident, )*
}
Expand All @@ -54,15 +56,14 @@ macro_rules! impl_outer_inherent {
impl InherentDataExt for $crate::inherent::InherentData {
fn create_extrinsics(&self) ->
$crate::inherent::Vec<<$block as $crate::inherent::BlockT>::Extrinsic> {
use $crate::inherent::ProvideInherent;
use $crate::inherent::Extrinsic;
use $crate::inherent::{ProvideInherent, Extrinsic};

let mut inherents = Vec::new();

$(
if let Some(inherent) = $module::create_inherent(self) {
inherents.push($uncheckedextrinsic::new(
Call::$call(inherent),
inherent.into(),
None,
).expect("Runtime UncheckedExtrinsic is not Opaque, so it has to return `Some`; qed"));
}
Expand All @@ -73,28 +74,26 @@ macro_rules! impl_outer_inherent {

fn check_extrinsics(&self, block: &$block) -> $crate::inherent::CheckInherentsResult {
use $crate::inherent::{ProvideInherent, IsFatalError};
use $crate::dispatch::IsSubType;

let mut result = $crate::inherent::CheckInherentsResult::new();
for xt in block.extrinsics() {
if $crate::inherent::Extrinsic::is_signed(xt).unwrap_or(false) {
break
}

$(
match xt.function {
Call::$call(ref call) => {
if let Err(e) = $module::check_inherent(call, self) {
result.put_error(
$module::INHERENT_IDENTIFIER, &e
).expect("There is only one fatal error; qed");
if e.is_fatal_error() {
return result
}
$({
if let Some(call) = IsSubType::<_>::is_sub_type(&xt.function) {
if let Err(e) = $module::check_inherent(call, self) {
result.put_error(
$module::INHERENT_IDENTIFIER, &e
).expect("There is only one fatal error; qed");
if e.is_fatal_error() {
return result
}
}
_ => {},
}
)*
})*
}

$(
Expand All @@ -105,10 +104,10 @@ macro_rules! impl_outer_inherent {
return false
}

match xt.function {
Call::$call(_) => true,
_ => false,
}
let call: Option<&<$module as ProvideInherent>::Call> =
xt.function.is_sub_type();

call.is_some()
});

if !found {
Expand Down