draft: server: rpc client
parent
c329e7f504
commit
4a37e703eb
|
@ -807,9 +807,12 @@ dependencies = [
|
||||||
"futures 0.3.19",
|
"futures 0.3.19",
|
||||||
"jsonrpc-core",
|
"jsonrpc-core",
|
||||||
"jsonrpc-pubsub",
|
"jsonrpc-pubsub",
|
||||||
|
"jsonrpc-server-utils",
|
||||||
"log",
|
"log",
|
||||||
|
"parity-tokio-ipc",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"tokio",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,16 @@ figment = "^0.10"
|
||||||
jsonrpc-core = "~18.0"
|
jsonrpc-core = "~18.0"
|
||||||
jsonrpc-derive = "~18.0"
|
jsonrpc-derive = "~18.0"
|
||||||
jsonrpc-ipc-server = "~18.0"
|
jsonrpc-ipc-server = "~18.0"
|
||||||
jsonrpc-core-client = "~18.0"
|
|
||||||
serde = "^1.0"
|
serde = "^1.0"
|
||||||
|
|
||||||
|
[dependencies.jsonrpc-core-client]
|
||||||
|
version = "~18.0"
|
||||||
|
features = ["ipc"]
|
||||||
|
|
||||||
[dependencies.procfs]
|
[dependencies.procfs]
|
||||||
version = "^0.12"
|
version = "^0.12"
|
||||||
features = ["chrono"]
|
features = ["chrono"]
|
||||||
|
|
||||||
[dependencies.rocket]
|
[dependencies.rocket]
|
||||||
version = "^0.5.0-rc.1"
|
version = "^0.5.0-rc.1"
|
||||||
features = ["json", "secrets", "tls"]
|
features = ["json", "secrets", "tls"]
|
|
@ -0,0 +1,5 @@
|
||||||
|
use crate::rpc::gen_client::Client;
|
||||||
|
|
||||||
|
pub struct Context {
|
||||||
|
pub rpc_client: Client,
|
||||||
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
mod config;
|
mod config;
|
||||||
|
mod context;
|
||||||
mod routes;
|
mod routes;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
|
||||||
use argh::FromArgs;
|
use argh::FromArgs;
|
||||||
|
use context::Context;
|
||||||
|
use jsonrpc_core_client::transports::ipc::connect;
|
||||||
use rocket;
|
use rocket;
|
||||||
use rocket::fairing::AdHoc;
|
use rocket::fairing::AdHoc;
|
||||||
use rocket::figment::providers::{Env, Format, Serialized, Toml};
|
use rocket::figment::providers::{Env, Format, Serialized, Toml};
|
||||||
|
@ -43,9 +46,14 @@ pub async fn main() -> Result<(), rocket::Error> {
|
||||||
figment = figment.merge(("port", port));
|
figment = figment.merge(("port", port));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let context = Context {
|
||||||
|
rpc_client: connect("weywot.sock").await.unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
rocket::custom(figment)
|
rocket::custom(figment)
|
||||||
.mount("/", rocket::routes![routes::hello::hello])
|
.mount("/", rocket::routes![routes::status::get_status])
|
||||||
.attach(AdHoc::config::<Config>())
|
.attach(AdHoc::config::<Config>())
|
||||||
|
.manage(context)
|
||||||
.ignite()
|
.ignite()
|
||||||
.await?
|
.await?
|
||||||
.launch()
|
.launch()
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
pub mod hello;
|
pub mod hello;
|
||||||
|
pub mod status;
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
use crate::rpc::Status;
|
||||||
|
use crate::server::context::Context;
|
||||||
|
use rocket::State;
|
||||||
|
use rocket::serde::json::Json;
|
||||||
|
|
||||||
|
#[rocket::get("/status")]
|
||||||
|
pub async fn get_status(state: &State<Context>) -> Json<Status> {
|
||||||
|
Json(state.rpc_client.status().await.unwrap())
|
||||||
|
}
|
Loading…
Reference in New Issue