Skip to main content

sui_rpc/proto/sui/rpc/v2/
mod.rs

1#![allow(clippy::uninlined_format_args)]
2
3// Include the generated proto definitions
4include!("../../../generated/sui.rpc.v2.rs");
5
6// Include generated field info impls
7include!("../../../generated/sui.rpc.v2.field_info.rs");
8
9// Include generated serde impls
10include!("../../../generated/sui.rpc.v2.serde.rs");
11include!("../../../generated/sui.rpc.v2.accessors.rs");
12
13pub use descriptor::FILE_DESCRIPTOR_SET;
14mod descriptor {
15    /// Byte encoded FILE_DESCRIPTOR_SET.
16    pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("../../../generated/sui.rpc.v2.fds.bin");
17
18    #[cfg(test)]
19    mod tests {
20        use super::FILE_DESCRIPTOR_SET;
21        use prost::Message as _;
22
23        #[test]
24        fn file_descriptor_set_is_valid() {
25            prost_types::FileDescriptorSet::decode(FILE_DESCRIPTOR_SET).unwrap();
26        }
27    }
28}
29
30#[cfg(test)]
31mod proptests;
32
33mod balance_change;
34mod checkpoint;
35mod effects;
36mod epoch;
37mod events;
38mod executed_transaction;
39mod execution_status;
40pub mod filter;
41mod ledger_service;
42mod move_package_service;
43mod name_service;
44mod object;
45mod signatures;
46mod transaction;
47mod transaction_execution_service;
48
49//
50// Bcs
51//
52
53impl Bcs {
54    pub fn serialize<T: serde::Serialize>(value: &T) -> Result<Self, bcs::Error> {
55        bcs::to_bytes(value).map(|bcs| Self {
56            name: None,
57            value: Some(bcs.into()),
58        })
59    }
60
61    pub fn deserialize<'de, T: serde::Deserialize<'de>>(&'de self) -> Result<T, bcs::Error> {
62        bcs::from_bytes(self.value.as_deref().unwrap_or(&[]))
63    }
64}
65
66impl From<Vec<u8>> for Bcs {
67    fn from(value: Vec<u8>) -> Self {
68        Self {
69            name: None,
70            value: Some(value.into()),
71        }
72    }
73}
74
75impl From<&Bcs> for Vec<u8> {
76    fn from(value: &Bcs) -> Self {
77        value
78            .value
79            .as_ref()
80            .map(|bytes| bytes.to_vec())
81            .unwrap_or_default()
82    }
83}
84
85impl From<Bcs> for Vec<u8> {
86    fn from(value: Bcs) -> Self {
87        value
88            .value
89            .as_ref()
90            .map(|bytes| bytes.to_vec())
91            .unwrap_or_default()
92    }
93}
94
95impl From<prost::bytes::Bytes> for Bcs {
96    fn from(value: prost::bytes::Bytes) -> Self {
97        Self {
98            name: None,
99            value: Some(value),
100        }
101    }
102}
103
104impl From<&Bcs> for prost::bytes::Bytes {
105    fn from(value: &Bcs) -> Self {
106        value.value.clone().unwrap_or_default()
107    }
108}
109
110impl From<Bcs> for prost::bytes::Bytes {
111    fn from(value: Bcs) -> Self {
112        value.value.unwrap_or_default()
113    }
114}
115
116impl AsRef<str> for ErrorReason {
117    fn as_ref(&self) -> &str {
118        self.as_str_name()
119    }
120}
121
122impl From<ErrorReason> for String {
123    fn from(value: ErrorReason) -> Self {
124        value.as_ref().into()
125    }
126}