1use cuprate_fixed_bytes::ByteArrayVec;
4use cuprate_hex::Hex;
5
6use crate::{AddressType, ConnectionState, HardFork};
7
8#[cfg(feature = "serde")]
9const fn default_string() -> String {
10 String::new()
11}
12
13fn default_zero<T: From<u8>>() -> T {
14 T::from(0)
15}
16
17macro_rules! monero_definition_link {
19 (
20 $commit:literal, $file_path:literal, $start:literal$(..=$end:literal)? ) => {
24 concat!(
25 "[Definition](https://github.com/monero-project/monero/blob/",
26 $commit,
27 "/src/",
28 $file_path,
29 "#L",
30 stringify!($start),
31 $(
32 "-L",
33 stringify!($end),
34 )?
35 ")."
36 )
37 };
38}
39
40macro_rules! define_struct_and_impl_epee {
51 ($(
52 $( #[$struct_attr:meta] )*
54 $struct_name:ident {
56 $(
58 $( #[$field_attr:meta] )* $field_name:ident: $field_type:ty $(= $field_default:expr_2021)?,
61 )*
62 }
63 )*) => {
64 $(
65 #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
66 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67 $( #[$struct_attr] )*
68 pub struct $struct_name {
69 $(
70 $( #[$field_attr] )*
71 pub $field_name: $field_type,
72 )*
73 }
74
75 #[cfg(feature = "epee")]
76 cuprate_epee_encoding::epee_object! {
77 $struct_name,
78 $(
79 $field_name: $field_type $(= $field_default)?,
80 )*
81 }
82 )*
83 };
84}
85
86define_struct_and_impl_epee! {
87 #[doc = monero_definition_link!(
88 "cc73fe71162d564ffda8e549b79a350bca53c454",
89 "rpc/core_rpc_server_commands_defs.h",
90 1163..=1212
91 )]
92 BlockHeader {
93 block_weight: u64,
94 cumulative_difficulty_top64: u64,
95 cumulative_difficulty: u64,
96 depth: u64,
97 difficulty_top64: u64,
98 difficulty: u64,
99 hash: [u8; 32],
100 height: u64,
101 long_term_weight: u64,
102 major_version: HardFork,
103 miner_tx_hash: [u8; 32],
104 minor_version: u8,
105 nonce: u32,
106 num_txes: u64,
107 orphan_status: bool,
108 pow_hash: Option<[u8; 32]>,
110 prev_hash: [u8; 32],
111 reward: u64,
112 timestamp: u64,
113 }
114
115 #[doc = monero_definition_link!(
116 "cc73fe71162d564ffda8e549b79a350bca53c454",
117 "cryptonote_protocol/cryptonote_protocol_defs.h",
118 47..=116
119 )]
120 ConnectionInfo {
121 address: String,
122 address_type: AddressType,
123 avg_download: u64,
124 avg_upload: u64,
125 connection_id: String,
126 current_download: u64,
127 current_upload: u64,
128 height: u64,
129 host: String,
130 incoming: bool,
131 ip: String,
132 live_time: u64,
133 localhost: bool,
134 local_ip: bool,
135 peer_id: String,
136 port: String,
137 pruning_seed: u32,
138 recv_count: u64,
139 recv_idle_time: u64,
140 rpc_credits_per_hash: u32,
141 rpc_port: u16,
142 send_count: u64,
143 send_idle_time: u64,
144 state: ConnectionState,
148 support_flags: u32,
149 }
150
151 #[doc = monero_definition_link!(
152 "cc73fe71162d564ffda8e549b79a350bca53c454",
153 "rpc/core_rpc_server_commands_defs.h",
154 2034..=2047
155 )]
156 SetBan {
157 #[cfg_attr(feature = "serde", serde(default = "default_string"))]
158 host: String,
159 #[cfg_attr(feature = "serde", serde(default = "default_zero"))]
160 ip: u32,
161 ban: bool,
162 seconds: u32,
163 }
164
165 #[doc = monero_definition_link!(
166 "cc73fe71162d564ffda8e549b79a350bca53c454",
167 "rpc/core_rpc_server_commands_defs.h",
168 1999..=2010
169 )]
170 GetBan {
171 host: String,
172 ip: u32,
173 seconds: u32,
174 }
175
176 #[doc = monero_definition_link!(
177 "cc73fe71162d564ffda8e549b79a350bca53c454",
178 "rpc/core_rpc_server_commands_defs.h",
179 2139..=2156
180 )]
181 #[derive(Copy)]
182 HistogramEntry {
183 amount: u64,
184 total_instances: u64,
185 unlocked_instances: u64,
186 recent_instances: u64,
187 }
188
189 #[doc = monero_definition_link!(
190 "cc73fe71162d564ffda8e549b79a350bca53c454",
191 "rpc/core_rpc_server_commands_defs.h",
192 2180..=2191
193 )]
194 #[derive(Copy)]
195 HardForkEntry {
196 height: u64,
197 hf_version: HardFork,
198 }
199
200 #[doc = monero_definition_link!(
201 "cc73fe71162d564ffda8e549b79a350bca53c454",
202 "rpc/core_rpc_server_commands_defs.h",
203 2289..=2310
204 )]
205 ChainInfo {
206 block_hash: [u8; 32],
207 block_hashes: Vec<[u8; 32]>,
208 difficulty_top64: u64,
209 difficulty: u64,
210 height: u64,
211 length: u64,
212 main_chain_parent_block: [u8; 32],
213 }
214
215 #[doc = monero_definition_link!(
216 "cc73fe71162d564ffda8e549b79a350bca53c454",
217 "rpc/core_rpc_server_commands_defs.h",
218 2393..=2400
219 )]
220 SyncInfoPeer {
221 info: ConnectionInfo,
222 }
223
224 #[doc = monero_definition_link!(
225 "cc73fe71162d564ffda8e549b79a350bca53c454",
226 "rpc/core_rpc_server_commands_defs.h",
227 2402..=2421
228 )]
229 Span {
230 connection_id: String,
231 nblocks: u64,
232 rate: u32,
233 remote_address: String,
234 size: u64,
235 speed: u32,
236 start_block_height: u64,
237 }
238
239 #[doc = monero_definition_link!(
240 "cc73fe71162d564ffda8e549b79a350bca53c454",
241 "rpc/core_rpc_server_commands_defs.h",
242 1637..=1642
243 )]
244 #[derive(Copy)]
245 TxBacklogEntry {
246 weight: u64,
247 fee: u64,
248 time_in_pool: u64,
249 }
250
251 #[doc = monero_definition_link!(
252 "cc73fe71162d564ffda8e549b79a350bca53c454",
253 "rpc/rpc_handler.h",
254 45..=50
255 )]
256 OutputDistributionData {
257 amount: u64,
258 distribution: Vec<u64>,
259 start_height: u64,
260 base: u64,
261 }
262
263 #[doc = monero_definition_link!(
264 "cc73fe71162d564ffda8e549b79a350bca53c454",
265 "rpc/core_rpc_server_commands_defs.h",
266 1016..=1027
267 )]
268 GetMinerDataTxBacklogEntry {
269 id: Hex<32>,
270 weight: u64,
271 fee: u64,
272 }
273
274 #[doc = monero_definition_link!(
275 "cc73fe71162d564ffda8e549b79a350bca53c454",
276 "rpc/core_rpc_server_commands_defs.h",
277 1070..=1079
278 )]
279 AuxPow {
280 id: Hex<32>,
281 hash: Hex<32>,
282 }
283
284 #[doc = monero_definition_link!(
285 "cc73fe71162d564ffda8e549b79a350bca53c454",
286 "rpc/core_rpc_server_commands_defs.h",
287 192..=199
288 )]
289 TxOutputIndices {
290 indices: Vec<u64>,
291 }
292
293 #[doc = monero_definition_link!(
294 "cc73fe71162d564ffda8e549b79a350bca53c454",
295 "rpc/core_rpc_server_commands_defs.h",
296 201..=208
297 )]
298 BlockOutputIndices {
299 indices: Vec<TxOutputIndices>,
300 }
301
302 #[doc = monero_definition_link!(
303 "cc73fe71162d564ffda8e549b79a350bca53c454",
304 "rpc/core_rpc_server_commands_defs.h",
305 512..=521
306 )]
307 #[derive(Copy)]
308 GetOutputsOut {
309 amount: u64,
310 index: u64,
311 }
312
313 #[doc = monero_definition_link!(
314 "cc73fe71162d564ffda8e549b79a350bca53c454",
315 "rpc/core_rpc_server_commands_defs.h",
316 1335..=1367
317 )]
318 Peer {
319 id: u64,
320 host: String,
321 ip: u32,
322 port: u16,
323 #[cfg_attr(feature = "serde", serde(default = "default_zero"))]
324 rpc_port: u16 = default_zero::<u16>(),
325 #[cfg_attr(feature = "serde", serde(default = "default_zero"))]
326 rpc_credits_per_hash: u32 = default_zero::<u32>(),
327 last_seen: u64,
328 #[cfg_attr(feature = "serde", serde(default = "default_zero"))]
329 pruning_seed: u32 = default_zero::<u32>(),
330 }
331
332 #[doc = monero_definition_link!(
333 "cc73fe71162d564ffda8e549b79a350bca53c454",
334 "rpc/core_rpc_server_commands_defs.h",
335 1398..=1417
336 )]
337 PublicNode {
338 host: String,
339 last_seen: u64,
340 rpc_port: u16,
341 rpc_credits_per_hash: u32,
342 }
343
344 #[doc = monero_definition_link!(
345 "cc73fe71162d564ffda8e549b79a350bca53c454",
346 "rpc/core_rpc_server_commands_defs.h",
347 1519..=1556
348 )]
349 TxInfo {
350 blob_size: u64,
351 do_not_relay: bool,
352 double_spend_seen: bool,
353 fee: u64,
354 id_hash: [u8; 32],
355 kept_by_block: bool,
356 last_failed_height: u64,
357 last_failed_id_hash: [u8; 32],
358 last_relayed_time: u64,
359 max_used_block_height: u64,
360 max_used_block_id_hash: [u8; 32],
361 receive_time: u64,
362 relayed: bool,
363 tx_blob: Vec<u8>,
364 tx_json: crate::json::tx::Transaction,
365 #[cfg_attr(feature = "serde", serde(default = "default_zero"))]
366 weight: u64 = default_zero::<u64>(),
367 }
368
369 #[doc = monero_definition_link!(
370 "cc73fe71162d564ffda8e549b79a350bca53c454",
371 "rpc/core_rpc_server_commands_defs.h",
372 1558..=1567
373 )]
374 SpentKeyImageInfo {
375 id_hash: [u8; 32],
376 txs_hashes: Vec<[u8; 32]>,
377 }
378
379 #[doc = monero_definition_link!(
380 "cc73fe71162d564ffda8e549b79a350bca53c454",
381 "rpc/core_rpc_server_commands_defs.h",
382 1666..=1675
383 )]
384 #[derive(Copy)]
385 TxpoolHisto {
386 txs: u32,
387 bytes: u64,
388 }
389
390 #[doc = monero_definition_link!(
391 "cc73fe71162d564ffda8e549b79a350bca53c454",
392 "rpc/core_rpc_server_commands_defs.h",
393 1677..=1710
394 )]
395 TxpoolStats {
396 bytes_max: u32,
397 bytes_med: u32,
398 bytes_min: u32,
399 bytes_total: u64,
400 fee_total: u64,
401 histo_98pc: u64,
402 histo: Vec<TxpoolHisto>,
403 num_10m: u32,
404 num_double_spends: u32,
405 num_failing: u32,
406 num_not_relayed: u32,
407 oldest: u64,
408 txs_total: u32,
409 }
410
411 #[doc = monero_definition_link!(
412 "893916ad091a92e765ce3241b94e706ad012b62a",
413 "blockchain_db/lmdb/db_lmdb.cpp",
414 4222
415 )]
416 OutputHistogramInput {
417 amounts: Vec<u64>,
418 min_count: u64,
419 max_count: u64,
420 unlocked: bool,
421 recent_cutoff: u64,
422 }
423
424 #[doc = monero_definition_link!(
425 "893916ad091a92e765ce3241b94e706ad012b62a",
426 "rpc/core_rpc_server_commands_defs.h",
427 2139..=2156
428 )]
429 OutputHistogramEntry {
430 amount: u64,
431 total_instances: u64,
432 unlocked_instances: u64,
433 recent_instances: u64,
434 }
435
436 #[doc = monero_definition_link!(
437 "893916ad091a92e765ce3241b94e706ad012b62a",
438 "rpc/core_rpc_server_commands_defs.h",
439 2228..=2247
440 )]
441 CoinbaseTxSum {
442 emission_amount_top64: u64,
443 emission_amount: u64,
444 fee_amount_top64: u64,
445 fee_amount: u64,
446 }
447
448 #[doc = monero_definition_link!(
449 "893916ad091a92e765ce3241b94e706ad012b62a",
450 "rpc/core_rpc_server_commands_defs.h",
451 1027..=1033
452 )]
453 MinerData {
454 major_version: u8,
455 height: u64,
456 prev_id: [u8; 32],
457 seed_hash: [u8; 32],
458 difficulty_top64: u64,
459 difficulty: u64,
460 median_weight: u64,
461 already_generated_coins: u64,
462 tx_backlog: Vec<MinerDataTxBacklogEntry>,
463 }
464
465 #[doc = monero_definition_link!(
466 "893916ad091a92e765ce3241b94e706ad012b62a",
467 "rpc/core_rpc_server_commands_defs.h",
468 1037..=1039
469 )]
470 MinerDataTxBacklogEntry {
471 id: [u8; 32],
472 weight: u64,
473 fee: u64,
474 }
475
476 #[doc = monero_definition_link!(
477 "893916ad091a92e765ce3241b94e706ad012b62a",
478 "rpc/core_rpc_server_commands_defs.h",
479 1973..=1980
480 )]
481 HardForkInfo {
482 earliest_height: u64,
483 enabled: bool,
484 state: u32,
485 threshold: u32,
486 version: u8,
487 votes: u32,
488 voting: u8,
489 window: u32,
490 }
491
492 #[doc = monero_definition_link!(
493 "893916ad091a92e765ce3241b94e706ad012b62a",
494 "rpc/core_rpc_server_commands_defs.h",
495 2264..=2267
496 )]
497 FeeEstimate {
498 fee: u64,
499 fees: Vec<u64>,
500 quantization_mask: u64,
501 }
502
503 #[doc = monero_definition_link!(
504 "893916ad091a92e765ce3241b94e706ad012b62a",
505 "rpc/core_rpc_server_commands_defs.h",
506 1115..=1119
507 )]
508 AddAuxPow {
509 blocktemplate_blob: Vec<u8>,
510 blockhashing_blob: Vec<u8>,
511 merkle_root: [u8; 32],
512 merkle_tree_depth: u64,
513 aux_pow: Vec<AuxPow>,
514 }
515
516 #[doc = monero_definition_link!(
517 "893916ad091a92e765ce3241b94e706ad012b62a",
518 "rpc/core_rpc_server_commands_defs.h",
519 227..=229
520 )]
521 PoolTxInfo {
522 tx_hash: [u8; 32],
523 tx_blob: Vec<u8>,
524 double_spend_seen: bool,
525 }
526
527 #[doc = monero_definition_link!(
528 "893916ad091a92e765ce3241b94e706ad012b62a",
529 "rpc/core_rpc_server_commands_defs.h",
530 254..=256
531 )]
532 PoolInfoIncremental {
533 added_pool_txs: Vec<PoolTxInfo>,
534 remaining_added_pool_txids: ByteArrayVec<32>,
535 removed_pool_txids: ByteArrayVec<32>,
536 }
537
538 #[doc = monero_definition_link!(
539 "893916ad091a92e765ce3241b94e706ad012b62a",
540 "rpc/core_rpc_server_commands_defs.h",
541 254..=256
542 )]
543 PoolInfoFull {
544 added_pool_txs: Vec<PoolTxInfo>,
545 remaining_added_pool_txids: ByteArrayVec<32>,
546 }
547
548}
549
550#[cfg(test)]
552mod test {
553 }