radrootsd

JSON-RPC bridge for Radroots event publishing
git clone https://radroots.dev/git/radrootsd.git
Log | Files | Refs | README | LICENSE

session_close.rs (890B)


      1 use anyhow::Result;
      2 use jsonrpsee::server::RpcModule;
      3 use serde::{Deserialize, Serialize};
      4 
      5 use crate::transport::jsonrpc::{MethodRegistry, RpcContext, RpcError};
      6 
      7 #[derive(Debug, Deserialize)]
      8 struct Nip46SessionCloseParams {
      9     session_id: String,
     10 }
     11 
     12 #[derive(Clone, Debug, Serialize)]
     13 struct Nip46SessionCloseResponse {
     14     closed: bool,
     15 }
     16 
     17 pub fn register(m: &mut RpcModule<RpcContext>, registry: &MethodRegistry) -> Result<()> {
     18     registry.track("nip46.session.close");
     19     m.register_async_method("nip46.session.close", |params, ctx, _| async move {
     20         let Nip46SessionCloseParams { session_id } = params
     21             .parse()
     22             .map_err(|e| RpcError::InvalidParams(e.to_string()))?;
     23         let closed = ctx.state.nip46_sessions.remove(&session_id).await;
     24         Ok::<Nip46SessionCloseResponse, RpcError>(Nip46SessionCloseResponse { closed })
     25     })?;
     26     Ok(())
     27 }