Skip to main content

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
11use cuprate_types::{
12    rpc::{BlockOutputIndices, PoolInfoExtent, PoolTxInfo},
13    BlockCompleteEntry,
14};
15
16use crate::{
17    base::AccessResponseBase,
18    macros::define_request_and_response,
19    misc::{GetOutputsOut, OutKeyBin},
20    rpc_call::RpcCallValue,
21};
22
23#[cfg(any(feature = "epee", feature = "serde"))]
24use crate::defaults::{default, default_true};
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> = default::<Vec<BlockCompleteEntry>>(), "default",
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> = default::<ByteArrayVec<32>>(), "default",
47        start_height: u64,
48    },
49    AccessResponseBase {
50        m_block_ids: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
51        start_height: u64,
52        current_height: u64,
53    }
54}
55
56define_request_and_response! {
57    get_o_indexesbin,
58    "cc73fe71162d564ffda8e549b79a350bca53c454" =>
59    core_rpc_server_commands_defs.h => 487..=510,
60    GetOutputIndexes,
61    #[derive(Copy)]
62    Request {
63        txid: [u8; 32],
64    },
65    AccessResponseBase {
66        o_indexes: Vec<u64> = default::<Vec<u64>>(), "default",
67    }
68}
69
70define_request_and_response! {
71    get_outsbin,
72    "cc73fe71162d564ffda8e549b79a350bca53c454" =>
73    core_rpc_server_commands_defs.h => 512..=565,
74    GetOuts,
75    Request {
76        outputs: Vec<GetOutputsOut> = default::<Vec<GetOutputsOut>>(), "default",
77        get_txid: bool = default_true(), "default_true",
78    },
79    AccessResponseBase {
80        outs: Vec<OutKeyBin> = default::<Vec<OutKeyBin>>(), "default",
81    }
82}
83
84define_request_and_response! {
85    get_transaction_pool_hashesbin,
86    "cc73fe71162d564ffda8e549b79a350bca53c454" =>
87    core_rpc_server_commands_defs.h => 1593..=1613,
88    GetTransactionPoolHashes,
89    Request {},
90    AccessResponseBase {
91        tx_hashes: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
92    }
93}
94
95define_request_and_response! {
96    get_blocksbin,
97    "cc73fe71162d564ffda8e549b79a350bca53c454" =>
98    core_rpc_server_commands_defs.h => 162..=262,
99
100    GetBlocks,
101
102    Request {
103        requested_info: u8 = default::<u8>(), "default",
104        block_ids: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
105        start_height: u64 = default::<u64>(), "default",
106        prune: bool = default::<bool>(), "default",
107        no_miner_tx: bool = default::<bool>(), "default",
108        pool_info_since: u64 = default::<u64>(), "default",
109        max_block_count: u64 = default::<u64>(), "default",
110    },
111
112    AccessResponseBase {
113        blocks: Vec<BlockCompleteEntry> = default::<Vec<BlockCompleteEntry>>(), "default",
114        start_height: u64,
115        current_height: u64,
116        top_block_hash: [u8; 32] = default::<[u8; 32]>(), "default",
117        output_indices: Vec<BlockOutputIndices> = default::<Vec<BlockOutputIndices>>(), "default",
118        daemon_time: u64 = default::<u64>(), "default",
119        pool_info_extent: PoolInfoExtent = default::<PoolInfoExtent>(), "default",
120        added_pool_txs: Vec<PoolTxInfo>,
121        remaining_added_pool_txids: ByteArrayVec<32>,
122        removed_pool_txids: ByteArrayVec<32>,
123    }
124}
125
126//---------------------------------------------------------------------------------------------------- Request
127/// Binary requests.
128///
129/// This enum contains all [`crate::bin`] requests.
130///
131/// See also: [`BinResponse`].
132#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
133#[cfg_attr(feature = "serde", serde(untagged))]
134#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
135pub enum BinRequest {
136    GetBlocks(GetBlocksRequest),
137    GetBlocksByHeight(GetBlocksByHeightRequest),
138    GetHashes(GetHashesRequest),
139    GetOutputIndexes(GetOutputIndexesRequest),
140    GetOuts(GetOutsRequest),
141    GetTransactionPoolHashes(GetTransactionPoolHashesRequest),
142    GetOutputDistribution(crate::json::GetOutputDistributionRequest),
143}
144
145impl RpcCallValue for BinRequest {
146    fn is_restricted(&self) -> bool {
147        match self {
148            Self::GetBlocks(x) => x.is_restricted(),
149            Self::GetBlocksByHeight(x) => x.is_restricted(),
150            Self::GetHashes(x) => x.is_restricted(),
151            Self::GetOutputIndexes(x) => x.is_restricted(),
152            Self::GetOuts(x) => x.is_restricted(),
153            Self::GetTransactionPoolHashes(x) => x.is_restricted(),
154            Self::GetOutputDistribution(x) => x.is_restricted(),
155        }
156    }
157
158    fn is_empty(&self) -> bool {
159        match self {
160            Self::GetBlocks(x) => x.is_empty(),
161            Self::GetBlocksByHeight(x) => x.is_empty(),
162            Self::GetHashes(x) => x.is_empty(),
163            Self::GetOutputIndexes(x) => x.is_empty(),
164            Self::GetOuts(x) => x.is_empty(),
165            Self::GetTransactionPoolHashes(x) => x.is_empty(),
166            Self::GetOutputDistribution(x) => x.is_empty(),
167        }
168    }
169}
170
171//---------------------------------------------------------------------------------------------------- Response
172/// Binary responses.
173///
174/// This enum contains all [`crate::bin`] responses.
175///
176/// See also: [`BinRequest`].
177#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
178#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
179#[cfg_attr(feature = "serde", serde(untagged))]
180pub enum BinResponse {
181    GetBlocks(GetBlocksResponse),
182    GetBlocksByHeight(GetBlocksByHeightResponse),
183    GetHashes(GetHashesResponse),
184    GetOutputIndexes(GetOutputIndexesResponse),
185    GetOuts(GetOutsResponse),
186    GetTransactionPoolHashes(GetTransactionPoolHashesResponse),
187    GetOutputDistribution(crate::json::GetOutputDistributionResponse),
188}
189
190//---------------------------------------------------------------------------------------------------- Tests
191#[cfg(test)]
192mod test {
193    // use super::*;
194}