use jsonrpsee::core::RpcResult; pub use sov_modules_api::default_context::DefaultContext; use sov_modules_api::macros::{expose_rpc, rpc_gen}; use sov_modules_api::{CallResponse, Context, Error, Module, ModuleInfo, StateValue, WorkingSet}; #[derive(ModuleInfo)] pub struct QueryModule { #[address] pub address: C::Address, #[state] pub data: StateValue, } impl Module for QueryModule { type Context = C; type Config = u8; type CallMessage = u8; fn genesis( &self, config: &Self::Config, working_set: &mut WorkingSet, ) -> Result<(), Error> { self.data.set(config, working_set); Ok(()) } fn call( &self, msg: Self::CallMessage, _context: &Self::Context, working_set: &mut WorkingSet, ) -> Result { self.data.set(&msg, working_set); Ok(CallResponse::default()) } } #[derive(Debug, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)] pub struct QueryResponse { pub value: Option, } #[rpc_gen(client, server, namespace = "queryModule")] impl QueryModule { #[rpc_method(name = "queryValue")] pub fn query_value( &self, working_set: &mut WorkingSet, ) -> RpcResult { Ok(QueryResponse { value: self.data.get(working_set), }) } } #[expose_rpc] struct Runtime { pub first: QueryModule, } fn main() {}