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
+3 -4
View File
@@ -44,7 +44,7 @@ use runtime_support::{storage, Parameter};
use runtime_support::dispatch::Result;
use runtime_support::storage::StorageValue;
use runtime_support::storage::unhashed::StorageVec;
use primitives::RuntimeString;
use primitives::CheckInherentError;
use primitives::traits::{
MaybeSerializeDebug, Member, ProvideInherent, Block as BlockT
};
@@ -249,7 +249,6 @@ impl<T: Trait> Module<T> {
impl<T: Trait> ProvideInherent for Module<T> {
type Inherent = Vec<u32>;
type Call = Call<T>;
type Error = RuntimeString;
fn create_inherent_extrinsics(data: Self::Inherent) -> Vec<(u32, Self::Call)> {
vec![(T::NOTE_OFFLINE_POSITION, Call::note_offline(data))]
@@ -257,7 +256,7 @@ impl<T: Trait> ProvideInherent for Module<T> {
fn check_inherent<Block: BlockT, F: Fn(&Block::Extrinsic) -> Option<&Self::Call>>(
block: &Block, data: Self::Inherent, extract_function: &F
) -> result::Result<(), Self::Error> {
) -> result::Result<(), CheckInherentError> {
let noted_offline = block
.extrinsics().get(T::NOTE_OFFLINE_POSITION as usize)
.and_then(|xt| match extract_function(&xt) {
@@ -267,7 +266,7 @@ impl<T: Trait> ProvideInherent for Module<T> {
noted_offline.iter().try_for_each(|n|
if !data.contains(n) {
Err("Online node marked offline".into())
Err(CheckInherentError::Other("Online node marked offline".into()))
} else {
Ok(())
}