sui_rpc/proto/sui/rpc/v2beta2/
ledger_service.rs1use 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 }
13 }
14}
15
16impl GetObjectResponse {
17 pub fn new(object: Object) -> Self {
18 Self {
19 object: Some(object),
20 }
21 }
22}
23
24impl BatchGetObjectsResponse {
25 pub fn new(objects: Vec<GetObjectResult>) -> Self {
26 Self { objects }
27 }
28}
29
30impl GetObjectResult {
31 pub fn new_object(object: Object) -> Self {
32 Self {
33 result: Some(get_object_result::Result::Object(object)),
34 }
35 }
36
37 pub fn new_error(error: crate::proto::google::rpc::Status) -> Self {
38 Self {
39 result: Some(get_object_result::Result::Error(error)),
40 }
41 }
42
43 pub fn to_result(self) -> Result<Object, crate::proto::google::rpc::Status> {
44 match self.result {
45 Some(get_object_result::Result::Object(object)) => Ok(object),
46 Some(get_object_result::Result::Error(error)) => Err(error),
47 None => Err(crate::proto::google::rpc::Status {
48 code: tonic::Code::NotFound.into(),
49 ..Default::default()
50 }),
51 }
52 }
53}
54
55impl GetTransactionRequest {
56 pub fn new(digest: &Digest) -> Self {
57 Self {
58 digest: Some(digest.to_string()),
59 read_mask: None,
60 }
61 }
62}
63
64impl GetTransactionResponse {
65 pub fn new(transaction: ExecutedTransaction) -> Self {
66 Self {
67 transaction: Some(transaction),
68 }
69 }
70}
71
72impl BatchGetTransactionsResponse {
73 pub fn new(transactions: Vec<GetTransactionResult>) -> Self {
74 Self { transactions }
75 }
76}
77
78impl GetTransactionResult {
79 pub fn new_transaction(transaction: ExecutedTransaction) -> Self {
80 Self {
81 result: Some(get_transaction_result::Result::Transaction(transaction)),
82 }
83 }
84
85 pub fn new_error(error: crate::proto::google::rpc::Status) -> Self {
86 Self {
87 result: Some(get_transaction_result::Result::Error(error)),
88 }
89 }
90
91 pub fn to_result(self) -> Result<ExecutedTransaction, crate::proto::google::rpc::Status> {
92 match self.result {
93 Some(get_transaction_result::Result::Transaction(transaction)) => Ok(transaction),
94 Some(get_transaction_result::Result::Error(error)) => Err(error),
95 None => Err(crate::proto::google::rpc::Status {
96 code: tonic::Code::NotFound.into(),
97 ..Default::default()
98 }),
99 }
100 }
101}
102
103impl GetCheckpointRequest {
104 pub fn latest() -> Self {
105 Self {
106 read_mask: None,
107 checkpoint_id: None,
108 }
109 }
110
111 pub fn by_sequence_number(checkpoint: u64) -> Self {
112 Self {
113 read_mask: None,
114 checkpoint_id: Some(get_checkpoint_request::CheckpointId::SequenceNumber(
115 checkpoint,
116 )),
117 }
118 }
119
120 pub fn by_digest(digest: &Digest) -> Self {
121 Self {
122 read_mask: None,
123 checkpoint_id: Some(get_checkpoint_request::CheckpointId::Digest(
124 digest.to_string(),
125 )),
126 }
127 }
128}
129
130impl GetCheckpointResponse {
131 pub fn new(checkpoint: Checkpoint) -> Self {
132 Self {
133 checkpoint: Some(checkpoint),
134 }
135 }
136}
137
138impl GetEpochRequest {
139 pub fn latest() -> Self {
140 Self {
141 epoch: None,
142 read_mask: None,
143 }
144 }
145
146 pub fn new(epoch: u64) -> Self {
147 Self {
148 epoch: Some(epoch),
149 read_mask: None,
150 }
151 }
152}
153
154impl GetEpochResponse {
155 pub fn new(epoch: Epoch) -> Self {
156 Self { epoch: Some(epoch) }
157 }
158}