diff --git a/rpc/types/README.md b/rpc/types/README.md index 297eabd..6dc269f 100644 --- a/rpc/types/README.md +++ b/rpc/types/README.md @@ -10,27 +10,26 @@ This crate ports the types used in Monero's RPC interface, including: # Modules This crate's types are split in the following manner: -1. This crate has 3 modules: - - The root module (`cuprate_rpc_types`) - - [`req`] (request types) - - [`resp`] (response types) -1. Miscellaneous types are found in the root module, e.g. [`Status`] -1. The `req` and `resp` modules perfectly mirror each-other, and are split into 3 modules: - - `json` (JSON types from the `/json_rpc` endpoint) - - `bin` (Binary types from the binary endpoints) - - `other` (Misc JSON types from other endpoints) -1. Each type in `req` has a corresponding type in `resp` and vice-versa with an identical name, e.g. [`req::json::GetBlockCount`] and [`resp::json::GetBlockCount`] +This crate has 4 modules: +- The root module; `cuprate_rpc_types` +- [`json`] module; JSON types from the `/json_rpc` endpoint +- [`bin`] module; Binary types from the binary endpoints +- [`other`] module; Misc JSON types from other endpoints + +Miscellaneous types are found in the root module, e.g. [`crate::Status`]. + +Each type in `{json,bin,other}` come in pairs and have identical names, but are suffixed with either `Request` or `Response`. e.g. [`GetBlockCountRequest`](crate::json::GetBlockCountRequest) & [`GetBlockCountResponse`](crate::json::GetBlockCountResponse). # Documentation -The documentation for types within [`req`] and [`resp`] are omitted, -as they can be found in [Monero's RPC documentation](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#on_get_block_hash). +The documentation for types within `{json,bin,other}` are omitted, as they can be found in [Monero's RPC documentation](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html). However, each type will document: -- The exact type definition location in `monerod` -- The Monero RPC documentation link +- **Definition**: the exact type definition location in `monerod` +- **Documentation**: the Monero RPC documentation link +- **Request/response**: the other side of this type, either the request or response # Naming -The naming for types within [`req`] and [`resp`] follow the following scheme: +The naming for types within `{json,bin,other}` follow the following scheme: - Convert the endpoint or method name into `UpperCamelCase` - Remove any suffix extension @@ -38,14 +37,14 @@ For example: | Endpoint/method | Crate location and name | |-----------------|-------------------------| -| [`get_block_count`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_block_count) | [`req::json::GetBlockCount`] & [`resp::json::GetBlockCount`] -| [`/get_blocks.bin`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_blockbin) | `req::bin::GetBlocks` & `resp::bin::GetBlocks` -| [`/get_height`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_height) | `req::other::GetHeight` & `resp::other::GetHeight` +| [`get_block_count`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_block_count) | [`json::GetBlockCountRequest`] & [`json::GetBlockCountResponse`] +| [`/get_blocks.bin`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_blockbin) | `bin::GetBlocksRequest` & `bin::GetBlocksResponse` +| [`/get_height`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_height) | `other::GetHeightRequest` & `other::GetHeightResponse` TODO: fix doc links when types are ready. # Mixed types -Note that some types within [`resp::other`] mix JSON & binary, i.e., +Note that some types within [`other`] mix JSON & binary together, i.e., the message overall is JSON, however some fields contain binary values, for example: diff --git a/rpc/types/src/bin.rs b/rpc/types/src/bin.rs index 79545c1..f327847 100644 --- a/rpc/types/src/bin.rs +++ b/rpc/types/src/bin.rs @@ -1,4 +1,4 @@ -//! Binary types. +//! Binary types from [binary](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_blocksbin) endpoints. //---------------------------------------------------------------------------------------------------- Import diff --git a/rpc/types/src/json.rs b/rpc/types/src/json.rs index 1918200..d81da51 100644 --- a/rpc/types/src/json.rs +++ b/rpc/types/src/json.rs @@ -1,4 +1,4 @@ -//! JSON types. +//! JSON types from the [`/json_rpc`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#json-rpc-methods) endpoint. //! //! . diff --git a/rpc/types/src/lib.rs b/rpc/types/src/lib.rs index e3bcf2b..c3d7841 100644 --- a/rpc/types/src/lib.rs +++ b/rpc/types/src/lib.rs @@ -103,96 +103,6 @@ pub use status::Status; mod macros; // Request/response JSON/binary/other types. -mod bin; -mod json; -mod other; - -/// TODO -/// -/// TODO: explain -/// - how this works -/// - where to add types -/// - when to add -/// - what to do when adding/editing types -macro_rules! re_export_request_and_response_types { - ( - json { - $( - $json_type:ident, - )* - } - bin { - $( - $binary_type:ident, - )* - } - other { - $( - $other_type:ident, - )* - } - ) => { paste::paste! { - /// RPC request types. - pub mod req { - /// JSON types from the [`/json_rpc`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#json-rpc-methods) endpoint. - pub mod json { - $( - pub use $crate::json::[] as $json_type; - )* - } - - /// Binary types from [binary](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_blocksbin) endpoints. - pub mod bin { - $( - pub use $crate::bin::[] as $binary_type; - )* - } - - /// JSON types from the [`other`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#other-daemon-rpc-calls) endpoints. - pub mod other { - $( - pub use $crate::other::[] as $other_type; - )* - } - } - - /// RPC response types. - pub mod resp { - /// JSON types from the [`/json_rpc`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#json-rpc-methods) endpoint. - pub mod json { - $( - pub use $crate::json::[] as $json_type; - )* - } - - /// Binary types from [binary](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_blocksbin) endpoints. - pub mod bin { - $( - pub use $crate::bin::[] as $binary_type; - )* - } - - /// JSON types from the [`other`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#other-daemon-rpc-calls) endpoints. - pub mod other { - $( - pub use $crate::other::[] as $other_type; - )* - } - } - }}; -} - -re_export_request_and_response_types! { - json { - GetBlockCount, - OnGetBlockHash, - GetBlockTemplate, - } - - bin { - } - - other { - SaveBc, - } -} +pub mod bin; +pub mod json; +pub mod other; diff --git a/rpc/types/src/macros.rs b/rpc/types/src/macros.rs index 35befa2..ba51ca9 100644 --- a/rpc/types/src/macros.rs +++ b/rpc/types/src/macros.rs @@ -48,15 +48,7 @@ macro_rules! define_monero_rpc_struct { $( #[$request_type_attr] )* #[doc = concat!( "", - "Definition: [`", - stringify!($monero_code_filename), - ".", - stringify!($monero_code_filename_extension), - " @ ", - stringify!($monero_code_line_start), - "..=", - stringify!($monero_code_line_end), - "`](", + "[Definition](", "https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/", stringify!($monero_code_filename), ".", @@ -65,14 +57,15 @@ macro_rules! define_monero_rpc_struct { 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", + "), [documentation](", + "https://www.getmonero.org/resources/developer-guides/daemon-rpc.html", "#", stringify!($monero_daemon_rpc_doc_link), + "), [response](", + stringify!([<$type_name Response>]), ")." )] - pub struct [] { + pub struct [<$type_name Request>] { $( $( #[$request_field_attr] )* pub $request_field: $request_field_type, @@ -86,15 +79,7 @@ macro_rules! define_monero_rpc_struct { $( #[$response_type_attr] )* #[doc = concat!( "", - "Definition: [`", - stringify!($monero_code_filename), - ".", - stringify!($monero_code_filename_extension), - " @ ", - stringify!($monero_code_line_start), - "..=", - stringify!($monero_code_line_end), - "`](", + "[Definition](", "https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/", stringify!($monero_code_filename), ".", @@ -103,14 +88,15 @@ macro_rules! define_monero_rpc_struct { 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", + "), [documentation](", + "https://www.getmonero.org/resources/developer-guides/daemon-rpc.html", "#", stringify!($monero_daemon_rpc_doc_link), + "), [request](", + stringify!([<$type_name Request>]), ")." )] - pub struct [] { + pub struct [<$type_name Response>] { $( $( #[$response_field_attr] )* pub $response_field: $response_field_type, diff --git a/rpc/types/src/other.rs b/rpc/types/src/other.rs index 858ff73..0f90483 100644 --- a/rpc/types/src/other.rs +++ b/rpc/types/src/other.rs @@ -1,4 +1,4 @@ -//! Other endpoint types. +//! JSON types from the [`other`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#other-daemon-rpc-calls) endpoints. //! //! . diff --git a/rpc/types/src/status.rs b/rpc/types/src/status.rs index ea1a0b8..8f6bac3 100644 --- a/rpc/types/src/status.rs +++ b/rpc/types/src/status.rs @@ -12,7 +12,7 @@ use strum::{ /// /// This type represents `monerod`'s frequently appearing string field, `status`. /// -/// This field appears within RPC [JSON response](crate::resp::json) types. +/// This field appears within RPC [JSON response](crate::json) types. /// /// Reference: . ///