mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-20 17:54:31 +00:00
support serde/epee default values
This commit is contained in:
parent
72bd1673d6
commit
d0981da311
4 changed files with 119 additions and 14 deletions
16
rpc/types/src/defaults.rs
Normal file
16
rpc/types/src/defaults.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
//! TODO
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- TODO
|
||||
/// TODO
|
||||
#[inline]
|
||||
pub(crate) const fn bool() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::*;
|
||||
}
|
|
@ -3,7 +3,12 @@
|
|||
//! <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/daemon_messages.h>.
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
use crate::{base::ResponseBase, macros::define_request_and_response};
|
||||
use crate::{
|
||||
base::{AccessResponseBase, ResponseBase},
|
||||
defaults::bool,
|
||||
macros::define_request_and_response,
|
||||
misc::BlockHeader,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Struct definitions
|
||||
// This generates 2 structs:
|
||||
|
@ -109,12 +114,32 @@ define_request_and_response! {
|
|||
core_rpc_server_commands_defs.h => 935..=939,
|
||||
OnGetBlockHash,
|
||||
#[derive(Copy)]
|
||||
/// ```rust
|
||||
/// use serde_json::*;
|
||||
/// use cuprate_rpc_types::json::*;
|
||||
///
|
||||
/// let x = OnGetBlockHashRequest { block_height: [3] };
|
||||
/// let x = to_string(&x).unwrap();
|
||||
/// assert_eq!(x, "[3]");
|
||||
/// ```
|
||||
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||
#[repr(transparent)]
|
||||
Request {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
block_height: u64,
|
||||
// This is `std::vector<uint64_t>` in `monerod` but
|
||||
// it must be a 1 length array or else it will error.
|
||||
block_height: [u64; 1],
|
||||
},
|
||||
/// ```rust
|
||||
/// use serde_json::*;
|
||||
/// use cuprate_rpc_types::json::*;
|
||||
///
|
||||
/// let x = OnGetBlockHashResponse { block_hash: String::from("asdf") };
|
||||
/// let x = to_string(&x).unwrap();
|
||||
/// assert_eq!(x, "\"asdf\"");
|
||||
/// ```
|
||||
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||
#[repr(transparent)]
|
||||
Response {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
block_hash: String,
|
||||
}
|
||||
}
|
||||
|
@ -152,6 +177,69 @@ define_request_and_response! {
|
|||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
generateblocks,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 1130..=1161,
|
||||
GenerateBlocks,
|
||||
Request {
|
||||
amount_of_blocks: u64,
|
||||
wallet_address: String,
|
||||
prev_block: String,
|
||||
starting_nonce: u32,
|
||||
},
|
||||
ResponseBase {
|
||||
height: u64,
|
||||
blocks: Vec<String>,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
get_last_block_header,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 1214..=1238,
|
||||
GetLastBlockHeader,
|
||||
Request {
|
||||
#[cfg_attr(feature = "serde", serde(default = "bool"))]
|
||||
fill_pow_hash: bool = bool(),
|
||||
},
|
||||
AccessResponseBase {
|
||||
block_header: BlockHeader,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
get_block_header_by_hash,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 1240..=1269,
|
||||
GetBlockHeaderByHash,
|
||||
Request {
|
||||
hash: String,
|
||||
hashes: Vec<String>,
|
||||
#[cfg_attr(feature = "serde", serde(default = "bool"))]
|
||||
fill_pow_hash: bool = bool(),
|
||||
},
|
||||
AccessResponseBase {
|
||||
block_header: BlockHeader,
|
||||
block_headers: Vec<BlockHeader>,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
get_block_header_by_height,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 1271..=1296,
|
||||
GetBlockHeaderByHeight,
|
||||
Request {
|
||||
height: u64,
|
||||
#[cfg_attr(feature = "serde", serde(default = "bool"))]
|
||||
fill_pow_hash: bool = bool(),
|
||||
},
|
||||
AccessResponseBase {
|
||||
block_header: BlockHeader,
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
|
|
@ -99,6 +99,7 @@
|
|||
//---------------------------------------------------------------------------------------------------- Use
|
||||
mod binary_string;
|
||||
mod constants;
|
||||
mod defaults;
|
||||
mod macros;
|
||||
mod status;
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ macro_rules! define_request_and_response {
|
|||
// And any fields.
|
||||
$(
|
||||
$( #[$request_field_attr:meta] )*
|
||||
$request_field:ident: $request_field_type:ty,
|
||||
$request_field:ident: $request_field_type:ty $(= $request_field_type_default:expr)?,
|
||||
)*
|
||||
},
|
||||
|
||||
|
@ -73,7 +73,7 @@ macro_rules! define_request_and_response {
|
|||
// And any fields.
|
||||
$(
|
||||
$( #[$response_field_attr:meta] )*
|
||||
$response_field:ident: $response_field_type:ty,
|
||||
$response_field:ident: $response_field_type:ty $(= $response_field_type_default:expr)?,
|
||||
)*
|
||||
}
|
||||
) => { paste::paste! {
|
||||
|
@ -91,7 +91,7 @@ macro_rules! define_request_and_response {
|
|||
[<$type_name Request>] {
|
||||
$(
|
||||
$( #[$request_field_attr] )*
|
||||
$request_field: $request_field_type,
|
||||
$request_field: $request_field_type $(= $request_field_type_default)?,
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ macro_rules! define_request_and_response {
|
|||
$response_base_type => [<$type_name Response>] {
|
||||
$(
|
||||
$( #[$response_field_attr] )*
|
||||
$response_field: $response_field_type,
|
||||
$response_field: $response_field_type $(= $response_field_type_default)?,
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ macro_rules! define_request {
|
|||
// And any fields.
|
||||
$(
|
||||
$( #[$request_field_attr:meta] )*
|
||||
$request_field:ident: $request_field_type:ty,
|
||||
$request_field:ident: $request_field_type:ty $(= $request_field_type_default:expr)?,
|
||||
)*
|
||||
}
|
||||
) => {
|
||||
|
@ -164,7 +164,7 @@ macro_rules! define_request {
|
|||
::cuprate_epee_encoding::epee_object! {
|
||||
$request_type_name,
|
||||
$(
|
||||
$request_field: $request_field_type,
|
||||
$request_field: $request_field_type $(= $request_field_type_default)?,
|
||||
)*
|
||||
}
|
||||
};
|
||||
|
@ -181,7 +181,7 @@ macro_rules! define_response {
|
|||
// And any fields.
|
||||
$(
|
||||
$( #[$response_field_attr:meta] )*
|
||||
$response_field:ident: $response_field_type:ty,
|
||||
$response_field:ident: $response_field_type:ty $(= $response_field_type_default:expr)?,
|
||||
)*
|
||||
}
|
||||
) => {
|
||||
|
@ -197,7 +197,7 @@ macro_rules! define_response {
|
|||
::cuprate_epee_encoding::epee_object! {
|
||||
$response_type_name,
|
||||
$(
|
||||
$response_field: $response_field_type,
|
||||
$response_field: $response_field_type $($response_field_type_default)?,
|
||||
)*
|
||||
}
|
||||
};
|
||||
|
@ -211,7 +211,7 @@ macro_rules! define_response {
|
|||
// And any fields.
|
||||
$(
|
||||
$( #[$response_field_attr:meta] )*
|
||||
$response_field:ident: $response_field_type:ty,
|
||||
$response_field:ident: $response_field_type:ty $(= $response_field_type_default:expr)?,
|
||||
)*
|
||||
}
|
||||
) => {
|
||||
|
@ -230,7 +230,7 @@ macro_rules! define_response {
|
|||
::cuprate_epee_encoding::epee_object! {
|
||||
$response_type_name,
|
||||
$(
|
||||
$response_field: $response_field_type,
|
||||
$response_field: $response_field_type $(= $response_field_type_default)?,
|
||||
)*
|
||||
!flatten: base: $response_base_type,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue