Skip to main content

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

1use sui_sdk_types::Address;
2use sui_sdk_types::Digest;
3
4use super::*;
5
6impl GetObjectRequest {
7    pub fn new(object_id: &Address) -> Self {
8        Self {
9            object_id: Some(object_id.to_string()),
10            version: None,
11            read_mask: None,
12            at_checkpoint: None,
13            max_version: None,
14        }
15    }
16}
17
18impl GetObjectResponse {
19    pub fn new(object: Object) -> Self {
20        Self {
21            object: Some(object),
22        }
23    }
24}
25
26impl BatchGetObjectsResponse {
27    pub fn new(objects: Vec<GetObjectResult>) -> Self {
28        Self { objects }
29    }
30}
31
32impl GetObjectResult {
33    pub fn new_object(object: Object) -> Self {
34        Self {
35            result: Some(get_object_result::Result::Object(object)),
36        }
37    }
38
39    pub fn new_error(error: crate::proto::google::rpc::Status) -> Self {
40        Self {
41            result: Some(get_object_result::Result::Error(error)),
42        }
43    }
44
45    pub fn to_result(self) -> Result<Object, crate::proto::google::rpc::Status> {
46        match self.result {
47            Some(get_object_result::Result::Object(object)) => Ok(object),
48            Some(get_object_result::Result::Error(error)) => Err(error),
49            None => Err(crate::proto::google::rpc::Status {
50                code: tonic::Code::NotFound.into(),
51                ..Default::default()
52            }),
53        }
54    }
55}
56
57impl GetTransactionRequest {
58    pub fn new(digest: &Digest) -> Self {
59        Self {
60            digest: Some(digest.to_string()),
61            read_mask: None,
62        }
63    }
64}
65
66impl GetTransactionResponse {
67    pub fn new(transaction: ExecutedTransaction) -> Self {
68        Self {
69            transaction: Some(transaction),
70        }
71    }
72}
73
74impl BatchGetTransactionsResponse {
75    pub fn new(transactions: Vec<GetTransactionResult>) -> Self {
76        Self { transactions }
77    }
78}
79
80impl GetTransactionResult {
81    pub fn new_transaction(transaction: ExecutedTransaction) -> Self {
82        Self {
83            result: Some(get_transaction_result::Result::Transaction(transaction)),
84        }
85    }
86
87    pub fn new_error(error: crate::proto::google::rpc::Status) -> Self {
88        Self {
89            result: Some(get_transaction_result::Result::Error(error)),
90        }
91    }
92
93    pub fn to_result(self) -> Result<ExecutedTransaction, crate::proto::google::rpc::Status> {
94        match self.result {
95            Some(get_transaction_result::Result::Transaction(transaction)) => Ok(transaction),
96            Some(get_transaction_result::Result::Error(error)) => Err(error),
97            None => Err(crate::proto::google::rpc::Status {
98                code: tonic::Code::NotFound.into(),
99                ..Default::default()
100            }),
101        }
102    }
103}
104
105impl GetCheckpointRequest {
106    pub fn latest() -> Self {
107        Self {
108            read_mask: None,
109            checkpoint_id: None,
110        }
111    }
112
113    pub fn by_sequence_number(checkpoint: u64) -> Self {
114        Self {
115            read_mask: None,
116            checkpoint_id: Some(get_checkpoint_request::CheckpointId::SequenceNumber(
117                checkpoint,
118            )),
119        }
120    }
121
122    pub fn by_digest(digest: &Digest) -> Self {
123        Self {
124            read_mask: None,
125            checkpoint_id: Some(get_checkpoint_request::CheckpointId::Digest(
126                digest.to_string(),
127            )),
128        }
129    }
130}
131
132impl GetCheckpointResponse {
133    pub fn new(checkpoint: Checkpoint) -> Self {
134        Self {
135            checkpoint: Some(checkpoint),
136        }
137    }
138}
139
140impl GetEpochRequest {
141    pub fn latest() -> Self {
142        Self {
143            epoch: None,
144            read_mask: None,
145        }
146    }
147
148    pub fn new(epoch: u64) -> Self {
149        Self {
150            epoch: Some(epoch),
151            read_mask: None,
152        }
153    }
154}
155
156impl GetEpochResponse {
157    pub fn new(epoch: Epoch) -> Self {
158        Self { epoch: Some(epoch) }
159    }
160}
161
162impl GetProtocolConfigRequest {
163    pub fn latest() -> Self {
164        Self {
165            version: None,
166            read_mask: None,
167        }
168    }
169
170    pub fn new(version: u64) -> Self {
171        Self {
172            version: Some(version),
173            read_mask: None,
174        }
175    }
176}
177
178impl GetProtocolConfigResponse {
179    pub fn new(protocol_config: ProtocolConfig) -> Self {
180        Self {
181            protocol_config: Some(protocol_config),
182        }
183    }
184}