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.:
// #[derive(MyCustomDerive)]
GetBlockCount, // <- The type name.
#[derive(Copy)]
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:
// ```
// $ATTRIBUTES
@ -25,35 +31,48 @@ define_monero_rpc_struct! {
// ```
// The struct generated and all fields are `pub`.
/// 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,
},
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,
}
}
// define_monero_rpc_struct! {
// on_get_block_hash,
// core_rpc_server_commands_defs.h => 919..=933,
// OnGetBlockHash { height: [123] } =>
// r#"[123]"#,
// #[repr(transparent)]
// #[cfg_attr(feature = "serde", serde(transparent))]
// OnGetBlockHash {
// /// A block's height.
// height: [u64; 1],
// }
// }
define_monero_rpc_struct! {
on_get_block_hash,
core_rpc_server_commands_defs.h => 935..=939,
OnGetBlockHash,
#[derive(Copy)]
Request {
block_height: u64,
},
Response {
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
#[cfg(test)]

View file

@ -98,7 +98,7 @@
)]
//---------------------------------------------------------------------------------------------------- Use
mod binary;
mod bin;
mod data;
mod json;
mod macros;
@ -106,6 +106,12 @@ pub mod misc;
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 {
@ -113,7 +119,7 @@ macro_rules! re_export_request_and_response_types {
$json_type:ident,
)*
}
binary {
bin {
$(
$binary_type:ident,
)*
@ -134,9 +140,9 @@ macro_rules! re_export_request_and_response_types {
}
/// 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
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! {
json {
GetBlockCount,
OnGetBlockHash,
GetBlockTemplate,
}
binary {
bin {
}
other {
SaveBc,
}
}

View file

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

View file

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