add GetHeight

This commit is contained in:
hinto.janai 2024-06-03 20:26:34 -04:00
parent af70416736
commit a4ad660daa
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
4 changed files with 23 additions and 26 deletions

View file

@ -1,4 +1,4 @@
//! Misc data structures within other types.
//! Data structures that appear in other types.
//---------------------------------------------------------------------------------------------------- Import

View file

@ -3,10 +3,10 @@
//! <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/daemon_messages.h>.
//---------------------------------------------------------------------------------------------------- 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 {

View file

@ -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

View file

@ -3,30 +3,15 @@
//! <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/daemon_messages.h>.
//---------------------------------------------------------------------------------------------------- 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,
}
}