//! Zebra supported RPC methods. //! //! Based on the [`zcashd` RPC methods](https://zcash.github.io/rpc/) //! as used by `lightwalletd.` //! //! Some parts of the `zcashd` RPC documentation are outdated. //! So this implementation follows the `lightwalletd` client implementation. use jsonrpc_core::{self, Result}; use jsonrpc_derive::rpc; use zebra_network::constants::USER_AGENT; #[cfg(test)] mod tests; #[rpc(server)] /// RPC method signatures. pub trait Rpc { /// getinfo /// /// Returns software information from the RPC server running Zebra. /// /// zcashd reference: /// /// Result: /// { /// "build": String, // Full application version /// "subversion", String, // Zebra user agent /// } /// /// Note 1: We only expose 2 fields as they are the only ones needed for /// lightwalletd: /// /// Note 2: is outdated so it does not /// show the fields we are exposing. However, this fields are part of the output /// as shown in the following zcashd code: /// /// Zcash open ticket to add this fields to the docs: #[rpc(name = "getinfo")] fn get_info(&self) -> Result; /// getblockchaininfo /// /// TODO: explain what the method does /// link to the zcashd RPC reference /// list the arguments and fields that lightwalletd uses /// note any other lightwalletd changes #[rpc(name = "getblockchaininfo")] fn get_blockchain_info(&self) -> Result; } /// RPC method implementations. pub struct RpcImpl { /// Zebra's application version. pub app_version: String, } impl Rpc for RpcImpl { fn get_info(&self) -> Result { let response = GetInfo { build: self.app_version.clone(), subversion: USER_AGENT.into(), }; Ok(response) } fn get_blockchain_info(&self) -> Result { // TODO: dummy output data, fix in the context of #3143 let response = GetBlockChainInfo { chain: "TODO: main".to_string(), }; Ok(response) } } #[derive(serde::Serialize, serde::Deserialize)] /// Response to a `getinfo` RPC request. pub struct GetInfo { build: String, subversion: String, } #[derive(serde::Serialize, serde::Deserialize)] /// Response to a `getblockchaininfo` RPC request. pub struct GetBlockChainInfo { chain: String, // TODO: add other fields used by lightwalletd (#3143) }