forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom RPC methods for DummyOrdered pallet (paritytech#317)
* RPC for DummyOrdered * add test for RPC * proof returned by RPC is Vec<<Vec<u8>>>.encode() * retrieval -> receiving * bp-runtime crate * bp-runtime supports no_std * cargo fmt --all * jsonrpc_core::BoxFuture * Update modules/message-lane/rpc/Cargo.toml Co-authored-by: Hernando Castano <[email protected]> * Update modules/message-lane/rpc/src/lib.rs Co-authored-by: Hernando Castano <[email protected]> * messageLane_ prefix for RPC methods * Update primitives/runtime/Cargo.toml Co-authored-by: Hernando Castano <[email protected]> * Update primitives/runtime/src/lib.rs Co-authored-by: Hernando Castano <[email protected]> * Update modules/message-lane/rpc/src/lib.rs Co-authored-by: Hernando Castano <[email protected]> * Update modules/message-lane/rpc/src/lib.rs Co-authored-by: Hernando Castano <[email protected]> * Update modules/message-lane/rpc/src/lib.rs Co-authored-by: Hernando Castano <[email protected]> Co-authored-by: Hernando Castano <[email protected]>
- Loading branch information
Showing
6 changed files
with
433 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
[package] | ||
name = "pallet-message-lane-rpc" | ||
description = "Module that provides RPC methods specific to message-lane pallet." | ||
version = "0.1.0" | ||
authors = ["Parity Technologies <[email protected]>"] | ||
edition = "2018" | ||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" | ||
|
||
[dependencies] | ||
bp-runtime = { path = "../../../primitives/runtime" } | ||
bp-message-lane = { path = "../../../primitives/message-lane" } | ||
derive_more = "0.99.2" | ||
futures = { version = "0.3.5", features = ["compat"] } | ||
jsonrpc-core = "14.2.0" | ||
jsonrpc-core-client = "14.2.0" | ||
jsonrpc-derive = "14.2.1" | ||
|
||
# Substrate Based Dependencies | ||
|
||
[dependencies.sc-client-api] | ||
version = "2.0.0-rc6" | ||
tag = 'v2.0.0-rc6' | ||
git = "https://github.com/paritytech/substrate/" | ||
|
||
[dependencies.sp-blockchain] | ||
version = "2.0.0-rc6" | ||
tag = 'v2.0.0-rc6' | ||
git = "https://github.com/paritytech/substrate/" | ||
|
||
[dependencies.sp-core] | ||
version = "2.0.0-rc6" | ||
tag = 'v2.0.0-rc6' | ||
git = "https://github.com/paritytech/substrate/" | ||
|
||
[dependencies.sp-runtime] | ||
version = "2.0.0-rc6" | ||
tag = 'v2.0.0-rc6' | ||
git = "https://github.com/paritytech/substrate/" | ||
|
||
[dependencies.sp-state-machine] | ||
version = "0.8.0-rc6" | ||
tag = 'v2.0.0-rc6' | ||
git = "https://github.com/paritytech/substrate/" | ||
|
||
[dependencies.sp-trie] | ||
version = "2.0.0-rc6" | ||
tag = 'v2.0.0-rc6' | ||
git = "https://github.com/paritytech/substrate/" | ||
|
||
[dev-dependencies] | ||
async-std = "1.6.2" | ||
|
||
[dev-dependencies.substrate-test-runtime-client] | ||
version = "2.0.0-rc6" | ||
tag = 'v2.0.0-rc6' | ||
git = "https://github.com/paritytech/substrate/" |
This file contains 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2019-2020 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity Bridges Common. | ||
|
||
// Parity Bridges Common 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. | ||
|
||
// Parity Bridges Common 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 Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Possible errors and results of message-lane RPC calls. | ||
|
||
/// Future Result type. | ||
pub type FutureResult<T> = jsonrpc_core::BoxFuture<T>; | ||
|
||
/// State RPC errors. | ||
#[derive(Debug, derive_more::Display, derive_more::From)] | ||
pub enum Error { | ||
/// When unknown instance id is passed. | ||
#[display(fmt = "Message lane instance is unknown")] | ||
UnknownInstance, | ||
/// Client error. | ||
#[display(fmt = "Client error: {}", _0)] | ||
Client(Box<dyn std::error::Error + Send>), | ||
} | ||
|
||
impl std::error::Error for Error { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
match self { | ||
Error::UnknownInstance => None, | ||
Error::Client(ref err) => Some(&**err), | ||
} | ||
} | ||
} | ||
|
||
impl From<Error> for jsonrpc_core::Error { | ||
fn from(e: Error) -> Self { | ||
const UNKNOW_INSTANCE_CODE: i64 = 1; | ||
|
||
match e { | ||
Error::UnknownInstance => jsonrpc_core::Error { | ||
code: jsonrpc_core::ErrorCode::ServerError(UNKNOW_INSTANCE_CODE), | ||
message: "Unknown instance passed".into(), | ||
data: None, | ||
}, | ||
Error::Client(e) => jsonrpc_core::Error { | ||
code: jsonrpc_core::ErrorCode::InternalError, | ||
message: format!("Unknown error occured: {}", e), | ||
data: Some(format!("{:?}", e).into()), | ||
}, | ||
} | ||
} | ||
} |
Oops, something went wrong.