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;
40mod ledger_service;
41mod move_package_service;
42mod name_service;
43mod object;
44mod signatures;
45mod transaction;
46mod transaction_execution_service;
47
48//
49// Bcs
50//
51
52impl Bcs {
53 pub fn serialize<T: serde::Serialize>(value: &T) -> Result<Self, bcs::Error> {
54 bcs::to_bytes(value).map(|bcs| Self {
55 name: None,
56 value: Some(bcs.into()),
57 })
58 }
59
60 pub fn deserialize<'de, T: serde::Deserialize<'de>>(&'de self) -> Result<T, bcs::Error> {
61 bcs::from_bytes(self.value.as_deref().unwrap_or(&[]))
62 }
63}
64
65impl From<Vec<u8>> for Bcs {
66 fn from(value: Vec<u8>) -> Self {
67 Self {
68 name: None,
69 value: Some(value.into()),
70 }
71 }
72}
73
74impl From<&Bcs> for Vec<u8> {
75 fn from(value: &Bcs) -> Self {
76 value
77 .value
78 .as_ref()
79 .map(|bytes| bytes.to_vec())
80 .unwrap_or_default()
81 }
82}
83
84impl From<Bcs> for Vec<u8> {
85 fn from(value: Bcs) -> Self {
86 value
87 .value
88 .as_ref()
89 .map(|bytes| bytes.to_vec())
90 .unwrap_or_default()
91 }
92}
93
94impl From<prost::bytes::Bytes> for Bcs {
95 fn from(value: prost::bytes::Bytes) -> Self {
96 Self {
97 name: None,
98 value: Some(value),
99 }
100 }
101}
102
103impl From<&Bcs> for prost::bytes::Bytes {
104 fn from(value: &Bcs) -> Self {
105 value.value.clone().unwrap_or_default()
106 }
107}
108
109impl From<Bcs> for prost::bytes::Bytes {
110 fn from(value: Bcs) -> Self {
111 value.value.unwrap_or_default()
112 }
113}
114
115impl AsRef<str> for ErrorReason {
116 fn as_ref(&self) -> &str {
117 self.as_str_name()
118 }
119}
120
121impl From<ErrorReason> for String {
122 fn from(value: ErrorReason) -> Self {
123 value.as_ref().into()
124 }
125}