The main handler for JSONRPC server.
(body: Bytes, app_state: web::Data<AppState>)
| 15 | |
| 16 | /// The main handler for JSONRPC server. |
| 17 | async 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 | |
| 47 | async fn rpc_select( |
| 48 | app_state: &AppState, |
nothing calls this directly
no test coverage detected