This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Implement runtime api client side directly in the runtime #1094
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
68a962f
Move `initialise_block` into `Core` trait as it is crucial calling th…
bkchr 297e71f
Switch to first version of new runtime API implementation
bkchr 55fefb6
Fixes bug in tests
bkchr bac3bd9
Reenable asserts
bkchr aa4428e
Directly use the `TestAPI` in the tests
bkchr 2cadafe
Start improving the api traits
bkchr 4330dbf
Refactoring
bkchr 9a586a6
Move `sr-api` into client and more refactoring
bkchr 9d5d595
Fixes tests
bkchr 7035116
Some documentation and cleanup
bkchr 56eb339
Fixes compilation after rebase
bkchr fb94bec
More refactoring and more documentation
bkchr 5b5994b
Makes `substrate-client` compilable on `wasm`
bkchr 302b8ff
Fixes grumbles
bkchr d25193d
Updates wasm files after rebasing the master
bkchr cbaf0c2
Remove TODO comment
bkchr be9c57d
Remove whitespaces
bkchr 42213c7
Fixes after rebasing master
bkchr f3cca84
Another rebase, another fix commit
bkchr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
More refactoring and more documentation
- Loading branch information
commit fb94becfcf31202ef61e05501e38f84d1c2194fc
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,38 +14,15 @@ | |
| // You should have received a copy of the GNU General Public License | ||
| // along with Substrate. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| use super::{ConstructRuntimeApi, ApiExt}; | ||
| use runtime_version::RuntimeVersion; | ||
| use runtime_primitives::{traits::{Block as BlockT, ApiRef}, generic::BlockId}; | ||
| use runtime_primitives::{traits::Block as BlockT, generic::BlockId}; | ||
| use primitives::AuthorityId; | ||
| use error::Result; | ||
| use state_machine::OverlayedChanges; | ||
| use std::result; | ||
|
|
||
| /// Something that can be constructed to a runtime api. | ||
| pub trait ConstructRuntimeApi<Block: BlockT>: Sized { | ||
| /// Construct the runtime api. | ||
| fn construct_runtime_api<'a, T: CallApiAt<Block>>(call: &'a T) -> ApiRef<'a, Self>; | ||
| } | ||
|
|
||
| pub trait ApiExt { | ||
| fn map_api_result<F: FnOnce(&Self) -> result::Result<R, E>, R, E>(&self, map_call: F) -> result::Result<R, E>; | ||
| } | ||
|
|
||
| /// Something that can call into the runtime. | ||
| pub trait CallApiAt<Block: BlockT> { | ||
| /// Call the given API function with the given arguments and returns the result at the given | ||
| /// block. | ||
| fn call_api_at( | ||
| &self, | ||
| at: &BlockId<Block>, | ||
| function: &'static str, | ||
| args: Vec<u8>, | ||
| changes: &mut OverlayedChanges, | ||
| initialised_block: &mut Option<BlockId<Block>>, | ||
| ) -> Result<Vec<u8>>; | ||
| } | ||
|
|
||
| /// The `Core` api trait that is mandantory for each runtime. | ||
| /// This is the side that should be implemented for the `RuntimeApi` that is used by the `Client`. | ||
| /// Any modifications at one of these two traits, needs to be done on the other one as well. | ||
| 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>; | ||
|
|
@@ -65,6 +42,7 @@ pub mod runtime { | |
| use super::*; | ||
|
|
||
| /// The `Core` api trait that is mandantory for each runtime. | ||
|
||
| /// This is the side that should be implemented for the `Runtime`. | ||
| pub trait Core<Block: BlockT> { | ||
| /// Returns the version of the runtime. | ||
| fn version() -> RuntimeVersion; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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...