From 9c47eaaf93a4c4253cd5e7763f58750e25b0e823 Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Fri, 29 Aug 2025 09:59:42 +0200 Subject: [PATCH] Embedd rpc spec in rpc api Signed-off-by: Lee Smet --- src/rpc.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rpc.rs b/src/rpc.rs index 8ab1755..9893d33 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -22,6 +22,9 @@ use crate::{ time::current_timestamp, }; +/// The OpenRPC specification for the HeroCoordinator JSON-RPC API +const OPENRPC_SPEC: &str = include_str!("../specs/openrpc.json"); + pub struct AppState { pub service: AppService, } @@ -638,6 +641,15 @@ pub fn build_module(state: Arc) -> RpcModule<()> { }) .expect("register message.load"); } + { + module + .register_async_method("rpc.discover", move |_params, _caller, _ctx| async move { + let spec = serde_json::from_str::(OPENRPC_SPEC) + .expect("Failed to parse OpenRPC spec"); + Ok::<_, ErrorObjectOwned>(spec) + }) + .expect("register rpc.discover"); + } module }