timestampvm/api/
mod.rs

1//! Implementation of timestampvm APIs, to be registered via
2//! `create_static_handlers` and `create_handlers` in the [`vm`](crate::vm) crate.
3
4pub mod chain_handlers;
5pub mod static_handlers;
6
7use std::io;
8
9use bytes::Bytes;
10use jsonrpc_core::MethodCall;
11use serde::{Deserialize, Serialize};
12
13#[derive(Deserialize, Serialize, Debug, Clone)]
14pub struct PingResponse {
15    pub success: bool,
16}
17
18/// Deserializes JSON-RPC method call.
19/// # Errors
20/// Fails if the request is not a valid JSON-RPC method call.
21pub fn de_request(req: &Bytes) -> io::Result<String> {
22    let method_call: MethodCall = serde_json::from_slice(req).map_err(|e| {
23        io::Error::new(
24            io::ErrorKind::Other,
25            format!("failed to deserialize request: {e}"),
26        )
27    })?;
28    serde_json::to_string(&method_call).map_err(|e| {
29        io::Error::new(
30            io::ErrorKind::Other,
31            format!("failed to serialize request: {e}"),
32        )
33    })
34}