mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-11-17 00:07:53 +00:00
use different type for macro example
This commit is contained in:
parent
f40e3c168d
commit
fba6dbcd72
3 changed files with 49 additions and 41 deletions
|
@ -11,30 +11,41 @@ use crate::{
|
||||||
//---------------------------------------------------------------------------------------------------- Struct definitions
|
//---------------------------------------------------------------------------------------------------- Struct definitions
|
||||||
// This generates 2 structs:
|
// This generates 2 structs:
|
||||||
//
|
//
|
||||||
// - `GetBlockCountRequest`
|
// - `GetBlockTemplateRequest`
|
||||||
// - `GetBlockCountResponse`
|
// - `GetBlockTemplateResponse`
|
||||||
//
|
//
|
||||||
// with some interconnected documentation.
|
// with some interconnected documentation.
|
||||||
define_request_and_response! {
|
define_request_and_response! {
|
||||||
// The markdown tag for Monero RPC documentation. Not necessarily the endpoint.
|
// The markdown tag for Monero RPC documentation. Not necessarily the endpoint.
|
||||||
get_block_count,
|
get_block_template,
|
||||||
|
|
||||||
// The commit hash and `$file.$extension` in which this type is defined in
|
// 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.
|
// the Monero codebase in the `rpc/` directory, followed by the specific lines.
|
||||||
cc73fe71162d564ffda8e549b79a350bca53c454 => core_rpc_server_commands_defs.h => 919..=933,
|
cc73fe71162d564ffda8e549b79a350bca53c454 => core_rpc_server_commands_defs.h => 943..=994,
|
||||||
|
|
||||||
// The base type name.
|
// The base type name.
|
||||||
GetBlockCount,
|
GetBlockTemplate,
|
||||||
|
|
||||||
// The request type.
|
// The base request type.
|
||||||
RequestBase {
|
//
|
||||||
// This request type requires no inputs,
|
// This must be a type found in [`crate::base`].
|
||||||
// so it is left empty. Leaving this empty
|
// It acts as a "base" that gets flattened into
|
||||||
// will cause the macro to generate a type
|
// the actually request type.
|
||||||
// alias to `()` instead of a `struct`.
|
//
|
||||||
|
// For example here, we're using [`crate::base::EmptyRequestBase`],
|
||||||
|
// which means that there is no extra fields flattened.
|
||||||
|
//
|
||||||
|
// If a request is not specified here, it will create a `type alias YOUR_REQUEST_TYPE = ()`
|
||||||
|
// instead of a `struct`, see below in other macro definitions for an example.
|
||||||
|
EmptyRequestBase {
|
||||||
|
reserve_size: u64,
|
||||||
|
wallet_address: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
// The response type.
|
// The base response type.
|
||||||
|
//
|
||||||
|
// This is the same as the request base type,
|
||||||
|
// it must be a type found in [`crate::base`].
|
||||||
//
|
//
|
||||||
// If there are any additional attributes (`/// docs` or `#[derive]`s)
|
// If there are any additional attributes (`/// docs` or `#[derive]`s)
|
||||||
// for the struct, they go here, e.g.:
|
// for the struct, they go here, e.g.:
|
||||||
|
@ -46,6 +57,32 @@ define_request_and_response! {
|
||||||
// $FIELD_NAME: $FIELD_TYPE,
|
// $FIELD_NAME: $FIELD_TYPE,
|
||||||
// ```
|
// ```
|
||||||
// The struct generated and all fields are `pub`.
|
// The struct generated and all fields are `pub`.
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
define_request_and_response! {
|
||||||
|
get_block_count,
|
||||||
|
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||||
|
core_rpc_server_commands_defs.h => 919..=933,
|
||||||
|
GetBlockCount,
|
||||||
|
|
||||||
|
// There is no request type specified,
|
||||||
|
// this will cause the macro to generate a
|
||||||
|
// type alias to `()` instead of a `struct`.
|
||||||
|
|
||||||
|
ResponseBase {
|
||||||
count: u64,
|
count: u64,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,31 +103,6 @@ define_request_and_response! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
define_request_and_response! {
|
|
||||||
get_block_template,
|
|
||||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
|
||||||
core_rpc_server_commands_defs.h => 943..=994,
|
|
||||||
GetBlockTemplate,
|
|
||||||
EmptyRequestBase {
|
|
||||||
reserve_size: u64,
|
|
||||||
wallet_address: String,
|
|
||||||
},
|
|
||||||
ResponseBase {
|
|
||||||
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)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|
|
@ -60,9 +60,6 @@ macro_rules! define_request_and_response {
|
||||||
// The base `struct` name.
|
// The base `struct` name.
|
||||||
$type_name:ident,
|
$type_name:ident,
|
||||||
|
|
||||||
// The empty unit request type.
|
|
||||||
$request_base_type:ty {},
|
|
||||||
|
|
||||||
// The response type (and any doc comments, derives, etc).
|
// The response type (and any doc comments, derives, etc).
|
||||||
$( #[$response_type_attr:meta] )*
|
$( #[$response_type_attr:meta] )*
|
||||||
$response_base_type:ty {
|
$response_base_type:ty {
|
||||||
|
|
|
@ -11,7 +11,6 @@ define_request_and_response! {
|
||||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||||
core_rpc_server_commands_defs.h => 898..=916,
|
core_rpc_server_commands_defs.h => 898..=916,
|
||||||
SaveBc,
|
SaveBc,
|
||||||
Request {},
|
|
||||||
ResponseBase {}
|
ResponseBase {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue