Skip to content

Commit 9900790

Browse files
committed
Upgrade jsonrpc versions to v14.0.0
1 parent f71f740 commit 9900790

File tree

12 files changed

+336
-297
lines changed

12 files changed

+336
-297
lines changed

codechain/rpc.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use std::net::SocketAddr;
1919

2020
use crate::rpc_apis;
2121
use crpc::{
22-
jsonrpc_core, start_http, start_ipc, start_ws, HttpServer, IpcServer, MetaIoHandler, Middleware, WsError,
23-
WsErrorKind, WsServer,
22+
jsonrpc_core, start_http, start_ipc, start_ws, HttpServer, IpcServer, MetaIoHandler, Middleware, WsError, WsServer,
2423
};
24+
use futures::future::Either;
2525
use serde_json;
2626

2727
#[derive(Debug, PartialEq)]
@@ -109,7 +109,7 @@ pub fn rpc_ws_start(
109109
let addr = url.parse().map_err(|_| format!("Invalid WebSockets listen host/port given: {}", url))?;
110110
let start_result = start_ws(&addr, server, cfg.max_connections);
111111
match start_result {
112-
Err(WsError(WsErrorKind::Io(ref err), _)) if err.kind() == io::ErrorKind::AddrInUse => {
112+
Err(WsError::Io(ref err)) if err.kind() == io::ErrorKind::AddrInUse => {
113113
Err(format!("WebSockets address {} is already in use, make sure that another instance of a Codechain node is not running or change the address using the --ws-port options.", addr))
114114
},
115115
Err(e) => Err(format!("WebSockets error: {:?}", e)),
@@ -133,8 +133,9 @@ struct LogMiddleware {}
133133

134134
impl<M: jsonrpc_core::Metadata> jsonrpc_core::Middleware<M> for LogMiddleware {
135135
type Future = jsonrpc_core::FutureResponse;
136+
type CallFuture = jsonrpc_core::FutureOutput;
136137

137-
fn on_request<F, X>(&self, request: jsonrpc_core::Request, meta: M, next: F) -> Self::Future
138+
fn on_request<F, X>(&self, request: jsonrpc_core::Request, meta: M, next: F) -> Either<Self::Future, X>
138139
where
139140
F: FnOnce(jsonrpc_core::Request, M) -> X + Send,
140141
X: futures::Future<Item = Option<jsonrpc_core::Response>, Error = ()> + Send + 'static, {
@@ -146,7 +147,15 @@ impl<M: jsonrpc_core::Metadata> jsonrpc_core::Middleware<M> for LogMiddleware {
146147
}
147148
}
148149
}
149-
Box::new(next(request, meta))
150+
Either::B(next(request, meta))
151+
}
152+
153+
fn on_call<F, X>(&self, call: jsonrpc_core::Call, meta: M, next: F) -> Either<Self::CallFuture, X>
154+
where
155+
F: FnOnce(jsonrpc_core::Call, M) -> X + Send,
156+
X: futures::Future<Item = Option<jsonrpc_core::Output>, Error = ()> + Send + 'static, {
157+
Self::print_call(&call);
158+
Either::B(next(call, meta))
150159
}
151160
}
152161

@@ -166,7 +175,9 @@ impl LogMiddleware {
166175
);
167176
}
168177
jsonrpc_core::Call::Notification(_) => {}
169-
jsonrpc_core::Call::Invalid(_) => {}
178+
jsonrpc_core::Call::Invalid {
179+
..
180+
} => {}
170181
}
171182
}
172183
}

rpc/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ rustc-hex = "1.0"
3333
rustc-serialize = "0.3"
3434
time = "0.1"
3535
tokio-core = "0.1.17"
36-
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
37-
jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
38-
jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
39-
jsonrpc-ipc-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
40-
jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
36+
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.0" }
37+
jsonrpc-derive = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.0" }
38+
jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.0" }
39+
jsonrpc-ipc-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.0" }
40+
jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", tag = "v14.0.0" }

rpc/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,20 @@ extern crate time;
5151
extern crate tokio_core;
5252

5353
#[macro_use]
54-
extern crate jsonrpc_macros;
54+
extern crate jsonrpc_derive;
5555

5656
pub mod rpc_server;
5757
pub mod v1;
5858

5959
pub use rustc_serialize::hex;
6060

6161
pub use jsonrpc_core::{Compatibility, Error, MetaIoHandler, Middleware, Params, Value};
62-
pub use jsonrpc_http_server::tokio_core::reactor::Remote;
6362

6463
pub use jsonrpc_http_server::Server as HttpServer;
6564
pub use rpc_server::start_http;
6665

6766
pub use jsonrpc_ipc_server::Server as IpcServer;
6867
pub use rpc_server::start_ipc;
6968

70-
pub use jsonrpc_ws_server::{Error as WsError, ErrorKind as WsErrorKind, Server as WsServer};
69+
pub use jsonrpc_ws_server::{Error as WsError, Server as WsServer};
7170
pub use rpc_server::start_ws;

rpc/src/v1/traits/account.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,38 @@ use primitives::H256;
2020

2121
use super::super::types::{SendTransactionResult, UnsignedTransaction};
2222

23-
build_rpc_trait! {
24-
pub trait Account {
25-
/// Gets a list of accounts
26-
# [rpc(name = "account_getList")]
27-
fn get_account_list(&self) -> Result<Vec<PlatformAddress>>;
28-
29-
/// Creates a new account
30-
# [rpc(name = "account_create")]
31-
fn create_account(&self, Option<Password>) -> Result<PlatformAddress>;
32-
33-
/// Imports a private key
34-
# [rpc(name = "account_importRaw")]
35-
fn create_account_from_secret(&self, H256, Option<Password>) -> Result<PlatformAddress>;
36-
37-
/// Unlocks the specified account for use.
38-
# [rpc(name = "account_unlock")]
39-
fn unlock(&self, PlatformAddress, Password, Option<u64>) -> Result<()>;
40-
41-
/// Calculates the account's signature for a given message
42-
# [rpc(name = "account_sign")]
43-
fn sign(&self, H256, PlatformAddress, Option<Password>) -> Result<Signature>;
44-
45-
/// Sends a transaction with a signature of the account
46-
# [rpc(name = "account_sendTransaction")]
47-
fn send_transaction(&self, UnsignedTransaction, PlatformAddress, Option<Password>) -> Result<SendTransactionResult>;
48-
49-
/// Changes the account's password
50-
# [rpc(name = "account_changePassword")]
51-
fn change_password(&self, PlatformAddress, Password, Password) -> Result<()>;
52-
}
23+
#[rpc(server)]
24+
pub trait Account {
25+
/// Gets a list of accounts
26+
#[rpc(name = "account_getList")]
27+
fn get_account_list(&self) -> Result<Vec<PlatformAddress>>;
28+
29+
/// Creates a new account
30+
#[rpc(name = "account_create")]
31+
fn create_account(&self, passphrase: Option<Password>) -> Result<PlatformAddress>;
32+
33+
/// Imports a private key
34+
#[rpc(name = "account_importRaw")]
35+
fn create_account_from_secret(&self, secret: H256, passphrase: Option<Password>) -> Result<PlatformAddress>;
36+
37+
/// Unlocks the specified account for use.
38+
#[rpc(name = "account_unlock")]
39+
fn unlock(&self, address: PlatformAddress, password: Password, duration: Option<u64>) -> Result<()>;
40+
41+
/// Calculates the account's signature for a given message
42+
#[rpc(name = "account_sign")]
43+
fn sign(&self, message_digest: H256, address: PlatformAddress, passphrase: Option<Password>) -> Result<Signature>;
44+
45+
/// Sends a transaction with a signature of the account
46+
#[rpc(name = "account_sendTransaction")]
47+
fn send_transaction(
48+
&self,
49+
tx: UnsignedTransaction,
50+
platform_address: PlatformAddress,
51+
passphrase: Option<Password>,
52+
) -> Result<SendTransactionResult>;
53+
54+
/// Changes the account's password
55+
#[rpc(name = "account_changePassword")]
56+
fn change_password(&self, address: PlatformAddress, old_password: Password, new_password: Password) -> Result<()>;
5357
}

0 commit comments

Comments
 (0)