From e6d57099635b7446f7fac336526c95f06a83f226 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Sun, 7 Jul 2024 20:22:26 -0400 Subject: [PATCH] other: `StartMining`, `StopMining`, `MiningStatus`, `GetPeerList`, `SetLogHashRate`, `SetLogLevel` --- rpc/types/src/defaults.rs | 12 ++++++ rpc/types/src/json.rs | 4 +- rpc/types/src/misc.rs | 90 +++++++++++++++++++++------------------ rpc/types/src/other.rs | 89 +++++++++++++++++++++++++++++++++++++- 4 files changed, 151 insertions(+), 44 deletions(-) diff --git a/rpc/types/src/defaults.rs b/rpc/types/src/defaults.rs index 277c184..bf64d3e 100644 --- a/rpc/types/src/defaults.rs +++ b/rpc/types/src/defaults.rs @@ -53,6 +53,18 @@ pub(crate) const fn default_u64() -> u64 { 0 } +/// Default [`u8`] used in request/response types. +#[inline] +pub(crate) const fn default_u32() -> u32 { + 0 +} + +/// Default [`u8`] used in request/response types. +#[inline] +pub(crate) const fn default_u16() -> u16 { + 0 +} + /// Default [`u8`] used in request/response types. #[inline] pub(crate) const fn default_u8() -> u8 { diff --git a/rpc/types/src/json.rs b/rpc/types/src/json.rs index dd2d9f1..3b610de 100644 --- a/rpc/types/src/json.rs +++ b/rpc/types/src/json.rs @@ -11,7 +11,7 @@ use crate::{ macros::define_request_and_response, misc::{ AuxPow, BlockHeader, ChainInfo, ConnectionInfo, GetBan, HardforkEntry, HistogramEntry, - OutputDistributionData, Peer, SetBan, Span, Status, TxBacklogEntry, + OutputDistributionData, SetBan, Span, Status, SyncInfoPeer, TxBacklogEntry, }, }; @@ -531,7 +531,7 @@ define_request_and_response! { next_needed_pruning_seed: u32, overview: String, // TODO: This is a `std::list` in `monerod` because...? - peers: Vec, + peers: Vec, // TODO: This is a `std::list` in `monerod` because...? spans: Vec, target_height: u64, diff --git a/rpc/types/src/misc.rs b/rpc/types/src/misc.rs index 3e507e1..facf671 100644 --- a/rpc/types/src/misc.rs +++ b/rpc/types/src/misc.rs @@ -28,6 +28,7 @@ use crate::{ CORE_RPC_STATUS_BUSY, CORE_RPC_STATUS_NOT_MINING, CORE_RPC_STATUS_OK, CORE_RPC_STATUS_PAYMENT_REQUIRED, CORE_RPC_STATUS_UNKNOWN, }, + defaults::{default_u16, default_u32}, macros::monero_definition_link, }; @@ -50,11 +51,14 @@ macro_rules! define_struct_and_impl_epee { // And any fields. $( $( #[$field_attr:meta] )* // Field attributes - $field_name:ident: $field_type:ty, + // Field name => the type => optional `epee_object` default value. + $field_name:ident: $field_type:ty $(= $field_default:expr)?, )* } ) => { $( #[$struct_attr] )* + #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct $struct_name { $( $( #[$field_attr] )* @@ -66,7 +70,7 @@ macro_rules! define_struct_and_impl_epee { epee_object! { $struct_name, $( - $field_name: $field_type, + $field_name: $field_type $(= $field_default)?, )* } }; @@ -86,8 +90,6 @@ define_struct_and_impl_epee! { /// - [`crate::json::GetBlockHeaderByHeightResponse`] /// - [`crate::json::GetBlockHeadersRangeResponse`] /// - [`crate::json::GetBlockResponse`] - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] BlockHeader { block_size: u64, block_weight: u64, @@ -121,8 +123,6 @@ define_struct_and_impl_epee! { 47..=116 )] /// Used in [`crate::json::GetConnectionsResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] ConnectionInfo { address: String, address_type: u8, @@ -160,8 +160,6 @@ define_struct_and_impl_epee! { 2034..=2047 )] /// Used in [`crate::json::SetBansRequest`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] SetBan { host: String, ip: u32, @@ -177,8 +175,6 @@ define_struct_and_impl_epee! { 1999..=2010 )] /// Used in [`crate::json::GetBansResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] GetBan { host: String, ip: u32, @@ -192,9 +188,8 @@ define_struct_and_impl_epee! { "rpc/core_rpc_server_commands_defs.h", 2139..=2156 )] + #[derive(Copy)] /// 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, @@ -209,9 +204,8 @@ define_struct_and_impl_epee! { "rpc/core_rpc_server_commands_defs.h", 2180..=2191 )] + #[derive(Copy)] /// 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, @@ -225,8 +219,6 @@ define_struct_and_impl_epee! { 2289..=2310 )] /// Used in [`crate::json::GetAlternateChainsResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] ChainInfo { block_hash: String, block_hashes: Vec, @@ -246,9 +238,7 @@ define_struct_and_impl_epee! { 2393..=2400 )] /// Used in [`crate::json::SyncInfoResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] - Peer { + SyncInfoPeer { info: ConnectionInfo, } } @@ -260,8 +250,6 @@ define_struct_and_impl_epee! { 2402..=2421 )] /// Used in [`crate::json::SyncInfoResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] Span { connection_id: String, nblocks: u64, @@ -279,9 +267,8 @@ define_struct_and_impl_epee! { "rpc/core_rpc_server_commands_defs.h", 1637..=1642 )] + #[derive(Copy)] /// Used in [`crate::json::GetTransactionPoolBacklogResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] TxBacklogEntry { weight: u64, fee: u64, @@ -296,8 +283,6 @@ define_struct_and_impl_epee! { 45..=50 )] /// Used in [`crate::json::GetOutputDistributionResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] OutputDistributionData { distribution: Vec, start_height: u64, @@ -314,8 +299,6 @@ define_struct_and_impl_epee! { /// Used in [`crate::json::GetMinerDataResponse`]. /// /// Note that this is different than [`crate::misc::TxBacklogEntry`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] GetMinerDataTxBacklogEntry { id: String, weight: u64, @@ -330,8 +313,6 @@ define_struct_and_impl_epee! { 1070..=1079 )] /// Used in [`crate::json::AddAuxPowRequest`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] AuxPow { id: String, hash: String, @@ -345,8 +326,6 @@ define_struct_and_impl_epee! { 192..=199 )] /// Used in [`crate::bin::GetBlocksResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] TxOutputIndices { indices: Vec, } @@ -359,8 +338,6 @@ define_struct_and_impl_epee! { 201..=208 )] /// Used in [`crate::bin::GetBlocksResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] BlockOutputIndices { indices: Vec, } @@ -373,8 +350,6 @@ define_struct_and_impl_epee! { 210..=221 )] /// Used in [`crate::bin::GetBlocksResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] PoolTxInfo { tx_hash: [u8; 32], tx_blob: String, @@ -389,8 +364,6 @@ define_struct_and_impl_epee! { 121..=131 )] /// Used in [`crate::bin::GetBlocksResponse`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] TxBlobEntry { blob: String, prunable_hash: [u8; 32], @@ -403,9 +376,8 @@ define_struct_and_impl_epee! { "rpc/core_rpc_server_commands_defs.h", 512..=521 )] + #[derive(Copy)] /// Used in [`crate::bin::GetOutsRequest`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] GetOutputsOut { amount: u64, index: u64, @@ -418,9 +390,8 @@ define_struct_and_impl_epee! { "rpc/core_rpc_server_commands_defs.h", 538..=553 )] + #[derive(Copy)] /// Used in [`crate::bin::GetOutsRequest`]. - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] OutKey { key: u8, // TODO: crypto::public_key, mask: u8, // TODO: rct::key, @@ -430,6 +401,43 @@ define_struct_and_impl_epee! { } } +define_struct_and_impl_epee! { + #[doc = monero_definition_link!( + cc73fe71162d564ffda8e549b79a350bca53c454, + "rpc/core_rpc_server_commands_defs.h", + 1335..=1367 + )] + /// Used in [`crate::other::GetPeerListResponse`]. + Peer { + id: u64, + host: String, + ip: u32, + port: u16, + #[cfg_attr(feature = "serde", serde(default = "default_u16"))] + rpc_port: u16 = default_u16(), + #[cfg_attr(feature = "serde", serde(default = "default_u32"))] + rpc_credits_per_hash: u32 = default_u32(), + last_seen: u64, + #[cfg_attr(feature = "serde", serde(default = "default_u32"))] + pruning_seed: u32 = default_u32(), + } +} + +define_struct_and_impl_epee! { + #[doc = monero_definition_link!( + cc73fe71162d564ffda8e549b79a350bca53c454, + "rpc/core_rpc_server_commands_defs.h", + 1398..=1417 + )] + /// Used in [`crate::other::GetPeerListResponse`]. + PublicNode { + host: String, + last_seen: u64, + rpc_port: u16, + rpc_credits_per_hash: u32, + } +} + //---------------------------------------------------------------------------------------------------- TODO // TODO - weird types. diff --git a/rpc/types/src/other.rs b/rpc/types/src/other.rs index c673ddf..7f40532 100644 --- a/rpc/types/src/other.rs +++ b/rpc/types/src/other.rs @@ -8,7 +8,7 @@ use crate::{ base::{AccessResponseBase, ResponseBase}, defaults::{default_bool, default_bool_true}, macros::define_request_and_response, - misc::TxEntry, + misc::{Peer, TxEntry}, }; //---------------------------------------------------------------------------------------------------- TODO @@ -102,6 +102,54 @@ define_request_and_response! { } } +define_request_and_response! { + start_mining, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 665..=691, + StartMining, + Request { + miner_address: String, + threads_count: u64, + do_background_mining: bool, + ignore_battery: bool, + }, + ResponseBase {} +} + +define_request_and_response! { + stop_mining, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 825..=843, + StopMining, + Request {}, + ResponseBase {} +} + +define_request_and_response! { + mining_status, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 846..=895, + MiningStatus, + Request {}, + ResponseBase { + active: bool, + address: String, + bg_idle_threshold: u8, + bg_ignore_battery: bool, + bg_min_idle_seconds: u8, + bg_target: u8, + block_reward: u64, + block_target: u32, + difficulty: u64, + difficulty_top64: u64, + is_background_mining_enabled: bool, + pow_algorithm: String, + speed: u64, + threads_count: u32, + wide_difficulty: String, + } +} + define_request_and_response! { save_bc, cc73fe71162d564ffda8e549b79a350bca53c454 => @@ -111,6 +159,45 @@ define_request_and_response! { ResponseBase {} } +define_request_and_response! { + get_peer_list, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 1369..=1417, + GetPeerList, + Request { + #[cfg_attr(feature = "serde", serde(default = "default_bool_true"))] + public_only: bool = default_bool_true(), + #[cfg_attr(feature = "serde", serde(default = "default_bool"))] + include_blocked: bool = default_bool(), + }, + ResponseBase { + white_list: Vec, + gray_list: Vec, + } +} + +define_request_and_response! { + set_log_hash_rate, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 1450..=1470, + SetLogHashRate, + Request { + visible: bool, + }, + ResponseBase {} +} + +define_request_and_response! { + set_log_level, + cc73fe71162d564ffda8e549b79a350bca53c454 => + core_rpc_server_commands_defs.h => 1450..=1470, + SetLogLevel, + Request { + level: u8, + }, + ResponseBase {} +} + //---------------------------------------------------------------------------------------------------- Tests #[cfg(test)] mod test {