cuprate_rpc_types/misc/
types.rs

1//! Miscellaneous types.
2//!
3//! These are `struct`s that appear in request/response types.
4//! For example, [`crate::json::GetConnectionsResponse`] contains
5//! the [`crate::misc::ConnectionInfo`] struct defined here.
6
7//---------------------------------------------------------------------------------------------------- Import
8use cuprate_hex::{Hex, HexVec};
9use cuprate_types::HardFork;
10
11#[cfg(any(feature = "epee", feature = "serde"))]
12use crate::defaults::default;
13
14use crate::macros::monero_definition_link;
15
16//---------------------------------------------------------------------------------------------------- Macros
17/// This macro (local to this file) defines all the misc types.
18///
19/// This macro:
20/// 1. Defines a `pub struct` with all `pub` fields
21/// 2. Implements `serde` on the struct
22/// 3. Implements `epee` on the struct
23///
24/// When using, consider documenting:
25/// - The original Monero definition site with [`monero_definition_link`]
26/// - The request/responses where the `struct` is used
27macro_rules! define_struct_and_impl_epee {
28    ($(
29        // Optional `struct` attributes.
30        $( #[$struct_attr:meta] )*
31        // The `struct`'s name.
32        $struct_name:ident {
33            // And any fields.
34            $(
35                $( #[$field_attr:meta] )* // Field attributes
36                // Field name => the type => optional `epee_object` default value.
37                $field_name:ident: $field_type:ty $(= $field_default:expr_2021)?,
38            )*
39        }
40    )*) => {
41        $(
42            #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
43            #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44            #[cfg_attr(feature = "serde", serde(default))]
45            $( #[$struct_attr] )*
46            pub struct $struct_name {
47                $(
48                    $( #[$field_attr] )*
49                    pub $field_name: $field_type,
50                )*
51            }
52
53            #[cfg(feature = "epee")]
54            cuprate_epee_encoding::epee_object! {
55                $struct_name,
56                $(
57                    $field_name: $field_type $(= $field_default)?,
58                )*
59            }
60        )*
61    };
62}
63
64//---------------------------------------------------------------------------------------------------- Type Definitions
65define_struct_and_impl_epee! {
66    #[doc = monero_definition_link!(
67        "cc73fe71162d564ffda8e549b79a350bca53c454",
68        "rpc/core_rpc_server_commands_defs.h",
69        1163..=1212
70    )]
71    ///
72    /// Used in:
73    /// - [`crate::json::GetLastBlockHeaderResponse`]
74    /// - [`crate::json::GetBlockHeaderByHashResponse`]
75    /// - [`crate::json::GetBlockHeaderByHeightResponse`]
76    /// - [`crate::json::GetBlockHeadersRangeResponse`]
77    /// - [`crate::json::GetBlockResponse`]
78    BlockHeader {
79        block_size: u64,
80        block_weight: u64,
81        cumulative_difficulty_top64: u64,
82        cumulative_difficulty: u64,
83        depth: u64,
84        difficulty_top64: u64,
85        difficulty: u64,
86        hash: Hex<32>,
87        height: u64,
88        long_term_weight: u64,
89        major_version: HardFork,
90        miner_tx_hash: Hex<32>,
91        minor_version: u8,
92        nonce: u32,
93        num_txes: u64,
94        orphan_status: bool,
95        /// This is a [`Hex<32>`] that is sometimes empty.
96        pow_hash: HexVec,
97        prev_hash: Hex<32>,
98        reward: u64,
99        timestamp: u64,
100        wide_cumulative_difficulty: String,
101        wide_difficulty: String,
102    }
103}
104
105define_struct_and_impl_epee! {
106    #[doc = monero_definition_link!(
107        "cc73fe71162d564ffda8e549b79a350bca53c454",
108        "cryptonote_protocol/cryptonote_protocol_defs.h",
109        47..=116
110    )]
111    /// Used in [`crate::json::GetConnectionsResponse`].
112    ConnectionInfo {
113        address: String,
114        address_type: cuprate_types::AddressType,
115        avg_download: u64,
116        avg_upload: u64,
117        connection_id: String,
118        current_download: u64,
119        current_upload: u64,
120        height: u64,
121        host: String,
122        incoming: bool,
123        ip: String,
124        live_time: u64,
125        localhost: bool,
126        local_ip: bool,
127        peer_id: String,
128        port: String,
129        pruning_seed: u32,
130        recv_count: u64,
131        recv_idle_time: u64,
132        rpc_credits_per_hash: u32,
133        rpc_port: u16,
134        send_count: u64,
135        send_idle_time: u64,
136        // Exists in the original definition, but isn't
137        // used or (de)serialized for RPC purposes.
138        // ssl: bool,
139        state: cuprate_types::ConnectionState,
140        support_flags: u32,
141    }
142}
143
144define_struct_and_impl_epee! {
145    #[doc = monero_definition_link!(
146        "cc73fe71162d564ffda8e549b79a350bca53c454",
147        "rpc/core_rpc_server_commands_defs.h",
148        2034..=2047
149    )]
150    /// Used in [`crate::json::SetBansRequest`].
151    SetBan {
152        host: String,
153        ip: u32,
154        ban: bool,
155        seconds: u32,
156    }
157}
158
159define_struct_and_impl_epee! {
160    #[doc = monero_definition_link!(
161        "cc73fe71162d564ffda8e549b79a350bca53c454",
162        "rpc/core_rpc_server_commands_defs.h",
163        1999..=2010
164    )]
165    /// Used in [`crate::json::GetBansResponse`].
166    GetBan {
167        host: String,
168        ip: u32,
169        seconds: u32,
170    }
171}
172
173define_struct_and_impl_epee! {
174    #[doc = monero_definition_link!(
175        "cc73fe71162d564ffda8e549b79a350bca53c454",
176        "rpc/core_rpc_server_commands_defs.h",
177        2139..=2156
178    )]
179    #[derive(Copy)]
180    /// Used in [`crate::json::GetOutputHistogramResponse`].
181    HistogramEntry {
182        amount: u64,
183        total_instances: u64,
184        unlocked_instances: u64,
185        recent_instances: u64,
186    }
187}
188
189define_struct_and_impl_epee! {
190    #[doc = monero_definition_link!(
191        "cc73fe71162d564ffda8e549b79a350bca53c454",
192        "rpc/core_rpc_server_commands_defs.h",
193        2289..=2310
194    )]
195    /// Used in [`crate::json::GetAlternateChainsResponse`].
196    ChainInfo {
197        block_hash: Hex<32>,
198        block_hashes: Vec<Hex<32>>,
199        difficulty: u64,
200        difficulty_top64: u64,
201        height: u64,
202        length: u64,
203        main_chain_parent_block: Hex<32>,
204        wide_difficulty: String,
205    }
206}
207
208define_struct_and_impl_epee! {
209    #[doc = monero_definition_link!(
210        "cc73fe71162d564ffda8e549b79a350bca53c454",
211        "rpc/core_rpc_server_commands_defs.h",
212        2393..=2400
213    )]
214    /// Used in [`crate::json::SyncInfoResponse`].
215    SyncInfoPeer {
216        info: ConnectionInfo,
217    }
218}
219
220define_struct_and_impl_epee! {
221    #[doc = monero_definition_link!(
222        "cc73fe71162d564ffda8e549b79a350bca53c454",
223        "rpc/core_rpc_server_commands_defs.h",
224        2402..=2421
225    )]
226    /// Used in [`crate::json::SyncInfoResponse`].
227    Span {
228        connection_id: String,
229        nblocks: u64,
230        rate: u32,
231        remote_address: String,
232        size: u64,
233        speed: u32,
234        start_block_height: u64,
235    }
236}
237
238define_struct_and_impl_epee! {
239    #[doc = monero_definition_link!(
240        "cc73fe71162d564ffda8e549b79a350bca53c454",
241        "rpc/core_rpc_server_commands_defs.h",
242        512..=521
243    )]
244    #[derive(Copy)]
245    ///
246    /// Used in:
247    /// - [`crate::bin::GetOutsRequest`]
248    /// - [`crate::other::GetOutsRequest`]
249    GetOutputsOut {
250        amount: u64,
251        index: u64,
252    }
253}
254
255define_struct_and_impl_epee! {
256    #[doc = monero_definition_link!(
257        "cc73fe71162d564ffda8e549b79a350bca53c454",
258        "rpc/core_rpc_server_commands_defs.h",
259        582..=597
260    )]
261    /// Used in [`crate::other::GetOutsRequest`].
262    OutKey {
263        key: Hex<32>,
264        mask: Hex<32>,
265        unlocked: bool,
266        height: u64,
267        /// This is a [`Hex<32>`] that is sometimes empty.
268        txid: HexVec,
269    }
270}
271
272define_struct_and_impl_epee! {
273    #[doc = monero_definition_link!(
274        "cc73fe71162d564ffda8e549b79a350bca53c454",
275        "rpc/core_rpc_server_commands_defs.h",
276        538..=553
277    )]
278    #[derive(Copy)]
279    /// Used in [`crate::bin::GetOutsRequest`].
280    OutKeyBin {
281        key: [u8; 32],
282        mask: [u8; 32],
283        unlocked: bool,
284        height: u64,
285        txid: [u8; 32],
286    }
287}
288
289define_struct_and_impl_epee! {
290    #[doc = monero_definition_link!(
291        "cc73fe71162d564ffda8e549b79a350bca53c454",
292        "rpc/core_rpc_server_commands_defs.h",
293        1519..=1556
294    )]
295    /// Used in [`crate::other::GetTransactionPoolResponse`].
296    TxInfo {
297        blob_size: u64,
298        do_not_relay: bool,
299        double_spend_seen: bool,
300        fee: u64,
301        id_hash: Hex<32>,
302        kept_by_block: bool,
303        last_failed_height: u64,
304        last_failed_id_hash: Hex<32>,
305        last_relayed_time: u64,
306        max_used_block_height: u64,
307        max_used_block_id_hash: Hex<32>,
308        receive_time: u64,
309        relayed: bool,
310        tx_blob: HexVec,
311        tx_json: cuprate_types::json::tx::Transaction,
312        weight: u64 = default::<u64>(),
313    }
314}
315
316define_struct_and_impl_epee! {
317    #[doc = monero_definition_link!(
318        "cc73fe71162d564ffda8e549b79a350bca53c454",
319        "rpc/core_rpc_server_commands_defs.h",
320        1558..=1567
321    )]
322    /// Used in [`crate::other::GetTransactionPoolResponse`].
323    SpentKeyImageInfo {
324        id_hash: Hex<32>,
325        txs_hashes: Vec<Hex<32>>,
326    }
327}
328
329//---------------------------------------------------------------------------------------------------- Tests
330#[cfg(test)]
331mod test {}