1use cuprate_fixed_bytes::ByteArrayVec;
7
8#[cfg(feature = "serde")]
9use serde::{Deserialize, Serialize};
10
11#[cfg(feature = "epee")]
12use cuprate_epee_encoding::container_as_blob::ContainerAsBlob;
13
14use cuprate_types::{
15 rpc::{BlockOutputIndices, PoolInfo},
16 BlockCompleteEntry,
17};
18
19use crate::{
20 base::AccessResponseBase,
21 macros::define_request_and_response,
22 misc::{GetOutputsOut, OutKeyBin},
23 rpc_call::RpcCallValue,
24};
25
26#[cfg(any(feature = "epee", feature = "serde"))]
27use crate::defaults::default;
28
29define_request_and_response! {
31 get_blocks_by_heightbin,
32 "cc73fe71162d564ffda8e549b79a350bca53c454" =>
33 core_rpc_server_commands_defs.h => 264..=286,
34 GetBlocksByHeight,
35 Request {
36 heights: Vec<u64>,
37 },
38 AccessResponseBase {
39 blocks: Vec<BlockCompleteEntry> = default::<Vec<BlockCompleteEntry>>(), "default",
40 }
41}
42
43define_request_and_response! {
44 get_hashesbin,
45 "cc73fe71162d564ffda8e549b79a350bca53c454" =>
46 core_rpc_server_commands_defs.h => 309..=338,
47 GetHashes,
48 Request {
49 block_ids: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
50 start_height: u64,
51 },
52 AccessResponseBase {
53 m_blocks_ids: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
54 start_height: u64,
55 current_height: u64,
56 }
57}
58
59#[cfg(not(feature = "epee"))]
60define_request_and_response! {
61 get_o_indexesbin,
62 "cc73fe71162d564ffda8e549b79a350bca53c454" =>
63 core_rpc_server_commands_defs.h => 487..=510,
64 GetOutputIndexes,
65 #[derive(Copy)]
66 Request {
67 txid: [u8; 32],
68 },
69 AccessResponseBase {
70 o_indexes: Vec<u64> = default::<Vec<u64>>(), "default",
71 }
72}
73
74#[cfg(feature = "epee")]
75define_request_and_response! {
76 get_o_indexesbin,
77 "cc73fe71162d564ffda8e549b79a350bca53c454" =>
78 core_rpc_server_commands_defs.h => 487..=510,
79 GetOutputIndexes,
80 #[derive(Copy)]
81 Request {
82 txid: [u8; 32],
83 },
84 AccessResponseBase {
85 o_indexes: Vec<u64> as ContainerAsBlob<u64>,
86 }
87}
88
89define_request_and_response! {
90 get_outsbin,
91 "cc73fe71162d564ffda8e549b79a350bca53c454" =>
92 core_rpc_server_commands_defs.h => 512..=565,
93 GetOuts,
94 Request {
95 outputs: Vec<GetOutputsOut> = default::<Vec<GetOutputsOut>>(), "default",
96 get_txid: bool,
97 },
98 AccessResponseBase {
99 outs: Vec<OutKeyBin> = default::<Vec<OutKeyBin>>(), "default",
100 }
101}
102
103define_request_and_response! {
104 get_transaction_pool_hashesbin,
105 "cc73fe71162d564ffda8e549b79a350bca53c454" =>
106 core_rpc_server_commands_defs.h => 1593..=1613,
107 GetTransactionPoolHashes,
108 Request {},
109 AccessResponseBase {
110 tx_hashes: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
111 }
112}
113
114define_request_and_response! {
115 get_blocksbin,
116 "cc73fe71162d564ffda8e549b79a350bca53c454" =>
117 core_rpc_server_commands_defs.h => 162..=262,
118
119 GetBlocks,
120
121 Request {
122 requested_info: u8 = default::<u8>(), "default",
123 block_ids: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
124 start_height: u64,
125 prune: bool,
126 no_miner_tx: bool,
127 pool_info_since: u64 = default::<u64>(), "default",
128 },
129
130 AccessResponseBase {
133 blocks: Vec<BlockCompleteEntry> = default::<Vec<BlockCompleteEntry>>(), "default",
134 start_height: u64,
135 current_height: u64,
136 output_indices: Vec<BlockOutputIndices> = default::<Vec<BlockOutputIndices>>(), "default",
137 daemon_time: u64 = default::<u64>(), "default",
138 pool_info: PoolInfo = default::<PoolInfo>(), "default",
139 }
140}
141
142#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
149#[cfg_attr(feature = "serde", serde(untagged))]
150#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
151pub enum BinRequest {
152 GetBlocks(GetBlocksRequest),
153 GetBlocksByHeight(GetBlocksByHeightRequest),
154 GetHashes(GetHashesRequest),
155 GetOutputIndexes(GetOutputIndexesRequest),
156 GetOuts(GetOutsRequest),
157 GetTransactionPoolHashes(GetTransactionPoolHashesRequest),
158 GetOutputDistribution(crate::json::GetOutputDistributionRequest),
159}
160
161impl RpcCallValue for BinRequest {
162 fn is_restricted(&self) -> bool {
163 match self {
164 Self::GetBlocks(x) => x.is_restricted(),
165 Self::GetBlocksByHeight(x) => x.is_restricted(),
166 Self::GetHashes(x) => x.is_restricted(),
167 Self::GetOutputIndexes(x) => x.is_restricted(),
168 Self::GetOuts(x) => x.is_restricted(),
169 Self::GetTransactionPoolHashes(x) => x.is_restricted(),
170 Self::GetOutputDistribution(x) => x.is_restricted(),
171 }
172 }
173
174 fn is_empty(&self) -> bool {
175 match self {
176 Self::GetBlocks(x) => x.is_empty(),
177 Self::GetBlocksByHeight(x) => x.is_empty(),
178 Self::GetHashes(x) => x.is_empty(),
179 Self::GetOutputIndexes(x) => x.is_empty(),
180 Self::GetOuts(x) => x.is_empty(),
181 Self::GetTransactionPoolHashes(x) => x.is_empty(),
182 Self::GetOutputDistribution(x) => x.is_empty(),
183 }
184 }
185}
186
187#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
194#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
195#[cfg_attr(feature = "serde", serde(untagged))]
196pub enum BinResponse {
197 GetBlocks(GetBlocksResponse),
198 GetBlocksByHeight(GetBlocksByHeightResponse),
199 GetHashes(GetHashesResponse),
200 GetOutputIndexes(GetOutputIndexesResponse),
201 GetOuts(GetOutsResponse),
202 GetTransactionPoolHashes(GetTransactionPoolHashesResponse),
203 GetOutputDistribution(crate::json::GetOutputDistributionResponse),
204}
205
206#[cfg(test)]
208mod test {
209 }