diff --git a/rpc/types/src/defaults.rs b/rpc/types/src/defaults.rs index c16cdd6..86c778b 100644 --- a/rpc/types/src/defaults.rs +++ b/rpc/types/src/defaults.rs @@ -28,6 +28,18 @@ pub(crate) const fn default_height() -> u64 { 0 } +/// TODO +#[inline] +pub(crate) const fn default_vec() -> Vec { + Vec::new() +} + +/// TODO +#[inline] +pub(crate) const fn default_u64() -> u64 { + 0 +} + //---------------------------------------------------------------------------------------------------- Tests #[cfg(test)] mod test { diff --git a/rpc/types/src/free.rs b/rpc/types/src/free.rs new file mode 100644 index 0000000..045bdc6 --- /dev/null +++ b/rpc/types/src/free.rs @@ -0,0 +1,8 @@ +//! Macros. + +//---------------------------------------------------------------------------------------------------- TODO +/// TODO +#[allow(clippy::trivially_copy_pass_by_ref)] // serde needs `&` +pub(crate) const fn is_zero(u: &u64) -> bool { + *u == 0 +} diff --git a/rpc/types/src/json.rs b/rpc/types/src/json.rs index 1d27e07..a4009f8 100644 --- a/rpc/types/src/json.rs +++ b/rpc/types/src/json.rs @@ -5,9 +5,11 @@ //---------------------------------------------------------------------------------------------------- Import use crate::{ base::{AccessResponseBase, ResponseBase}, - defaults::{default_bool, default_height, default_string}, + defaults::{default_bool, default_height, default_string, default_u64, default_vec}, + free::is_zero, macros::define_request_and_response, - misc::{BlockHeader, ConnectionInfo, GetBan, SetBan}, + misc::{BlockHeader, ConnectionInfo, GetBan, HardforkEntry, HistogramEntry, SetBan}, + Status, }; //---------------------------------------------------------------------------------------------------- Struct definitions @@ -374,7 +376,7 @@ define_request_and_response! { define_request_and_response! { get_bans, cc73fe71162d564ffda8e549b79a350bca53c454 => - core_rpc_server_commands_defs.h => 2032..=2067, + core_rpc_server_commands_defs.h => 1997..=2030, GetBans, Request {}, ResponseBase { @@ -382,6 +384,93 @@ define_request_and_response! { } } +define_request_and_response! { + banned, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 2069..=2094, + Banned, + #[cfg_attr(feature = "serde", serde(transparent))] + #[repr(transparent)] + Request { + address: String, + }, + Response { + banned: bool, + seconds: u32, + status: Status, + } +} + +define_request_and_response! { + flush_txpool, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 2096..=2116, + FlushTransactionPool, + Request { + #[cfg_attr(feature = "serde", serde(default = "default_vec"))] + txids: Vec = default_vec::(), + }, + #[cfg_attr(feature = "serde", serde(transparent))] + #[repr(transparent)] + Response { + status: Status, + } +} + +define_request_and_response! { + get_output_histogram, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 2118..=2168, + GetOutputHistogram, + Request { + amounts: Vec, + min_count: u64, + max_count: u64, + unlocked: bool, + recent_cutoff: u64, + }, + AccessResponseBase { + histogram: Vec, + } +} + +define_request_and_response! { + get_coinbase_tx_sum, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 2213..=2248, + GetCoinbaseTxSum, + Request { + height: u64, + count: u64, + }, + AccessResponseBase { + emission_amount: u64, + emission_amount_top64: u64, + fee_amount: u64, + fee_amount_top64: u64, + wide_emission_amount: String, + wide_fee_amount: String, + } +} + +define_request_and_response! { + get_version, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 2170..=2211, + GetVersion, + Request {}, + ResponseBase { + version: u32, + release: bool, + #[serde(skip_serializing_if = "is_zero", default = "default_u64")] + current_height: u64 = default_u64(), + #[serde(skip_serializing_if = "is_zero", default = "default_u64")] + target_height: u64 = default_u64(), + #[serde(skip_serializing_if = "Vec::is_empty", default = "default_vec")] + hard_forks: Vec = default_vec(), + } +} + //---------------------------------------------------------------------------------------------------- Tests #[cfg(test)] mod test { diff --git a/rpc/types/src/lib.rs b/rpc/types/src/lib.rs index 85a2f2a..d644df3 100644 --- a/rpc/types/src/lib.rs +++ b/rpc/types/src/lib.rs @@ -100,6 +100,7 @@ mod binary_string; mod constants; mod defaults; +mod free; mod macros; mod status; diff --git a/rpc/types/src/misc.rs b/rpc/types/src/misc.rs index dca7e28..143e00e 100644 --- a/rpc/types/src/misc.rs +++ b/rpc/types/src/misc.rs @@ -163,6 +163,40 @@ define_struct_and_impl_epee! { } } +//---------------------------------------------------------------------------------------------------- HistogramEntry +define_struct_and_impl_epee! { + #[doc = monero_definition_link!( + cc73fe71162d564ffda8e549b79a350bca53c454, + "rpc/core_rpc_server_commands_defs.h", + 2139..=2156 + )] + /// Used in [`crate::json::GetOutputHistogramResponse`]. + #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + HistogramEntry { + amount: u64, + total_instances: u64, + unlocked_instances: u64, + recent_instances: u64, + } +} + +//---------------------------------------------------------------------------------------------------- HardforkEntry +define_struct_and_impl_epee! { + #[doc = monero_definition_link!( + cc73fe71162d564ffda8e549b79a350bca53c454, + "rpc/core_rpc_server_commands_defs.h", + 2180..=2191 + )] + /// Used in [`crate::json::GetVersionResponse`]. + #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + HardforkEntry { + height: u64, + hf_version: u8, + } +} + //---------------------------------------------------------------------------------------------------- Tests #[cfg(test)] mod test {