sui_json_rpc_types/
sui_protocol.rs1use std::collections::BTreeMap;
5
6use schemars::JsonSchema;
7use serde::{Deserialize, Serialize};
8use serde_with::DisplayFromStr;
9use serde_with::serde_as;
10use sui_protocol_config::{ProtocolConfig, ProtocolConfigValue, ProtocolVersion};
11use sui_types::sui_serde::Readable;
12use sui_types::sui_serde::{AsProtocolVersion, BigInt};
13
14#[serde_as]
15#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, PartialEq)]
16#[serde(rename_all = "camelCase", rename = "ProtocolConfigValue")]
17pub enum SuiProtocolConfigValue {
18 U16(
19 #[schemars(with = "BigInt<u16>")]
20 #[serde_as(as = "BigInt<u16>")]
21 u16,
22 ),
23 U32(
24 #[schemars(with = "BigInt<u32>")]
25 #[serde_as(as = "BigInt<u32>")]
26 u32,
27 ),
28 U64(
29 #[schemars(with = "BigInt<u64>")]
30 #[serde_as(as = "BigInt<u64>")]
31 u64,
32 ),
33 F64(
34 #[schemars(with = "String")]
35 #[serde_as(as = "DisplayFromStr")]
36 f64,
37 ),
38 Bool(
39 #[schemars(with = "String")]
40 #[serde_as(as = "DisplayFromStr")]
41 bool,
42 ),
43}
44
45impl From<ProtocolConfigValue> for SuiProtocolConfigValue {
46 fn from(value: ProtocolConfigValue) -> Self {
47 match value {
48 ProtocolConfigValue::u16(y) => SuiProtocolConfigValue::U16(y),
49 ProtocolConfigValue::u32(y) => SuiProtocolConfigValue::U32(y),
50 ProtocolConfigValue::u64(x) => SuiProtocolConfigValue::U64(x),
51 ProtocolConfigValue::bool(z) => SuiProtocolConfigValue::Bool(z),
52 }
53 }
54}
55
56#[serde_as]
57#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, PartialEq)]
58#[serde(rename_all = "camelCase", rename = "ProtocolConfig")]
59pub struct ProtocolConfigResponse {
60 #[schemars(with = "AsProtocolVersion")]
61 #[serde_as(as = "Readable<AsProtocolVersion, _>")]
62 pub min_supported_protocol_version: ProtocolVersion,
63 #[schemars(with = "AsProtocolVersion")]
64 #[serde_as(as = "Readable<AsProtocolVersion, _>")]
65 pub max_supported_protocol_version: ProtocolVersion,
66 #[schemars(with = "AsProtocolVersion")]
67 #[serde_as(as = "Readable<AsProtocolVersion, _>")]
68 pub protocol_version: ProtocolVersion,
69 pub feature_flags: BTreeMap<String, bool>,
70 pub attributes: BTreeMap<String, Option<SuiProtocolConfigValue>>,
71}
72
73impl From<ProtocolConfig> for ProtocolConfigResponse {
74 fn from(config: ProtocolConfig) -> Self {
75 ProtocolConfigResponse {
76 protocol_version: config.version,
77 attributes: config
78 .attr_map()
79 .into_iter()
80 .map(|(k, v)| (k, v.map(SuiProtocolConfigValue::from)))
81 .collect(),
82 min_supported_protocol_version: ProtocolVersion::MIN,
83 max_supported_protocol_version: ProtocolVersion::MAX,
84 feature_flags: config.feature_map(),
85 }
86 }
87}