mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-23 03:59:37 +00:00
fix modules
This commit is contained in:
parent
1c12d6d2cf
commit
07ae4f6bd2
7 changed files with 37 additions and 142 deletions
|
@ -10,27 +10,26 @@ This crate ports the types used in Monero's RPC interface, including:
|
||||||
# Modules
|
# Modules
|
||||||
This crate's types are split in the following manner:
|
This crate's types are split in the following manner:
|
||||||
|
|
||||||
1. This crate has 3 modules:
|
This crate has 4 modules:
|
||||||
- The root module (`cuprate_rpc_types`)
|
- The root module; `cuprate_rpc_types`
|
||||||
- [`req`] (request types)
|
- [`json`] module; JSON types from the `/json_rpc` endpoint
|
||||||
- [`resp`] (response types)
|
- [`bin`] module; Binary types from the binary endpoints
|
||||||
1. Miscellaneous types are found in the root module, e.g. [`Status`]
|
- [`other`] module; Misc JSON types from other endpoints
|
||||||
1. The `req` and `resp` modules perfectly mirror each-other, and are split into 3 modules:
|
|
||||||
- `json` (JSON types from the `/json_rpc` endpoint)
|
Miscellaneous types are found in the root module, e.g. [`crate::Status`].
|
||||||
- `bin` (Binary types from the binary endpoints)
|
|
||||||
- `other` (Misc JSON types from other endpoints)
|
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).
|
||||||
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`]
|
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
The documentation for types within [`req`] and [`resp`] are omitted,
|
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).
|
||||||
as they can be found in [Monero's RPC documentation](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#on_get_block_hash).
|
|
||||||
|
|
||||||
However, each type will document:
|
However, each type will document:
|
||||||
- The exact type definition location in `monerod`
|
- **Definition**: the exact type definition location in `monerod`
|
||||||
- The Monero RPC documentation link
|
- **Documentation**: the Monero RPC documentation link
|
||||||
|
- **Request/response**: the other side of this type, either the request or response
|
||||||
|
|
||||||
# Naming
|
# 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`
|
- Convert the endpoint or method name into `UpperCamelCase`
|
||||||
- Remove any suffix extension
|
- Remove any suffix extension
|
||||||
|
|
||||||
|
@ -38,14 +37,14 @@ For example:
|
||||||
|
|
||||||
| Endpoint/method | Crate location and name |
|
| 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_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) | `req::bin::GetBlocks` & `resp::bin::GetBlocks`
|
| [`/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) | `req::other::GetHeight` & `resp::other::GetHeight`
|
| [`/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.
|
TODO: fix doc links when types are ready.
|
||||||
|
|
||||||
# Mixed types
|
# 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
|
the message overall is JSON, however some fields contain binary
|
||||||
values, for example:
|
values, for example:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Binary types.
|
//! Binary types from [binary](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_blocksbin) endpoints.
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
//---------------------------------------------------------------------------------------------------- Import
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
//!
|
//!
|
||||||
//! <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/daemon_messages.h>.
|
//! <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/daemon_messages.h>.
|
||||||
|
|
||||||
|
|
|
@ -103,96 +103,6 @@ pub use status::Status;
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
||||||
// Request/response JSON/binary/other types.
|
// Request/response JSON/binary/other types.
|
||||||
mod bin;
|
pub mod bin;
|
||||||
mod json;
|
pub mod json;
|
||||||
mod other;
|
pub 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::[<Request $json_type>] 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::[<Request $binary_type>] 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::[<Request $other_type>] 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::[<Response $json_type>] 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::[<Response $binary_type>] 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::[<Response $other_type>] as $other_type;
|
|
||||||
)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
re_export_request_and_response_types! {
|
|
||||||
json {
|
|
||||||
GetBlockCount,
|
|
||||||
OnGetBlockHash,
|
|
||||||
GetBlockTemplate,
|
|
||||||
}
|
|
||||||
|
|
||||||
bin {
|
|
||||||
}
|
|
||||||
|
|
||||||
other {
|
|
||||||
SaveBc,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -48,15 +48,7 @@ macro_rules! define_monero_rpc_struct {
|
||||||
$( #[$request_type_attr] )*
|
$( #[$request_type_attr] )*
|
||||||
#[doc = concat!(
|
#[doc = concat!(
|
||||||
"",
|
"",
|
||||||
"Definition: [`",
|
"[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/",
|
"https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/",
|
||||||
stringify!($monero_code_filename),
|
stringify!($monero_code_filename),
|
||||||
".",
|
".",
|
||||||
|
@ -65,14 +57,15 @@ macro_rules! define_monero_rpc_struct {
|
||||||
stringify!($monero_code_line_start),
|
stringify!($monero_code_line_start),
|
||||||
"-L",
|
"-L",
|
||||||
stringify!($monero_code_line_end),
|
stringify!($monero_code_line_end),
|
||||||
"), documentation: [`",
|
"), [documentation](",
|
||||||
stringify!($monero_daemon_rpc_doc_link),
|
"https://www.getmonero.org/resources/developer-guides/daemon-rpc.html",
|
||||||
"`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html",
|
|
||||||
"#",
|
"#",
|
||||||
stringify!($monero_daemon_rpc_doc_link),
|
stringify!($monero_daemon_rpc_doc_link),
|
||||||
|
"), [response](",
|
||||||
|
stringify!([<$type_name Response>]),
|
||||||
")."
|
")."
|
||||||
)]
|
)]
|
||||||
pub struct [<Request $type_name>] {
|
pub struct [<$type_name Request>] {
|
||||||
$(
|
$(
|
||||||
$( #[$request_field_attr] )*
|
$( #[$request_field_attr] )*
|
||||||
pub $request_field: $request_field_type,
|
pub $request_field: $request_field_type,
|
||||||
|
@ -86,15 +79,7 @@ macro_rules! define_monero_rpc_struct {
|
||||||
$( #[$response_type_attr] )*
|
$( #[$response_type_attr] )*
|
||||||
#[doc = concat!(
|
#[doc = concat!(
|
||||||
"",
|
"",
|
||||||
"Definition: [`",
|
"[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/",
|
"https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/",
|
||||||
stringify!($monero_code_filename),
|
stringify!($monero_code_filename),
|
||||||
".",
|
".",
|
||||||
|
@ -103,14 +88,15 @@ macro_rules! define_monero_rpc_struct {
|
||||||
stringify!($monero_code_line_start),
|
stringify!($monero_code_line_start),
|
||||||
"-L",
|
"-L",
|
||||||
stringify!($monero_code_line_end),
|
stringify!($monero_code_line_end),
|
||||||
"), documentation: [`",
|
"), [documentation](",
|
||||||
stringify!($monero_daemon_rpc_doc_link),
|
"https://www.getmonero.org/resources/developer-guides/daemon-rpc.html",
|
||||||
"`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html",
|
|
||||||
"#",
|
"#",
|
||||||
stringify!($monero_daemon_rpc_doc_link),
|
stringify!($monero_daemon_rpc_doc_link),
|
||||||
|
"), [request](",
|
||||||
|
stringify!([<$type_name Request>]),
|
||||||
")."
|
")."
|
||||||
)]
|
)]
|
||||||
pub struct [<Response $type_name>] {
|
pub struct [<$type_name Response>] {
|
||||||
$(
|
$(
|
||||||
$( #[$response_field_attr] )*
|
$( #[$response_field_attr] )*
|
||||||
pub $response_field: $response_field_type,
|
pub $response_field: $response_field_type,
|
||||||
|
|
|
@ -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.
|
||||||
//!
|
//!
|
||||||
//! <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/daemon_messages.h>.
|
//! <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/daemon_messages.h>.
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ use strum::{
|
||||||
///
|
///
|
||||||
/// This type represents `monerod`'s frequently appearing string field, `status`.
|
/// 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: <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/message.cpp#L40-L44>.
|
/// Reference: <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/message.cpp#L40-L44>.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue