Rewrite impl_runtime_apis! and decl_runtime_apis! as proc-macro (#1174)

* 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
This commit is contained in:
Bastian Köcher
2018-11-30 11:42:46 +01:00
committed by Gav Wood
parent 309f627d5c
commit ed421c56ee
40 changed files with 1863 additions and 1269 deletions
+23 -20
View File
@@ -20,7 +20,10 @@
///
/// ```nocompile
/// construct_runtime!(
/// pub enum Runtime with Log(interalIdent: DigestItem<SessionKey>) {
/// pub enum Runtime with Log(interalIdent: DigestItem<SessionKey>) where
/// Block = Block,
/// NodeBlock = runtime::Block
/// {
/// System: system,
/// Test: test::{default, Log(Test)},
/// Test2: test_with_long_module::{Module},
@@ -48,7 +51,9 @@
macro_rules! construct_runtime {
(
pub enum $runtime:ident with Log ($log_internal:ident: DigestItem<$( $log_genarg:ty ),+>)
where Block = $block:ident, UncheckedExtrinsic = $unchecked:ident
where
Block = $block:ident,
NodeBlock = $node_block:ty
{
$( $rest:tt )*
}
@@ -56,7 +61,7 @@ macro_rules! construct_runtime {
construct_runtime!(
$runtime;
$block;
$unchecked;
$node_block;
$log_internal < $( $log_genarg ),* >;
;
$( $rest )*
@@ -65,7 +70,7 @@ macro_rules! construct_runtime {
(
$runtime:ident;
$block:ident;
$unchecked:ident;
$node_block:ty;
$log_internal:ident <$( $log_genarg:ty ),+>;
$(
$expanded_name:ident: $expanded_module:ident::{
@@ -92,7 +97,7 @@ macro_rules! construct_runtime {
construct_runtime!(
$runtime;
$block;
$unchecked;
$node_block;
$log_internal < $( $log_genarg ),* >;
$(
$expanded_name: $expanded_module::{
@@ -119,7 +124,7 @@ macro_rules! construct_runtime {
(
$runtime:ident;
$block:ident;
$unchecked:ident;
$node_block:ty;
$log_internal:ident <$( $log_genarg:ty ),+>;
$(
$expanded_name:ident: $expanded_module:ident::{
@@ -153,7 +158,7 @@ macro_rules! construct_runtime {
construct_runtime!(
$runtime;
$block;
$unchecked;
$node_block;
$log_internal < $( $log_genarg ),* >;
$(
$expanded_name: $expanded_module::{
@@ -186,7 +191,7 @@ macro_rules! construct_runtime {
(
$runtime:ident;
$block:ident;
$unchecked:ident;
$node_block:ty;
$log_internal:ident <$( $log_genarg:ty ),+>;
$(
$expanded_name:ident: $expanded_module:ident::{
@@ -219,7 +224,7 @@ macro_rules! construct_runtime {
construct_runtime!(
$runtime;
$block;
$unchecked;
$node_block;
$log_internal < $( $log_genarg ),* >;
$(
$expanded_name: $expanded_module::{
@@ -251,7 +256,7 @@ macro_rules! construct_runtime {
(
$runtime:ident;
$block:ident;
$unchecked:ident;
$node_block:ty;
$log_internal:ident <$( $log_genarg:ty ),+>;
$(
$name:ident: $module:ident::{
@@ -273,6 +278,12 @@ macro_rules! construct_runtime {
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct $runtime;
impl $crate::runtime_primitives::traits::GetNodeBlockType for $runtime {
type NodeBlock = $node_block;
}
impl $crate::runtime_primitives::traits::GetRuntimeBlockType for $runtime {
type RuntimeBlock = $block;
}
__decl_outer_event!(
$runtime;
$(
@@ -326,7 +337,6 @@ macro_rules! construct_runtime {
__decl_outer_inherent!(
$runtime;
$block;
$unchecked;
;
$(
$name: $module::{ $( $modules $( <$modules_generic> )* ),* }
@@ -1052,7 +1062,6 @@ macro_rules! __decl_outer_inherent {
(
$runtime:ident;
$block:ident;
$unchecked:ident;
$( $parsed_modules:ident :: $parsed_name:ident ),*;
$name:ident: $module:ident::{
Inherent $(, $modules:ident $( <$modules_generic:ident> )* )*
@@ -1064,7 +1073,6 @@ macro_rules! __decl_outer_inherent {
__decl_outer_inherent!(
$runtime;
$block;
$unchecked;
$( $parsed_modules :: $parsed_name, )* $module::$name;
$(
$rest_name: $rest_module::{
@@ -1076,7 +1084,6 @@ macro_rules! __decl_outer_inherent {
(
$runtime:ident;
$block:ident;
$unchecked:ident;
$( $parsed_modules:ident :: $parsed_name:ident ),*;
$name:ident: $module:ident::{
$ingore:ident $( <$ignor:ident> )* $(, $modules:ident $( <$modules_generic:ident> )* )*
@@ -1088,7 +1095,6 @@ macro_rules! __decl_outer_inherent {
__decl_outer_inherent!(
$runtime;
$block;
$unchecked;
$( $parsed_modules :: $parsed_name ),*;
$name: $module::{ $( $modules $( <$modules_generic> )* ),* }
$(
@@ -1101,7 +1107,6 @@ macro_rules! __decl_outer_inherent {
(
$runtime:ident;
$block:ident;
$unchecked:ident;
$( $parsed_modules:ident :: $parsed_name:ident ),*;
$name:ident: $module:ident::{}
$(, $rest_name:ident : $rest_module:ident::{
@@ -1111,7 +1116,6 @@ macro_rules! __decl_outer_inherent {
__decl_outer_inherent!(
$runtime;
$block;
$unchecked;
$( $parsed_modules :: $parsed_name ),*;
$(
$rest_name: $rest_module::{
@@ -1123,15 +1127,14 @@ macro_rules! __decl_outer_inherent {
(
$runtime:ident;
$block:ident;
$unchecked:ident;
$( $parsed_modules:ident :: $parsed_name:ident ),*;
;
) => {
substrate_generate_ident_name! {
impl_outer_inherent!(
pub struct InherentData where Block = $block, UncheckedExtrinsic = $unchecked {
pub struct InherentData where Block = $block {
$(
$parsed_modules: $parsed_name export Error as "inherent-error-ident" $parsed_name,
$parsed_modules: $parsed_name,
)*
}
);