mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 14:41:11 +00:00
ed421c56ee
* Rewrites `impl_runtime_apis!` macro as `proc-macro` * Adds some documentation * Require the `impl_runtime_apis` to use a path for accessing the trait * Make the runtime implement `GetNodeBlockType` * Moves first chunk of runtime api code into the `impl_runtime_apis` macro This also renames `ClientWithApi` into `RuntimeApi`. * Make `impl_runtime_apis` use `runtime` api version automatically * `decl_runtime_apis` automatically adds `Block: BlockT` as generic parameter * Remove function generic arguments in block builder api * Remove some unnused stuff from the `decl_runtime_apis` macro * Make `InherentData` working again * Make `impl_runtime_apis!` implement the `RuntimeApi` side as well * Make it compile again after rebasing with master * Split `sr-api-macros` into multiple files * Reimplement `decl_runtime_apis!` as proc_macro * Use `decl_runtime_apis!` for `Core` as well and improve error reporting * Adds documentation for `decl_runtime_apis!` and `impl_runtime_apis!` * Move some code * Adds compile fail tests * Adds a test and fixes some bugs * Make `impl_runtime_apis!` support `_` as parameter name * Fixes build errors with wasm * Wasm rebuild after master rebase * Apply suggestions from code review Co-Authored-By: bkchr <bkchr@users.noreply.github.com> * Addresses some grumbles * Adds test to ensure that method signatures need to match * New wasm files
105 lines
2.8 KiB
Rust
105 lines
2.8 KiB
Rust
// Copyright 2018 Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#[doc(hidden)]
|
|
pub use rstd::{result::Result, vec::Vec};
|
|
#[doc(hidden)]
|
|
pub use runtime_primitives::{
|
|
traits::{ProvideInherent, Block as BlockT}, CheckInherentError, InherentData
|
|
};
|
|
|
|
|
|
/// Implement the outer inherent.
|
|
/// All given modules need to implement `ProvideInherent`.
|
|
///
|
|
/// # Example
|
|
///
|
|
/// ```nocompile
|
|
/// impl_outer_inherent! {
|
|
/// pub struct InherentData where Block = Block, UncheckedExtrinsic = UncheckedExtrinsic {
|
|
/// timestamp: Timestamp export Error as TimestampInherentError,
|
|
/// consensus: Consensus,
|
|
/// }
|
|
/// }
|
|
/// ```
|
|
///
|
|
/// Additional parameters after `UncheckedExtrinsic` are `Error` and `Call`.
|
|
#[macro_export]
|
|
macro_rules! impl_outer_inherent {
|
|
(
|
|
$(#[$attr:meta])*
|
|
pub struct $name:ident where Block = $block:ident {
|
|
$( $module:ident: $module_ty:ident, )*
|
|
}
|
|
) => {
|
|
impl_outer_inherent!(
|
|
$( #[$attr] )*
|
|
pub struct $name where Block = $block, Call = Call {
|
|
$( $module: $module_ty, )*
|
|
}
|
|
);
|
|
};
|
|
(
|
|
$(#[$attr:meta])*
|
|
pub struct $name:ident where Block = $block:ident {
|
|
$( $module:ident: $module_ty:ident, )*
|
|
}
|
|
) => {
|
|
impl_outer_inherent!(
|
|
$( #[$attr] )*
|
|
pub struct $name where Block = $block, Call = Call {
|
|
$( $module: $module_ty, )*
|
|
}
|
|
);
|
|
};
|
|
(
|
|
$(#[$attr:meta])*
|
|
pub struct $name:ident where Block = $block:ident, Call = $call:ident {
|
|
$( $module:ident: $module_ty:ident, )*
|
|
}
|
|
) => {
|
|
$( #[$attr] )*
|
|
#[derive(Encode, Decode)]
|
|
/// Inherent data to include in a block.
|
|
pub struct $name {
|
|
$( $module: <$module_ty as $crate::inherent::ProvideInherent>::Inherent, )*
|
|
}
|
|
|
|
impl $name {
|
|
/// Create a new instance.
|
|
pub fn new( $( $module: <$module_ty as $crate::inherent::ProvideInherent>::Inherent ),* ) -> Self {
|
|
Self {
|
|
$( $module, )*
|
|
}
|
|
}
|
|
|
|
fn check_inherents(
|
|
data: $crate::inherent::InherentData,
|
|
block: $block
|
|
) -> $crate::inherent::Result<(), $crate::inherent::CheckInherentError> {
|
|
$(
|
|
<$module_ty as $crate::inherent::ProvideInherent>::check_inherent(
|
|
&block, data.$module, &|xt| match xt.function {
|
|
Call::$module_ty(ref data) => Some(data),
|
|
_ => None,
|
|
})?;
|
|
)*
|
|
Ok(())
|
|
}
|
|
}
|
|
};
|
|
}
|