From a4ad660daac0edb096ddf5d56ec8d835037ccfcc Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Mon, 3 Jun 2024 20:26:34 -0400 Subject: [PATCH] add `GetHeight` --- rpc/monero-rpc-types/src/data.rs | 2 +- rpc/monero-rpc-types/src/json.rs | 17 +++++++++++++++-- rpc/monero-rpc-types/src/macros.rs | 7 +++---- rpc/monero-rpc-types/src/other.rs | 23 ++++------------------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/rpc/monero-rpc-types/src/data.rs b/rpc/monero-rpc-types/src/data.rs index fc17a61..8b7548f 100644 --- a/rpc/monero-rpc-types/src/data.rs +++ b/rpc/monero-rpc-types/src/data.rs @@ -1,4 +1,4 @@ -//! Misc data structures within other types. +//! Data structures that appear in other types. //---------------------------------------------------------------------------------------------------- Import diff --git a/rpc/monero-rpc-types/src/json.rs b/rpc/monero-rpc-types/src/json.rs index 37f62af..d4e60d2 100644 --- a/rpc/monero-rpc-types/src/json.rs +++ b/rpc/monero-rpc-types/src/json.rs @@ -3,10 +3,10 @@ //! . //---------------------------------------------------------------------------------------------------- Import -use crate::{macros::define_monero_rpc_type_struct, misc::Status}; +use crate::{macros::define_monero_rpc_struct, misc::Status}; //---------------------------------------------------------------------------------------------------- Struct definitions -define_monero_rpc_type_struct! { +define_monero_rpc_struct! { // The markdown tag for Monero RPC documentation. Not necessarily the endpoint. get_block_count, // The `$file.$extension` in which this type is defined in the Monero @@ -36,6 +36,19 @@ define_monero_rpc_type_struct! { } } +define_monero_rpc_struct! { + on_get_block_hash, + core_rpc_server_commands_defs.h => 919..=933, + OnGetBlockHash { height: [123] } => + r#"[123]"#, + #[repr(transparent)] + #[cfg_attr(feature = "serde", serde(transparent))] + OnGetBlockHash { + /// A block's height. + height: [u64; 1], + } +} + //---------------------------------------------------------------------------------------------------- Tests #[cfg(test)] mod test { diff --git a/rpc/monero-rpc-types/src/macros.rs b/rpc/monero-rpc-types/src/macros.rs index 6f55789..f00467c 100644 --- a/rpc/monero-rpc-types/src/macros.rs +++ b/rpc/monero-rpc-types/src/macros.rs @@ -10,7 +10,7 @@ /// generate which docs. /// /// See [`crate::json::GetHeight`] for example usage. -macro_rules! define_monero_rpc_type_struct { +macro_rules! define_monero_rpc_struct { ( // The markdown tag for Monero RPC documentation. Not necessarily the endpoint. $monero_daemon_rpc_doc_link:ident, @@ -34,10 +34,9 @@ macro_rules! define_monero_rpc_type_struct { )* } ) => { - $( #[$type_attr:meta] )* #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] - /// + $( #[$type_attr] )* #[doc = concat!( "", "Definition: [`", @@ -83,6 +82,6 @@ macro_rules! define_monero_rpc_type_struct { } }; } -pub(crate) use define_monero_rpc_type_struct; +pub(crate) use define_monero_rpc_struct; //---------------------------------------------------------------------------------------------------- Documentation macros diff --git a/rpc/monero-rpc-types/src/other.rs b/rpc/monero-rpc-types/src/other.rs index 3f8966f..742feb8 100644 --- a/rpc/monero-rpc-types/src/other.rs +++ b/rpc/monero-rpc-types/src/other.rs @@ -3,30 +3,15 @@ //! . //---------------------------------------------------------------------------------------------------- Import -use crate::macros::define_monero_rpc_type_struct; +use crate::macros::define_monero_rpc_struct; //---------------------------------------------------------------------------------------------------- TODO -define_monero_rpc_type_struct! { - // The markdown tag for Monero RPC documentation. Not necessarily the endpoint. +define_monero_rpc_struct! { get_height, - // The `$file.$extension` in which this type is defined in the Monero - // codebase in the `rpc/` directory, followed by the specific lines. daemon_messages.h => 81..=87, - // The type and its compacted JSON string form, used in example doc-test. GetHeight { height: 123 } => r#"{"height":123}"#, - // The actual type definitions. - // If there are any additional attributes (`/// docs` or `#[derive]`s) - // for the struct, they go here, e.g.: - // #[derive(MyCustomDerive)] - GetHeight /* <- The type name */ { - // Within the `{}` is an infinite matching pattern of: - // ``` - // $ATTRIBUTES - // $FIELD_NAME: $FIELD_TYPE, - // ``` - // The struct generated and all fields are `pub`. - - /// A block height. + GetHeight { + /// A block's height. height: u64, } }