diff --git a/rpc/monero-rpc-types/Cargo.toml b/rpc/monero-rpc-types/Cargo.toml index f638a93..880c3c5 100644 --- a/rpc/monero-rpc-types/Cargo.toml +++ b/rpc/monero-rpc-types/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/rpc/monero-rpc-types keywords = ["monero", "rpc", "types"] [features] -default = ["dep:serde"] +default = ["serde"] [dependencies] monero-serai = { workspace = true } diff --git a/rpc/monero-rpc-types/src/json.rs b/rpc/monero-rpc-types/src/json.rs index fd30727..5526925 100644 --- a/rpc/monero-rpc-types/src/json.rs +++ b/rpc/monero-rpc-types/src/json.rs @@ -1,8 +1,20 @@ //! TODO +//! +//! . //---------------------------------------------------------------------------------------------------- Import +use crate::macros::define_monero_rpc_type_struct; //---------------------------------------------------------------------------------------------------- TODO +define_monero_rpc_type_struct! { + get_height, + daemon_messages.h => 81..=87, + GetHeight { height: 123 } => r#"{"height":123}"#, + GetHeight { + /// A block height. + height: u64, + } +} //---------------------------------------------------------------------------------------------------- Tests #[cfg(test)] diff --git a/rpc/monero-rpc-types/src/lib.rs b/rpc/monero-rpc-types/src/lib.rs index da0d5d2..4c2094f 100644 --- a/rpc/monero-rpc-types/src/lib.rs +++ b/rpc/monero-rpc-types/src/lib.rs @@ -76,6 +76,9 @@ // FIXME: good lint but is less clear in most cases. clippy::items_after_statements, + // TODO + rustdoc::bare_urls, + clippy::module_name_repetitions, clippy::module_inception, clippy::redundant_pub_crate, diff --git a/rpc/monero-rpc-types/src/macros.rs b/rpc/monero-rpc-types/src/macros.rs index e012259..3c8132f 100644 --- a/rpc/monero-rpc-types/src/macros.rs +++ b/rpc/monero-rpc-types/src/macros.rs @@ -2,22 +2,75 @@ //! //! These generate repetitive documentation, tests, etc. -//---------------------------------------------------------------------------------------------------- Documentation macros +//---------------------------------------------------------------------------------------------------- Struct definition /// TODO -macro_rules! serde_doc_test { +macro_rules! define_monero_rpc_type_struct { ( - $type:ty, // TODO + $monero_daemon_rpc_doc_link:ident, // TODO + $monero_code_filename:ident.$monero_code_filename_extension:ident => // TODO + $monero_code_line_start:literal..= // TODO + $monero_code_line_end:literal, // TODO + $type_literal:expr => // TODO + $type_as_json:literal, // TODO + $type_name:ident { // TODO + $( + $( #[$field_attr:meta] )* // TODO + $field:ident: $type:ty, // TODO + )* + } ) => { - #[doc = "TODO"] + /// + #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + /// + // Documents the original Monero type and where it is located in `monero-project/monero`. + #[doc = concat!( + "", + "Definition: [`", + stringify!($monero_code_filename), + ".", + stringify!($monero_code_filename_extension), + " @ ", + stringify!($monero_code_line_start), + "..=", + stringify!($monero_code_line_end), + "`](", + "https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/", + stringify!($monero_code_filename), + ".", + stringify!($monero_code_filename_extension), + "#L", + stringify!($monero_code_line_start), + "-L", + stringify!($monero_code_line_end), + "), documentation: [`", + stringify!($monero_daemon_rpc_doc_link), + "`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html", + "#", + stringify!($monero_daemon_rpc_doc_link), + ").", + )] + /// + // Doc-test that tests (de)serialization. + /// # `serde` example + /// ```rust + #[doc = "# use monero_rpc_types::{json::*, binary::*, data::*, mix::*};"] + #[doc = concat!("let t = ", stringify!($type_literal), ";")] + #[doc = "let string = serde_json::to_string(&t).unwrap();"] + #[doc = concat!("assert_eq!(string, ", stringify!($type_as_json), ");")] + #[doc = ""] + #[doc = "let t2 = serde_json::from_str(&string).unwrap();"] + #[doc = "assert_eq!(t, t2);"] + /// ``` + // The type. + pub struct $type_name { + $( + $( #[$field_attr] )* + pub $field: $type, + )* + } }; } +pub(crate) use define_monero_rpc_type_struct; -/// TODO -macro_rules! monero_ref { - ( - $monero_code_link:literal, // TODO - $monero_rpc_doc_link:literal, // TODO - ) => { - #[doc = "TODO"] - }; -} +//---------------------------------------------------------------------------------------------------- Documentation macros