cuprate_rpc_types/misc/
misc.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
8#[cfg(feature = "serde")]
9use serde::{Deserialize, Serialize};
10
11#[cfg(feature = "epee")]
12use cuprate_epee_encoding::epee_object;
13
14#[cfg(any(feature = "epee", feature = "serde"))]
15use crate::defaults::default_zero;
16
17use crate::macros::monero_definition_link;
18
19//---------------------------------------------------------------------------------------------------- Macros
20/// This macro (local to this file) defines all the misc types.
21///
22/// This macro:
23/// 1. Defines a `pub struct` with all `pub` fields
24/// 2. Implements `serde` on the struct
25/// 3. Implements `epee` on the struct
26///
27/// When using, consider documenting:
28/// - The original Monero definition site with [`monero_definition_link`]
29/// - The request/responses where the `struct` is used
30macro_rules! define_struct_and_impl_epee {
31    (
32        // Optional `struct` attributes.
33        $( #[$struct_attr:meta] )*
34        // The `struct`'s name.
35        $struct_name:ident {
36            // And any fields.
37            $(
38                $( #[$field_attr:meta] )* // Field attributes
39                // Field name => the type => optional `epee_object` default value.
40                $field_name:ident: $field_type:ty $(= $field_default:expr_2021)?,
41            )*
42        }
43    ) => {
44        #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
45        #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
46        $( #[$struct_attr] )*
47        pub struct $struct_name {
48            $(
49                $( #[$field_attr] )*
50                pub $field_name: $field_type,
51            )*
52        }
53
54        #[cfg(feature = "epee")]
55        epee_object! {
56            $struct_name,
57            $(
58                $field_name: $field_type $(= $field_default)?,
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: String,
87        height: u64,
88        long_term_weight: u64,
89        major_version: u8,
90        miner_tx_hash: String,
91        minor_version: u8,
92        nonce: u32,
93        num_txes: u64,
94        orphan_status: bool,
95        pow_hash: String,
96        prev_hash: String,
97        reward: u64,
98        timestamp: u64,
99        wide_cumulative_difficulty: String,
100        wide_difficulty: String,
101    }
102}
103
104define_struct_and_impl_epee! {
105    #[doc = monero_definition_link!(
106        cc73fe71162d564ffda8e549b79a350bca53c454,
107        "cryptonote_protocol/cryptonote_protocol_defs.h",
108        47..=116
109    )]
110    /// Used in [`crate::json::GetConnectionsResponse`].
111    ConnectionInfo {
112        address: String,
113        address_type: cuprate_types::AddressType,
114        avg_download: u64,
115        avg_upload: u64,
116        connection_id: String,
117        current_download: u64,
118        current_upload: u64,
119        height: u64,
120        host: String,
121        incoming: bool,
122        ip: String,
123        live_time: u64,
124        localhost: bool,
125        local_ip: bool,
126        peer_id: String,
127        port: String,
128        pruning_seed: u32,
129        recv_count: u64,
130        recv_idle_time: u64,
131        rpc_credits_per_hash: u32,
132        rpc_port: u16,
133        send_count: u64,
134        send_idle_time: u64,
135        // Exists in the original definition, but isn't
136        // used or (de)serialized for RPC purposes.
137        // ssl: bool,
138        state: cuprate_types::ConnectionState,
139        support_flags: u32,
140    }
141}
142
143define_struct_and_impl_epee! {
144    #[doc = monero_definition_link!(
145        cc73fe71162d564ffda8e549b79a350bca53c454,
146        "rpc/core_rpc_server_commands_defs.h",
147        2034..=2047
148    )]
149    /// Used in [`crate::json::SetBansRequest`].
150    SetBan {
151        #[cfg_attr(feature = "serde", serde(default = "crate::defaults::default_string"))]
152        host: String,
153        #[cfg_attr(feature = "serde", serde(default = "default_zero"))]
154        ip: u32,
155        ban: bool,
156        seconds: u32,
157    }
158}
159
160define_struct_and_impl_epee! {
161    #[doc = monero_definition_link!(
162        cc73fe71162d564ffda8e549b79a350bca53c454,
163        "rpc/core_rpc_server_commands_defs.h",
164        1999..=2010
165    )]
166    /// Used in [`crate::json::GetBansResponse`].
167    GetBan {
168        host: String,
169        ip: u32,
170        seconds: u32,
171    }
172}
173
174define_struct_and_impl_epee! {
175    #[doc = monero_definition_link!(
176        cc73fe71162d564ffda8e549b79a350bca53c454,
177        "rpc/core_rpc_server_commands_defs.h",
178        2139..=2156
179    )]
180    #[derive(Copy)]
181    /// Used in [`crate::json::GetOutputHistogramResponse`].
182    HistogramEntry {
183        amount: u64,
184        total_instances: u64,
185        unlocked_instances: u64,
186        recent_instances: u64,
187    }
188}
189
190define_struct_and_impl_epee! {
191    #[doc = monero_definition_link!(
192        cc73fe71162d564ffda8e549b79a350bca53c454,
193        "rpc/core_rpc_server_commands_defs.h",
194        2180..=2191
195    )]
196    #[derive(Copy)]
197    /// Used in [`crate::json::GetVersionResponse`].
198    HardforkEntry {
199        height: u64,
200        hf_version: u8,
201    }
202}
203
204define_struct_and_impl_epee! {
205    #[doc = monero_definition_link!(
206        cc73fe71162d564ffda8e549b79a350bca53c454,
207        "rpc/core_rpc_server_commands_defs.h",
208        2289..=2310
209    )]
210    /// Used in [`crate::json::GetAlternateChainsResponse`].
211    ChainInfo {
212        block_hash: String,
213        block_hashes: Vec<String>,
214        difficulty: u64,
215        difficulty_top64: u64,
216        height: u64,
217        length: u64,
218        main_chain_parent_block: String,
219        wide_difficulty: String,
220    }
221}
222
223define_struct_and_impl_epee! {
224    #[doc = monero_definition_link!(
225        cc73fe71162d564ffda8e549b79a350bca53c454,
226        "rpc/core_rpc_server_commands_defs.h",
227        2393..=2400
228    )]
229    /// Used in [`crate::json::SyncInfoResponse`].
230    SyncInfoPeer {
231        info: ConnectionInfo,
232    }
233}
234
235define_struct_and_impl_epee! {
236    #[doc = monero_definition_link!(
237        cc73fe71162d564ffda8e549b79a350bca53c454,
238        "rpc/core_rpc_server_commands_defs.h",
239        2402..=2421
240    )]
241    /// Used in [`crate::json::SyncInfoResponse`].
242    Span {
243        connection_id: String,
244        nblocks: u64,
245        rate: u32,
246        remote_address: String,
247        size: u64,
248        speed: u32,
249        start_block_height: u64,
250    }
251}
252
253define_struct_and_impl_epee! {
254    #[doc = monero_definition_link!(
255        cc73fe71162d564ffda8e549b79a350bca53c454,
256        "rpc/core_rpc_server_commands_defs.h",
257        1637..=1642
258    )]
259    #[derive(Copy)]
260    /// Used in [`crate::json::GetTransactionPoolBacklogResponse`].
261    TxBacklogEntry {
262        weight: u64,
263        fee: u64,
264        time_in_pool: u64,
265    }
266}
267
268define_struct_and_impl_epee! {
269    #[doc = monero_definition_link!(
270        cc73fe71162d564ffda8e549b79a350bca53c454,
271        "rpc/rpc_handler.h",
272        45..=50
273    )]
274    /// Used in [`crate::json::GetOutputDistributionResponse`].
275    OutputDistributionData {
276        distribution: Vec<u64>,
277        start_height: u64,
278        base: u64,
279    }
280}
281
282define_struct_and_impl_epee! {
283    #[doc = monero_definition_link!(
284        cc73fe71162d564ffda8e549b79a350bca53c454,
285        "rpc/core_rpc_server_commands_defs.h",
286        1016..=1027
287    )]
288    /// Used in [`crate::json::GetMinerDataResponse`].
289    ///
290    /// Note that this is different than [`crate::misc::TxBacklogEntry`].
291    GetMinerDataTxBacklogEntry {
292        id: String,
293        weight: u64,
294        fee: u64,
295    }
296}
297
298define_struct_and_impl_epee! {
299    #[doc = monero_definition_link!(
300        cc73fe71162d564ffda8e549b79a350bca53c454,
301        "rpc/core_rpc_server_commands_defs.h",
302        1070..=1079
303    )]
304    /// Used in [`crate::json::AddAuxPowRequest`].
305    AuxPow {
306        id: String,
307        hash: String,
308    }
309}
310
311define_struct_and_impl_epee! {
312    #[doc = monero_definition_link!(
313        cc73fe71162d564ffda8e549b79a350bca53c454,
314        "rpc/core_rpc_server_commands_defs.h",
315        192..=199
316    )]
317    /// Used in [`crate::bin::GetBlocksResponse`].
318    TxOutputIndices {
319        indices: Vec<u64>,
320    }
321}
322
323define_struct_and_impl_epee! {
324    #[doc = monero_definition_link!(
325        cc73fe71162d564ffda8e549b79a350bca53c454,
326        "rpc/core_rpc_server_commands_defs.h",
327        201..=208
328    )]
329    /// Used in [`crate::bin::GetBlocksResponse`].
330    BlockOutputIndices {
331        indices: Vec<TxOutputIndices>,
332    }
333}
334
335define_struct_and_impl_epee! {
336    #[doc = monero_definition_link!(
337        cc73fe71162d564ffda8e549b79a350bca53c454,
338        "rpc/core_rpc_server_commands_defs.h",
339        210..=221
340    )]
341    /// Used in [`crate::bin::GetBlocksResponse`].
342    PoolTxInfo {
343        tx_hash: [u8; 32],
344        tx_blob: String,
345        double_spend_seen: bool,
346    }
347}
348
349define_struct_and_impl_epee! {
350    #[doc = monero_definition_link!(
351        cc73fe71162d564ffda8e549b79a350bca53c454,
352        "rpc/core_rpc_server_commands_defs.h",
353        512..=521
354    )]
355    #[derive(Copy)]
356    ///
357    /// Used in:
358    /// - [`crate::bin::GetOutsRequest`]
359    /// - [`crate::other::GetOutsRequest`]
360    GetOutputsOut {
361        amount: u64,
362        index: u64,
363    }
364}
365
366define_struct_and_impl_epee! {
367    #[doc = monero_definition_link!(
368        cc73fe71162d564ffda8e549b79a350bca53c454,
369        "rpc/core_rpc_server_commands_defs.h",
370        538..=553
371    )]
372    #[derive(Copy)]
373    /// Used in [`crate::bin::GetOutsRequest`].
374    OutKeyBin {
375        key: [u8; 32],
376        mask: [u8; 32],
377        unlocked: bool,
378        height: u64,
379        txid: [u8; 32],
380    }
381}
382
383define_struct_and_impl_epee! {
384    #[doc = monero_definition_link!(
385        cc73fe71162d564ffda8e549b79a350bca53c454,
386        "rpc/core_rpc_server_commands_defs.h",
387        1335..=1367
388    )]
389    /// Used in [`crate::other::GetPeerListResponse`].
390    Peer {
391        id: u64,
392        host: String,
393        ip: u32,
394        port: u16,
395        #[cfg_attr(feature = "serde", serde(default = "default_zero"))]
396        rpc_port: u16 = default_zero::<u16>(),
397        #[cfg_attr(feature = "serde", serde(default = "default_zero"))]
398        rpc_credits_per_hash: u32 = default_zero::<u32>(),
399        last_seen: u64,
400        #[cfg_attr(feature = "serde", serde(default = "default_zero"))]
401        pruning_seed: u32 = default_zero::<u32>(),
402    }
403}
404
405define_struct_and_impl_epee! {
406    #[doc = monero_definition_link!(
407        cc73fe71162d564ffda8e549b79a350bca53c454,
408        "rpc/core_rpc_server_commands_defs.h",
409        1398..=1417
410    )]
411    ///
412    /// Used in:
413    /// - [`crate::other::GetPeerListResponse`]
414    /// - [`crate::other::GetPublicNodesResponse`]
415    PublicNode {
416        host: String,
417        last_seen: u64,
418        rpc_port: u16,
419        rpc_credits_per_hash: u32,
420    }
421}
422
423define_struct_and_impl_epee! {
424    #[doc = monero_definition_link!(
425        cc73fe71162d564ffda8e549b79a350bca53c454,
426        "rpc/core_rpc_server_commands_defs.h",
427        1519..=1556
428    )]
429    /// Used in [`crate::other::GetTransactionPoolResponse`].
430    TxInfo {
431        blob_size: u64,
432        do_not_relay: bool,
433        double_spend_seen: bool,
434        fee: u64,
435        id_hash: String,
436        kept_by_block: bool,
437        last_failed_height: u64,
438        last_failed_id_hash: String,
439        last_relayed_time: u64,
440        max_used_block_height: u64,
441        max_used_block_id_hash: String,
442        receive_time: u64,
443        relayed: bool,
444        tx_blob: String,
445        tx_json: String, // TODO: this should be another struct
446        #[cfg_attr(feature = "serde", serde(default = "default_zero"))]
447        weight: u64 = default_zero::<u64>(),
448    }
449}
450
451define_struct_and_impl_epee! {
452    #[doc = monero_definition_link!(
453        cc73fe71162d564ffda8e549b79a350bca53c454,
454        "rpc/core_rpc_server_commands_defs.h",
455        1558..=1567
456    )]
457    /// Used in [`crate::other::GetTransactionPoolResponse`].
458    SpentKeyImageInfo {
459        id_hash: String,
460        txs_hashes: Vec<String>,
461    }
462}
463
464define_struct_and_impl_epee! {
465    #[doc = monero_definition_link!(
466        cc73fe71162d564ffda8e549b79a350bca53c454,
467        "rpc/core_rpc_server_commands_defs.h",
468        1666..=1675
469    )]
470    #[derive(Copy)]
471    /// Used in [`crate::other::GetTransactionPoolStatsResponse`].
472    TxpoolHisto {
473        txs: u32,
474        bytes: u64,
475    }
476}
477
478define_struct_and_impl_epee! {
479    #[doc = monero_definition_link!(
480        cc73fe71162d564ffda8e549b79a350bca53c454,
481        "rpc/core_rpc_server_commands_defs.h",
482        1677..=1710
483    )]
484    /// Used in [`crate::other::GetTransactionPoolStatsResponse`].
485    TxpoolStats {
486        bytes_max: u32,
487        bytes_med: u32,
488        bytes_min: u32,
489        bytes_total: u64,
490        fee_total: u64,
491        histo_98pc: u64,
492        histo: Vec<TxpoolHisto>,
493        num_10m: u32,
494        num_double_spends: u32,
495        num_failing: u32,
496        num_not_relayed: u32,
497        oldest: u64,
498        txs_total: u32,
499    }
500}
501
502define_struct_and_impl_epee! {
503    #[doc = monero_definition_link!(
504        cc73fe71162d564ffda8e549b79a350bca53c454,
505        "rpc/core_rpc_server_commands_defs.h",
506        582..=597
507    )]
508    /// Used in [`crate::other::GetOutsResponse`].
509    OutKey {
510        key: String,
511        mask: String,
512        unlocked: bool,
513        height: u64,
514        txid: String,
515    }
516}
517
518//---------------------------------------------------------------------------------------------------- Tests
519#[cfg(test)]
520mod test {}