add struct ConnectionInfo, add macro for misc types

This commit is contained in:
hinto.janai 2024-07-03 17:23:37 -04:00
parent e5c833c996
commit 352ab2015a
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
4 changed files with 116 additions and 62 deletions

View file

@ -23,7 +23,7 @@ use crate::{macros::monero_definition_link, Status};
//---------------------------------------------------------------------------------------------------- Requests
//---------------------------------------------------------------------------------------------------- Responses
#[doc = monero_definition_link!(cc73fe71162d564ffda8e549b79a350bca53c454 => core_rpc_server_commands_defs.h => 101..=112)]
#[doc = monero_definition_link!(cc73fe71162d564ffda8e549b79a350bca53c454, "rpc/core_rpc_server_commands_defs.h", 101..=112)]
/// The most common base for responses.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -43,7 +43,7 @@ epee_object! {
untrusted: bool,
}
#[doc = monero_definition_link!(cc73fe71162d564ffda8e549b79a350bca53c454 => core_rpc_server_commands_defs.h => 124..=136)]
#[doc = monero_definition_link!(cc73fe71162d564ffda8e549b79a350bca53c454, "rpc/core_rpc_server_commands_defs.h", 124..=136)]
/// A base for RPC response types that support RPC payment.
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View file

@ -123,4 +123,4 @@ pub mod json;
pub mod other;
mod misc;
pub use misc::BlockHeader;
pub use misc::{BlockHeader, ConnectionInfo};

View file

@ -292,14 +292,12 @@ pub(crate) use define_request_and_response_doc;
//---------------------------------------------------------------------------------------------------- Macro
/// Link the original `monerod` definition for RPC base types.
macro_rules! monero_definition_link {
($commit:ident => $file:ident.$file_extension:ident => $start:literal..=$end:literal) => {
($commit:ident, $file_path:literal, $start:literal..=$end:literal) => {
concat!(
"[Definition](https://github.com/monero-project/monero/blob/",
stringify!($commit),
"/src/rpc/",
stringify!($file),
".",
stringify!($file_extension),
"/src/",
stringify!($file_path),
"#L",
stringify!($start),
"-L",

View file

@ -1,5 +1,11 @@
//! TODO
//---------------------------------------------------------------------------------------------------- Lints
#![allow(
missing_docs, // Docs are at: <https://www.getmonero.org/resources/developer-guides/daemon-rpc.html>
clippy::struct_excessive_bools, // hey man, tell that to the people who wrote `monerod`
)]
//---------------------------------------------------------------------------------------------------- Import
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@ -9,62 +15,112 @@ use cuprate_epee_encoding::epee_object;
use crate::macros::monero_definition_link;
//---------------------------------------------------------------------------------------------------- BlockHeader
#[doc = monero_definition_link!(cc73fe71162d564ffda8e549b79a350bca53c454 => core_rpc_server_commands_defs.h => 1163..=1212)]
/// TODO.
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(missing_docs)]
pub struct BlockHeader {
pub major_version: u8,
pub minor_version: u8,
pub timestamp: u64,
pub prev_hash: String,
pub nonce: u32,
pub orphan_status: bool,
pub height: u64,
pub depth: u64,
pub hash: String,
pub difficulty: u64,
pub wide_difficulty: String,
pub difficulty_top64: u64,
pub cumulative_difficulty: u64,
pub wide_cumulative_difficulty: String,
pub cumulative_difficulty_top64: u64,
pub reward: u64,
pub block_size: u64,
pub block_weight: u64,
pub num_txes: u64,
pub pow_hash: String,
pub long_term_weight: u64,
pub miner_tx_hash: String,
//---------------------------------------------------------------------------------------------------- Macros
/// TODO
macro_rules! define_struct_and_impl_epee {
(
$( #[$struct_attr:meta] )*
$struct_name:ident {
// And any fields.
$(
$( #[$field_attr:meta] )*
$field_name:ident: $field_type:ty,
)*
}
) => {
$( #[$struct_attr] )*
pub struct $struct_name {
$(
$( #[$field_attr] )*
pub $field_name: $field_type,
)*
}
#[cfg(feature = "epee")]
epee_object! {
$struct_name,
$(
$field_name: $field_type,
)*
}
};
}
#[cfg(feature = "epee")]
epee_object! {
BlockHeader,
major_version: u8,
minor_version: u8,
timestamp: u64,
prev_hash: String,
nonce: u32,
orphan_status: bool,
height: u64,
depth: u64,
hash: String,
difficulty: u64,
wide_difficulty: String,
difficulty_top64: u64,
cumulative_difficulty: u64,
wide_cumulative_difficulty: String,
cumulative_difficulty_top64: u64,
reward: u64,
block_size: u64,
block_weight: u64,
num_txes: u64,
pow_hash: String,
long_term_weight: u64,
miner_tx_hash: String,
//---------------------------------------------------------------------------------------------------- BlockHeader
define_struct_and_impl_epee! {
#[doc = monero_definition_link!(
cc73fe71162d564ffda8e549b79a350bca53c454,
"rpc/core_rpc_server_commands_defs.h",
1163..=1212
)]
/// TODO.
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
BlockHeader {
block_size: u64,
block_weight: u64,
cumulative_difficulty_top64: u64,
cumulative_difficulty: u64,
depth: u64,
difficulty_top64: u64,
difficulty: u64,
hash: String,
height: u64,
long_term_weight: u64,
major_version: u8,
miner_tx_hash: String,
minor_version: u8,
nonce: u32,
num_txes: u64,
orphan_status: bool,
pow_hash: String,
prev_hash: String,
reward: u64,
timestamp: u64,
wide_cumulative_difficulty: String,
wide_difficulty: String,
}
}
//---------------------------------------------------------------------------------------------------- BlockHeader
define_struct_and_impl_epee! {
#[doc = monero_definition_link!(
cc73fe71162d564ffda8e549b79a350bca53c454,
"cryptonote_protocol/cryptonote_protocol_defs.h",
47..=116
)]
/// TODO.
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
ConnectionInfo {
address: String,
address_type: u8,
avg_download: u64,
avg_upload: u64,
connection_id: String,
current_download: u64,
current_upload: u64,
height: u64,
host: String,
incoming: bool,
ip: String,
live_time: u64,
localhost: bool,
local_ip: bool,
peer_id: String,
port: String,
pruning_seed: u32,
recv_count: u64,
recv_idle_time: u64,
rpc_credits_per_hash: u32,
rpc_port: u16,
send_count: u64,
send_idle_time: u64,
ssl: bool,
state: String,
support_flags: u32,
}
}
//---------------------------------------------------------------------------------------------------- Tests