MCPcopy Create free account
hub / github.com/actix/examples / rpc_handler

Function rpc_handler

json/jsonrpc/src/main.rs:17–45  ·  view source on GitHub ↗

The main handler for JSONRPC server.

(body: Bytes, app_state: web::Data<AppState>)

Source from the content-addressed store, hash-verified

15
16/// The main handler for JSONRPC server.
17async fn rpc_handler(body: Bytes, app_state: web::Data<AppState>) -> Result<HttpResponse, Error> {
18 let reqjson: convention::Request = match serde_json::from_slice(body.as_ref()) {
19 Ok(ok) => ok,
20 Err(_) => {
21 let r = convention::Response {
22 jsonrpc: String::from(convention::JSONRPC_VERSION),
23 result: Value::Null,
24 error: Some(convention::ErrorData::std(-32700)),
25 id: Value::Null,
26 };
27 return Ok(HttpResponse::Ok()
28 .content_type("application/json")
29 .body(r.dump()));
30 }
31 };
32 let mut result = convention::Response {
33 id: reqjson.id.clone(),
34 ..convention::Response::default()
35 };
36
37 match rpc_select(&app_state, reqjson.method.as_str(), reqjson.params).await {
38 Ok(ok) => result.result = ok,
39 Err(e) => result.error = Some(e),
40 }
41
42 Ok(HttpResponse::Ok()
43 .content_type("application/json")
44 .body(result.dump()))
45}
46
47async fn rpc_select(
48 app_state: &AppState,

Callers

nothing calls this directly

Calls 3

rpc_selectFunction · 0.85
dumpMethod · 0.80
as_strMethod · 0.80

Tested by

no test coverage detected