cuprate_rpc_types/
bin.rs

1//! Binary types from [`.bin` endpoints](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_blocksbin).
2//!
3//! All types are originally defined in [`rpc/core_rpc_server_commands_defs.h`](https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server_commands_defs.h).
4
5//---------------------------------------------------------------------------------------------------- Import
6use 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::BlockCompleteEntry;
15
16use crate::{
17    base::AccessResponseBase,
18    macros::define_request_and_response,
19    misc::{BlockOutputIndices, GetOutputsOut, OutKeyBin, PoolInfo},
20    rpc_call::RpcCallValue,
21};
22
23#[cfg(any(feature = "epee", feature = "serde"))]
24use crate::defaults::{default_false, default_zero};
25
26//---------------------------------------------------------------------------------------------------- Definitions
27define_request_and_response! {
28    get_blocks_by_heightbin,
29    cc73fe71162d564ffda8e549b79a350bca53c454 =>
30    core_rpc_server_commands_defs.h => 264..=286,
31    GetBlocksByHeight,
32    Request {
33        heights: Vec<u64>,
34    },
35    AccessResponseBase {
36        blocks: Vec<BlockCompleteEntry>,
37    }
38}
39
40define_request_and_response! {
41    get_hashesbin,
42    cc73fe71162d564ffda8e549b79a350bca53c454 =>
43    core_rpc_server_commands_defs.h => 309..=338,
44    GetHashes,
45    Request {
46        block_ids: ByteArrayVec<32>,
47        start_height: u64,
48    },
49    AccessResponseBase {
50        m_blocks_ids: ByteArrayVec<32>,
51        start_height: u64,
52        current_height: u64,
53    }
54}
55
56#[cfg(not(feature = "epee"))]
57define_request_and_response! {
58    get_o_indexesbin,
59    cc73fe71162d564ffda8e549b79a350bca53c454 =>
60    core_rpc_server_commands_defs.h => 487..=510,
61    GetOutputIndexes,
62    #[derive(Copy)]
63    Request {
64        txid: [u8; 32],
65    },
66    AccessResponseBase {
67        o_indexes: Vec<u64>,
68    }
69}
70
71#[cfg(feature = "epee")]
72define_request_and_response! {
73    get_o_indexesbin,
74    cc73fe71162d564ffda8e549b79a350bca53c454 =>
75    core_rpc_server_commands_defs.h => 487..=510,
76    GetOutputIndexes,
77    #[derive(Copy)]
78    Request {
79        txid: [u8; 32],
80    },
81    AccessResponseBase {
82        o_indexes: Vec<u64> as ContainerAsBlob<u64>,
83    }
84}
85
86define_request_and_response! {
87    get_outsbin,
88    cc73fe71162d564ffda8e549b79a350bca53c454 =>
89    core_rpc_server_commands_defs.h => 512..=565,
90    GetOuts,
91    Request {
92        outputs: Vec<GetOutputsOut>,
93        get_txid: bool = default_false(), "default_false",
94    },
95    AccessResponseBase {
96        outs: Vec<OutKeyBin>,
97    }
98}
99
100define_request_and_response! {
101    get_transaction_pool_hashesbin,
102    cc73fe71162d564ffda8e549b79a350bca53c454 =>
103    core_rpc_server_commands_defs.h => 1593..=1613,
104    GetTransactionPoolHashes,
105    Request {},
106    AccessResponseBase {
107        tx_hashes: ByteArrayVec<32>,
108    }
109}
110
111define_request_and_response! {
112    get_blocksbin,
113    cc73fe71162d564ffda8e549b79a350bca53c454 =>
114    core_rpc_server_commands_defs.h => 162..=262,
115
116    GetBlocks,
117
118    Request {
119        requested_info: u8 = default_zero::<u8>(), "default_zero",
120        // FIXME: This is a `std::list` in `monerod` because...?
121        block_ids: ByteArrayVec<32>,
122        start_height: u64,
123        prune: bool,
124        no_miner_tx: bool = default_false(), "default_false",
125        pool_info_since: u64 = default_zero::<u64>(), "default_zero",
126    },
127
128    // TODO: add `top_block_hash` field
129    // <https://github.com/monero-project/monero/blame/893916ad091a92e765ce3241b94e706ad012b62a/src/rpc/core_rpc_server_commands_defs.h#L263>
130    AccessResponseBase {
131        blocks: Vec<BlockCompleteEntry>,
132        start_height: u64,
133        current_height: u64,
134        output_indices: Vec<BlockOutputIndices>,
135        daemon_time: u64 = default_zero::<u64>(), "default_zero",
136        // FIXME: use `default()` after <https://github.com/Cuprate/cuprate/pull/355>
137        pool_info: PoolInfo = PoolInfo::None, "PoolInfo::default",
138    }
139}
140
141//---------------------------------------------------------------------------------------------------- Request
142/// Binary requests.
143///
144/// This enum contains all [`crate::bin`] requests.
145///
146/// See also: [`BinResponse`].
147#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
148#[cfg_attr(feature = "serde", serde(untagged))]
149#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
150pub enum BinRequest {
151    GetBlocks(GetBlocksRequest),
152    GetBlocksByHeight(GetBlocksByHeightRequest),
153    GetHashes(GetHashesRequest),
154    GetOutputIndexes(GetOutputIndexesRequest),
155    GetOuts(GetOutsRequest),
156    GetTransactionPoolHashes(GetTransactionPoolHashesRequest),
157    GetOutputDistribution(crate::json::GetOutputDistributionRequest),
158}
159
160impl RpcCallValue for BinRequest {
161    fn is_restricted(&self) -> bool {
162        match self {
163            Self::GetBlocks(x) => x.is_restricted(),
164            Self::GetBlocksByHeight(x) => x.is_restricted(),
165            Self::GetHashes(x) => x.is_restricted(),
166            Self::GetOutputIndexes(x) => x.is_restricted(),
167            Self::GetOuts(x) => x.is_restricted(),
168            Self::GetTransactionPoolHashes(x) => x.is_restricted(),
169            Self::GetOutputDistribution(x) => x.is_restricted(),
170        }
171    }
172
173    fn is_empty(&self) -> bool {
174        match self {
175            Self::GetBlocks(x) => x.is_empty(),
176            Self::GetBlocksByHeight(x) => x.is_empty(),
177            Self::GetHashes(x) => x.is_empty(),
178            Self::GetOutputIndexes(x) => x.is_empty(),
179            Self::GetOuts(x) => x.is_empty(),
180            Self::GetTransactionPoolHashes(x) => x.is_empty(),
181            Self::GetOutputDistribution(x) => x.is_empty(),
182        }
183    }
184}
185
186//---------------------------------------------------------------------------------------------------- Response
187/// Binary responses.
188///
189/// This enum contains all [`crate::bin`] responses.
190///
191/// See also: [`BinRequest`].
192#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
193#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
194#[cfg_attr(feature = "serde", serde(untagged))]
195pub enum BinResponse {
196    GetBlocks(GetBlocksResponse),
197    GetBlocksByHeight(GetBlocksByHeightResponse),
198    GetHashes(GetHashesResponse),
199    GetOutputIndexes(GetOutputIndexesResponse),
200    GetOuts(GetOutsResponse),
201    GetTransactionPoolHashes(GetTransactionPoolHashesResponse),
202    GetOutputDistribution(crate::json::GetOutputDistributionResponse),
203}
204
205//---------------------------------------------------------------------------------------------------- Tests
206#[cfg(test)]
207mod test {
208    // use super::*;
209}