Embedd rpc spec in rpc api
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
12
src/rpc.rs
12
src/rpc.rs
@@ -22,6 +22,9 @@ use crate::{
|
|||||||
time::current_timestamp,
|
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 struct AppState {
|
||||||
pub service: AppService,
|
pub service: AppService,
|
||||||
}
|
}
|
||||||
@@ -638,6 +641,15 @@ pub fn build_module(state: Arc<AppState>) -> RpcModule<()> {
|
|||||||
})
|
})
|
||||||
.expect("register message.load");
|
.expect("register message.load");
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
module
|
||||||
|
.register_async_method("rpc.discover", move |_params, _caller, _ctx| async move {
|
||||||
|
let spec = serde_json::from_str::<serde_json::Value>(OPENRPC_SPEC)
|
||||||
|
.expect("Failed to parse OpenRPC spec");
|
||||||
|
Ok::<_, ErrorObjectOwned>(spec)
|
||||||
|
})
|
||||||
|
.expect("register rpc.discover");
|
||||||
|
}
|
||||||
|
|
||||||
module
|
module
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user