This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
- Loading branch information
Showing
27 changed files
with
1,522 additions
and
951 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
coverage: | ||
status: | ||
patch: off | ||
project: off |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
/target | ||
target | ||
Cargo.lock | ||
/.idea | ||
.idea |
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 |
---|---|---|
@@ -1,55 +1,74 @@ | ||
[package] | ||
name = "async-jsonrpc-client" | ||
version = "0.1.3" | ||
version = "0.2.0-dev" | ||
authors = ["koushiro <koushiro.cqx@gmail.com>"] | ||
edition = "2018" | ||
description = "An asynchronous JSON-RPC client library, which supports HTTP and WebSocket" | ||
readme = "README.md" | ||
license = "MIT OR Apache-2.0" | ||
license = "MIT/Apache-2.0" | ||
documentation = "https://docs.rs/async-jsonrpc-client" | ||
repository = "https://github.com/koushiro/async-jsonrpc-client-rs" | ||
description = "An asynchronous JSON-RPC client library, which supports HTTP and WebSocket" | ||
keywords = ["async", "jsonrpc", "client"] | ||
|
||
[features] | ||
default = ["http-reqwest", "ws"] | ||
http-reqwest = ["reqwest"] | ||
http-surf = ["surf", "anyhow"] | ||
ws = ["async-tungstenite", "parking_lot", "tokio"] | ||
default = ["http-tokio", "ws-tokio"] | ||
# HTTP | ||
http-tokio = ["tokio", "reqwest"] | ||
http-async-std = ["async-std", "anyhow", "surf"] | ||
# WebSocket | ||
ws-tokio = ["tokio", "async-tungstenite/tokio-runtime", "async-tungstenite/tokio-native-tls"] | ||
ws-async-std = ["async-std", "async-tungstenite/async-std-runtime", "async-tungstenite/async-native-tls"] | ||
|
||
[dependencies] | ||
async-trait = "0.1" | ||
base64 = "0.13" | ||
futures = "0.3" | ||
log = "0.4" | ||
jsonrpc-types = "0.3" | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
thiserror = "1.0" | ||
|
||
# HTTP (reqwest) | ||
reqwest = { version = "0.10", features = ["json"], optional = true } | ||
|
||
# HTTP (async-std) | ||
surf = { version = "2.1", optional = true, default-features = false, features = ["h1-client"] } | ||
# HTTP | ||
reqwest = { version = "0.11", features = ["json"], optional = true } | ||
anyhow = { version = "1.0", optional = true } | ||
surf = { version = "2.1", default-features = false, features = ["h1-client"], optional = true } | ||
|
||
# WebSocket | ||
async-tungstenite = { version = "0.8", features = ["tokio-runtime"], optional = true } | ||
parking_lot = { version = "0.11.1", optional = true } | ||
tokio = { version = "0.2.0", features = ["macros"], optional = true } | ||
async-tungstenite = { version = "0.12", optional = true } | ||
parking_lot = { version = "0.11", optional = true } | ||
|
||
# Runtime | ||
async-std = { version = "1.9", optional = true } | ||
tokio = { version = "1.1", optional = true } | ||
|
||
[dev-dependencies] | ||
env_logger = "0.8.2" | ||
async-std = { version = "1.8.0", features = ["attributes"] } | ||
env_logger = "0.8" | ||
async-std = { version = "1.9", features = ["attributes"] } | ||
hyper = { version = "0.14", features = ["server"] } | ||
tokio = { version = "1.0", features = ["macros"] } | ||
|
||
[[example]] | ||
name = "http-tokio" | ||
path = "examples/http_tokio.rs" | ||
required-features = ["http-tokio"] | ||
|
||
[[example]] | ||
name = "http-tokio-v1" | ||
path = "examples/http_tokio_v1.rs" | ||
required-features = ["http-tokio"] | ||
|
||
[[example]] | ||
name = "http_reqwest" | ||
path = "examples/http_reqwest.rs" | ||
required-features = ["http-reqwest"] | ||
name = "http-async-std" | ||
path = "examples/http_async_std.rs" | ||
required-features = ["http-async-std"] | ||
|
||
[[example]] | ||
name = "http_surf" | ||
path = "examples/http_surf.rs" | ||
required-features = ["http-surf"] | ||
name = "ws-tokio" | ||
path = "examples/ws_tokio.rs" | ||
required-features = ["ws-tokio"] | ||
|
||
[[example]] | ||
name = "ws" | ||
path = "examples/ws.rs" | ||
required-features = ["ws"] | ||
name = "ws-async-std" | ||
path = "examples/ws_async_std.rs" | ||
required-features = ["ws-async-std"] |
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
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,28 @@ | ||
/* | ||
use async_jsonrpc_client::{HttpReqwestTransport, Params, Transport, Value}; | ||
#[tokio::main] | ||
async fn main() { | ||
env_logger::init(); | ||
let http = HttpReqwestTransport::new("http://127.0.0.1:1234/rpc/v0"); | ||
// Filecoin.Version need read permission | ||
let version: Value = http | ||
.send("Filecoin.Version", Params::Array(vec![])) | ||
.await | ||
.unwrap(); | ||
println!("Version: {:?}", version); | ||
// lotus auth create-token --perm admin | ||
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.V82x4rrMmyzgLhW0jeBCL6FVN8I6iSnB0Dc05xeZjVE"; | ||
let http = HttpReqwestTransport::new_with_bearer_auth("http://127.0.0.1:1234/rpc/v0", token); | ||
// Filecoin.LogList need write permission | ||
let log_list: Value = http | ||
.send("Filecoin.LogList", Params::Array(vec![])) | ||
.await | ||
.unwrap(); | ||
println!("LogList: {:?}", log_list); | ||
} | ||
*/ | ||
|
||
fn main() {} |
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,42 @@ | ||
/* | ||
use async_jsonrpc_client::{ | ||
Params, PubsubTransport, SubscriptionId, Transport, Value, WebSocketTransport, | ||
}; | ||
use futures::stream::StreamExt; | ||
#[tokio::main] | ||
async fn main() { | ||
env_logger::init(); | ||
let ws = WebSocketTransport::new("ws://127.0.0.1:1234/rpc/v0"); | ||
// Filecoin.Version need read permission | ||
let version: Value = ws | ||
.send("Filecoin.Version", Params::Array(vec![])) | ||
.await | ||
.unwrap(); | ||
println!("Version: {:?}", version); | ||
// lotus auth create-token --perm admin | ||
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.zKxsT3HxoYdjy6A8cF1Q3qvJEbCxJb3PcAZ_CM-sf9I"; | ||
let ws = WebSocketTransport::new_with_bearer_auth("ws://127.0.0.1:1234/rpc/v0", token); | ||
// Filecoin.LogList need write permission | ||
let log_list: Value = ws | ||
.send("Filecoin.LogList", Params::Array(vec![])) | ||
.await | ||
.unwrap(); | ||
println!("LogList: {:?}", log_list); | ||
let ws = WebSocketTransport::new("ws://127.0.0.1:1234/rpc/v0"); | ||
let id: SubscriptionId = ws | ||
.send("Filecoin.SyncIncomingBlocks", Params::Array(vec![])) | ||
.await | ||
.unwrap(); | ||
println!("Subscription Id: {}", id); | ||
let mut stream = ws.subscribe::<Value>(id); | ||
while let Some(value) = stream.next().await { | ||
println!("Block: {:?}", value); | ||
} | ||
} | ||
*/ | ||
|
||
fn main() {} |
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,35 @@ | ||
use thiserror::Error; | ||
|
||
pub(crate) type Result<T, E = RpcClientError> = std::result::Result<T, E>; | ||
|
||
/// The error type for rpc client. | ||
#[derive(Debug, Error)] | ||
pub enum RpcClientError { | ||
/// Json serialization/deserialization error. | ||
#[error(transparent)] | ||
Json(#[from] serde_json::Error), | ||
#[cfg(feature = "http-tokio")] | ||
/// HTTP request error. | ||
#[error(transparent)] | ||
HttpRequest(#[from] reqwest::Error), | ||
#[cfg(feature = "http-async-std")] | ||
/// HTTP request error. | ||
#[error(transparent)] | ||
HttpRequest(anyhow::Error), | ||
/// HTTP connection error. | ||
#[cfg(any(feature = "ws-tokio", feature = "ws-async-std"))] | ||
#[error(transparent)] | ||
HttpConnection(#[from] async_tungstenite::tungstenite::http::Error), | ||
/// WebSocket protocol error. | ||
#[cfg(any(feature = "ws-tokio", feature = "ws-async-std"))] | ||
#[error(transparent)] | ||
WebSocket(#[from] async_tungstenite::tungstenite::Error), | ||
/// Internal task finished | ||
#[cfg(any(feature = "ws-tokio", feature = "ws-async-std"))] | ||
#[error("Cannot send request, internal task finished")] | ||
InternalTaskFinish, | ||
|
||
/// Rpc request error, return failure response. | ||
#[error(transparent)] | ||
RpcResponse(#[from] jsonrpc_types::Error), | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.