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

Function rpc_select

json/jsonrpc/src/main.rs:47–83  ·  view source on GitHub ↗
(
    app_state: &AppState,
    method: &str,
    params: Vec<Value>,
)

Source from the content-addressed store, hash-verified

45}
46
47async fn rpc_select(
48 app_state: &AppState,
49 method: &str,
50 params: Vec<Value>,
51) -> Result<Value, convention::ErrorData> {
52 match method {
53 "ping" => {
54 let r = app_state.network.read().unwrap().ping();
55 Ok(Value::from(r))
56 }
57 "wait" => {
58 if params.len() != 1 || !params[0].is_u64() {
59 return Err(convention::ErrorData::std(-32602));
60 }
61
62 let fut = app_state
63 .network
64 .read()
65 .unwrap()
66 .wait(params[0].as_u64().unwrap());
67
68 match fut.await {
69 Ok(ok) => Ok(Value::from(ok)),
70 Err(e) => Err(convention::ErrorData::new(500, &format!("{e:?}")[..])),
71 }
72 }
73 "get" => {
74 let r = app_state.network.read().unwrap().get();
75 Ok(Value::from(r))
76 }
77 "inc" => {
78 app_state.network.write().unwrap().inc();
79 Ok(Value::Null)
80 }
81 _ => Err(convention::ErrorData::std(-32601)),
82 }
83}
84
85pub trait ImplNetwork {
86 fn ping(&self) -> String;

Callers 1

rpc_handlerFunction · 0.85

Calls 4

pingMethod · 0.80
waitMethod · 0.80
getMethod · 0.80
incMethod · 0.80

Tested by

no test coverage detected