diff --git a/rpc/types/src/json.rs b/rpc/types/src/json.rs index d81da51..755efa4 100644 --- a/rpc/types/src/json.rs +++ b/rpc/types/src/json.rs @@ -9,21 +9,26 @@ use crate::macros::define_monero_rpc_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 - // codebase in the `rpc/` directory, followed by the specific lines. - core_rpc_server_commands_defs.h => 919..=933, + + // The commit hash and `$file.$extension` in which this type is defined in + // the Monero codebase in the `rpc/` directory, followed by the specific lines. + cc73fe71162d564ffda8e549b79a350bca53c454 => core_rpc_server_commands_defs.h => 919..=933, + // The actual type definitions. // If there are any additional attributes (`/// docs` or `#[derive]`s) // for the struct, they go here, e.g.: // #[derive(MyCustomDerive)] - GetBlockCount, // <- The type name. - #[derive(Copy)] - Request /* <- The request type */ { + GetBlockCount, // The type name. + + Request /* The request type */ { // This request type requires no inputs, - // so it is left empty. + // so it is left empty. Leaving this empty + // will cause the macro to generate a type + // alias to `()` instead of a `struct`. }, + #[derive(Copy)] - Response /* <- The response type */ { + Response /* The response type */ { // Within the `{}` is an infinite matching pattern of: // ``` // $ATTRIBUTES @@ -39,6 +44,7 @@ define_monero_rpc_struct! { define_monero_rpc_struct! { on_get_block_hash, + cc73fe71162d564ffda8e549b79a350bca53c454 => core_rpc_server_commands_defs.h => 935..=939, OnGetBlockHash, #[derive(Copy)] @@ -52,6 +58,7 @@ define_monero_rpc_struct! { define_monero_rpc_struct! { get_block_template, + cc73fe71162d564ffda8e549b79a350bca53c454 => core_rpc_server_commands_defs.h => 943..=994, GetBlockTemplate, Request { diff --git a/rpc/types/src/macros.rs b/rpc/types/src/macros.rs index ba51ca9..b9c2a97 100644 --- a/rpc/types/src/macros.rs +++ b/rpc/types/src/macros.rs @@ -15,10 +15,94 @@ macro_rules! define_monero_rpc_struct { // The markdown tag for Monero RPC documentation. Not necessarily the endpoint. $monero_daemon_rpc_doc_link:ident, - // The `$file.$extension` in which this type is defined in the Monero - // codebase in the `rpc/` directory, followed by the specific lines. - $monero_code_filename:ident.$monero_code_filename_extension:ident => - $monero_code_line_start:literal..=$monero_code_line_end:literal, + // The commit hash and `$file.$extension` in which this type is defined in + // the Monero codebase in the `rpc/` directory, followed by the specific lines. + $monero_code_commit:ident => + $monero_code_filename:ident. + $monero_code_filename_extension:ident => + $monero_code_line_start:literal..= + $monero_code_line_end:literal, + + // The actual request `struct` name and any doc comments, derives, etc. + $type_name:ident, + Request {}, + // The actual `struct` name and any doc comments, derives, etc. + $( #[$response_type_attr:meta] )* + Response { + // And any fields. + $( + $( #[$response_field_attr:meta] )* + $response_field:ident: $response_field_type:ty, + )* + } + ) => { paste::paste! { + #[doc = concat!( + "", + "[Definition](", + "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](", + "https://www.getmonero.org/resources/developer-guides/daemon-rpc.html", + "#", + stringify!($monero_daemon_rpc_doc_link), + "), [response](", + stringify!([<$type_name Response>]), + ")." + )] + /// + /// This request has no inputs. + pub type [<$type_name Request>] = (); + + #[allow(dead_code)] + #[allow(missing_docs)] + #[derive(serde::Serialize, serde::Deserialize)] + #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] + $( #[$response_type_attr] )* + #[doc = concat!( + "", + "[Definition](", + "https://github.com/monero-project/monero/blob/", + stringify!($monero_code_commit), + "/src/rpc/", + stringify!($monero_code_filename), + ".", + stringify!($monero_code_filename_extension), + "#L", + stringify!($monero_code_line_start), + "-L", + stringify!($monero_code_line_end), + "), [documentation](", + "https://www.getmonero.org/resources/developer-guides/daemon-rpc.html", + "#", + stringify!($monero_daemon_rpc_doc_link), + "), [request](", + stringify!([<$type_name Request>]), + ")." + )] + pub struct [<$type_name Response>] { + $( + $( #[$response_field_attr] )* + pub $response_field: $response_field_type, + )* + } + }}; + ( + // The markdown tag for Monero RPC documentation. Not necessarily the endpoint. + $monero_daemon_rpc_doc_link:ident, + + // The commit hash and `$file.$extension` in which this type is defined in + // the Monero codebase in the `rpc/` directory, followed by the specific lines. + $monero_code_commit:ident => + $monero_code_filename:ident. + $monero_code_filename_extension:ident => + $monero_code_line_start:literal..= + $monero_code_line_end:literal, // The actual request `struct` name and any doc comments, derives, etc. $type_name:ident, @@ -49,7 +133,9 @@ macro_rules! define_monero_rpc_struct { #[doc = concat!( "", "[Definition](", - "https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/", + "https://github.com/monero-project/monero/blob/", + stringify!($monero_code_commit), + "/src/rpc/", stringify!($monero_code_filename), ".", stringify!($monero_code_filename_extension), @@ -80,7 +166,9 @@ macro_rules! define_monero_rpc_struct { #[doc = concat!( "", "[Definition](", - "https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/", + "https://github.com/monero-project/monero/blob/", + stringify!($monero_code_commit), + "/src/rpc/", stringify!($monero_code_filename), ".", stringify!($monero_code_filename_extension), diff --git a/rpc/types/src/other.rs b/rpc/types/src/other.rs index 0f90483..5150d41 100644 --- a/rpc/types/src/other.rs +++ b/rpc/types/src/other.rs @@ -8,9 +8,9 @@ use crate::macros::define_monero_rpc_struct; //---------------------------------------------------------------------------------------------------- TODO define_monero_rpc_struct! { save_bc, + cc73fe71162d564ffda8e549b79a350bca53c454 => core_rpc_server_commands_defs.h => 898..=916, SaveBc, - #[derive(Copy)] Request {}, Response { status: crate::Status,