cfx_rpc_primitives/
rpc_module.rs1use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
8#[serde(transparent)]
9pub struct RpcModules {
10 module_map: HashMap<String, String>,
11}
12
13impl RpcModules {
14 pub const fn new(module_map: HashMap<String, String>) -> Self {
16 Self { module_map }
17 }
18
19 pub fn into_modules(self) -> HashMap<String, String> { self.module_map }
22}
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27 #[test]
28 fn test_parse_module_versions_roundtrip() {
29 let s = r#"{"txpool":"1.0","trace":"1.0","eth":"1.0","web3":"1.0","net":"1.0"}"#;
30 let module_map = HashMap::from([
31 ("txpool".to_owned(), "1.0".to_owned()),
32 ("trace".to_owned(), "1.0".to_owned()),
33 ("eth".to_owned(), "1.0".to_owned()),
34 ("web3".to_owned(), "1.0".to_owned()),
35 ("net".to_owned(), "1.0".to_owned()),
36 ]);
37 let m = RpcModules::new(module_map);
38 let de_serialized: RpcModules = serde_json::from_str(s).unwrap();
39 assert_eq!(de_serialized, m);
40 }
41}