-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Implement runtime api client side directly in the runtime #1094
Conversation
core/client/src/block_builder/mod.rs
Outdated
| //! Utility struct to build a block. | ||
| #[cfg(feature = "std")] | ||
| mod block_builder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errant space
| pub use rstd::slice; | ||
| #[doc(hidden)] | ||
| pub use codec::{Encode, Decode}; | ||
| //! Macros for declaring and implementing the runtime API's. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grocer's apostrophe
|
good to hear the |
|
would be nice to have an example of a new API being added and used from within |
5186859 to
4c02cf0
Compare
|
Fixed the grumbles and the merge conflict. :) |
core/client/src/runtime_api/core.rs
Outdated
| pub mod runtime { | ||
| use super::*; | ||
|
|
||
| /// The `Core` api trait that is mandantory for each runtime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces!
|
|
||
| #[cfg(feature = "std")] | ||
| impl client::runtime_api::Core<GBlock> for ClientWithApi { | ||
| fn version(&self, at: &GBlockId) -> Result<RuntimeVersion, client::error::Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this code due to be auto-generated?
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| impl client::runtime_api::Core<Block> for ClientWithApi { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code is very boilerplatey - is it due to be autogenerated?
| #[cfg(feature = "std")] | ||
| pub trait Core<Block: BlockT>: 'static + Send + Sync + ConstructRuntimeApi<Block> + ApiExt { | ||
| /// Returns the version of the runtime. | ||
| fn version(&self, at: &BlockId<Block>) -> Result<RuntimeVersion>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file looks very boilerplatey given there are two instances of the same API with minor differences...
|
some questions. other than those concerns it looks good. |
|
Everything where |
43d5781 to
696e416
Compare
|
@gavofyork resolved the merge conflict. |
:100644 100644 898aadc 49217199 M Cargo.lock :100644 100644 6157043 465ed664 M core/client/src/backend.rs :100644 100644 5d0c886 64d710fd M core/client/src/block_builder.rs :100644 100644 c447855e 5ecbe474 M core/client/src/client.rs :100644 100644 139cef1 f90dbf3d M core/client/src/error.rs :100644 100644 2800c50 3298e66 M core/client/src/runtime_api.rs :100644 100644 affa1c5 809b08b M core/primitives/src/lib.rs :100644 100644 2877dfa d554741 M core/sr-api/Cargo.toml :100644 100644 9a49784 6a625a0 M core/sr-api/src/lib.rs :100644 100644 7c28e1c a1a444a9 M core/sr-primitives/src/traits.rs :100644 100644 2e113ab dcc01a6 M srml/metadata/Cargo.toml :100644 100644 ea722a7 0809531 M srml/metadata/src/lib.rs
On `wasm` it basically just exports the runtime api stuff.
696e416 to
f3cca84
Compare
This pull requests moves the implementation of the runtime api client side into the runtime as well. This makes the api safer, as the compiler now enforces the user to implement a certain api when he wants to use it. The compile time checks obviously only work for the native runtime interface.
The
Coreapi is now also enforced by the compiler by making each other api derive from it.This pull requests also moves the
sr-apicrate intosubstrate-clientand thus, the client is required to compile onwasmas well. Onwasmthe client only exposes the api stuff, the rest is disabled. I made this design decision to minimize the size of a where clause when using a runtime api to made the api more ergonomic. Otherwise, the user would needed to specify the error each time and that blowed up easily. I'm still not quite happy with this solution, maybe while reviewing this pull request, we can come to a better solution.In a follow up pull request, I will provide some sort of macro to auto implement much of the stuff that is now hand written code in the
test-runtimeandnode/runtime. So, all theClientWithApistuff should be gone with this follow up pr.Progress on: #1031