macro changes, add few more types

This commit is contained in:
hinto.janai 2024-06-11 21:07:59 -04:00
parent 661e3d0ac8
commit 865ff304c5
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
6 changed files with 508 additions and 232 deletions

592
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -17,7 +17,13 @@ define_monero_rpc_struct! {
// for the struct, they go here, e.g.: // for the struct, they go here, e.g.:
// #[derive(MyCustomDerive)] // #[derive(MyCustomDerive)]
GetBlockCount, // <- The type name. GetBlockCount, // <- The type name.
#[derive(Copy)]
Request /* <- The request type */ { Request /* <- The request type */ {
// This request type requires no inputs,
// so it is left empty.
},
#[derive(Copy)]
Response /* <- The response type */ {
// Within the `{}` is an infinite matching pattern of: // Within the `{}` is an infinite matching pattern of:
// ``` // ```
// $ATTRIBUTES // $ATTRIBUTES
@ -25,35 +31,48 @@ define_monero_rpc_struct! {
// ``` // ```
// The struct generated and all fields are `pub`. // The struct generated and all fields are `pub`.
/// How many blocks are in the longest chain known to the node.
count: u64, count: u64,
/// General RPC error code. "OK" means everything looks good.
status: crate::misc::Status, status: crate::misc::Status,
/// Whether the node is untrusted (see Monero docs).
untrusted: bool,
},
Response /* <- The response type */ {
/// How many blocks are in the longest chain known to the node.
count: u64,
/// General RPC error code. "OK" means everything looks good.
status: crate::misc::Status,
/// Whether the node is untrusted (see Monero docs).
untrusted: bool, untrusted: bool,
} }
} }
// define_monero_rpc_struct! { define_monero_rpc_struct! {
// on_get_block_hash, on_get_block_hash,
// core_rpc_server_commands_defs.h => 919..=933, core_rpc_server_commands_defs.h => 935..=939,
// OnGetBlockHash { height: [123] } => OnGetBlockHash,
// r#"[123]"#, #[derive(Copy)]
// #[repr(transparent)] Request {
// #[cfg_attr(feature = "serde", serde(transparent))] block_height: u64,
// OnGetBlockHash { },
// /// A block's height. Response {
// height: [u64; 1], block_hash: String,
// } }
// } }
define_monero_rpc_struct! {
get_block_template,
core_rpc_server_commands_defs.h => 943..=994,
GetBlockTemplate,
Request {
reserve_size: u64,
wallet_address: String,
},
Response {
difficulty: u64,
wide_difficulty: String,
difficulty_top64: u64,
height: u64,
reserved_offset: u64,
expected_reward: u64,
prev_hash: String,
seed_height: u64,
seed_hash: String,
next_seed_hash: String,
blocktemplate_blob: String,
blockhashing_blob: String,
}
}
//---------------------------------------------------------------------------------------------------- Tests //---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)] #[cfg(test)]

View file

@ -98,7 +98,7 @@
)] )]
//---------------------------------------------------------------------------------------------------- Use //---------------------------------------------------------------------------------------------------- Use
mod binary; mod bin;
mod data; mod data;
mod json; mod json;
mod macros; mod macros;
@ -106,6 +106,12 @@ pub mod misc;
mod other; mod other;
/// TODO /// 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 { macro_rules! re_export_request_and_response_types {
( (
json { json {
@ -113,7 +119,7 @@ macro_rules! re_export_request_and_response_types {
$json_type:ident, $json_type:ident,
)* )*
} }
binary { bin {
$( $(
$binary_type:ident, $binary_type:ident,
)* )*
@ -134,9 +140,9 @@ macro_rules! re_export_request_and_response_types {
} }
/// TODO /// TODO
pub mod binary { pub mod bin {
$( $(
pub use $crate::binary::[<Request $binary_type>] as $binary_type; pub use $crate::bin::[<Request $binary_type>] as $binary_type;
)* )*
} }
@ -158,9 +164,9 @@ macro_rules! re_export_request_and_response_types {
} }
/// TODO /// TODO
pub mod binary { pub mod bin {
$( $(
pub use $crate::binary::[<Response $binary_type>] as $binary_type; pub use $crate::bin::[<Response $binary_type>] as $binary_type;
)* )*
} }
@ -177,11 +183,14 @@ macro_rules! re_export_request_and_response_types {
re_export_request_and_response_types! { re_export_request_and_response_types! {
json { json {
GetBlockCount, GetBlockCount,
OnGetBlockHash,
GetBlockTemplate,
} }
binary { bin {
} }
other { other {
SaveBc,
} }
} }

View file

@ -21,8 +21,8 @@ macro_rules! define_monero_rpc_struct {
$monero_code_line_start:literal..=$monero_code_line_end:literal, $monero_code_line_start:literal..=$monero_code_line_end:literal,
// The actual request `struct` name and any doc comments, derives, etc. // The actual request `struct` name and any doc comments, derives, etc.
$( #[$request_type_attr:meta] )*
$type_name:ident, $type_name:ident,
$( #[$request_type_attr:meta] )*
Request { Request {
// And any fields. // And any fields.
$( $(
@ -41,8 +41,10 @@ macro_rules! define_monero_rpc_struct {
)* )*
} }
) => { paste::paste! { ) => { paste::paste! {
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[allow(dead_code)]
#[allow(missing_docs)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
$( #[$request_type_attr] )* $( #[$request_type_attr] )*
#[doc = concat!( #[doc = concat!(
"", "",
@ -70,7 +72,6 @@ macro_rules! define_monero_rpc_struct {
stringify!($monero_daemon_rpc_doc_link), stringify!($monero_daemon_rpc_doc_link),
")." ")."
)] )]
#[allow(dead_code)]
pub struct [<Request $type_name>] { pub struct [<Request $type_name>] {
$( $(
$( #[$request_field_attr] )* $( #[$request_field_attr] )*
@ -79,7 +80,36 @@ macro_rules! define_monero_rpc_struct {
} }
#[allow(dead_code)] #[allow(dead_code)]
/// TODO #[allow(missing_docs)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
$( #[$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),
"`](",
"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),
")."
)]
pub struct [<Response $type_name>] { pub struct [<Response $type_name>] {
$( $(
$( #[$response_field_attr] )* $( #[$response_field_attr] )*

View file

@ -3,18 +3,20 @@
//! <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>.
//---------------------------------------------------------------------------------------------------- Import //---------------------------------------------------------------------------------------------------- Import
// use crate::macros::define_monero_rpc_struct; use crate::macros::define_monero_rpc_struct;
//---------------------------------------------------------------------------------------------------- TODO //---------------------------------------------------------------------------------------------------- TODO
// define_monero_rpc_struct! { define_monero_rpc_struct! {
// get_height, save_bc,
// daemon_messages.h => 81..=87, core_rpc_server_commands_defs.h => 898..=916,
// GetHeight { height: 123 } => r#"{"height":123}"#, SaveBc,
// GetHeight { #[derive(Copy)]
// /// A block's height. Request {},
// height: u64, Response {
// } status: crate::misc::Status,
// } untrusted: bool,
}
}
//---------------------------------------------------------------------------------------------------- Tests //---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)] #[cfg(test)]