mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-11-16 15:58:14 +00:00
Compare commits
8 commits
e1dcd8e724
...
255c5540aa
Author | SHA1 | Date | |
---|---|---|---|
|
255c5540aa | ||
|
b592ee0bf8 | ||
|
ea7f6fb2a5 | ||
|
4bad15965e | ||
|
352ab2015a | ||
|
e5c833c996 | ||
|
d0981da311 | ||
|
72bd1673d6 |
7 changed files with 697 additions and 47 deletions
|
@ -18,28 +18,13 @@ use serde::{Deserialize, Serialize};
|
|||
#[cfg(feature = "epee")]
|
||||
use cuprate_epee_encoding::epee_object;
|
||||
|
||||
use crate::Status;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Macro
|
||||
/// Link the original `monerod` definition for RPC base types.
|
||||
macro_rules! monero_rpc_base_link {
|
||||
($start:literal..=$end:literal) => {
|
||||
concat!(
|
||||
"[Definition](https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server_commands_defs.h#L",
|
||||
stringify!($start),
|
||||
"-L",
|
||||
stringify!($end),
|
||||
")."
|
||||
)
|
||||
};
|
||||
}
|
||||
use crate::{macros::monero_definition_link, Status};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Requests
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Responses
|
||||
#[doc = monero_definition_link!(cc73fe71162d564ffda8e549b79a350bca53c454, "rpc/core_rpc_server_commands_defs.h", 101..=112)]
|
||||
/// The most common base for responses.
|
||||
///
|
||||
#[doc = monero_rpc_base_link!(101..=112)]
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct ResponseBase {
|
||||
|
@ -58,9 +43,8 @@ epee_object! {
|
|||
untrusted: bool,
|
||||
}
|
||||
|
||||
#[doc = monero_definition_link!(cc73fe71162d564ffda8e549b79a350bca53c454, "rpc/core_rpc_server_commands_defs.h", 124..=136)]
|
||||
/// A base for RPC response types that support RPC payment.
|
||||
///
|
||||
#[doc = monero_rpc_base_link!(124..=136)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct AccessResponseBase {
|
||||
|
|
47
rpc/types/src/defaults.rs
Normal file
47
rpc/types/src/defaults.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
//! TODO
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
use std::borrow::Cow;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- TODO
|
||||
/// TODO
|
||||
#[inline]
|
||||
pub(crate) const fn default_bool() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// TODO
|
||||
#[inline]
|
||||
pub(crate) const fn default_cow_str() -> Cow<'static, str> {
|
||||
Cow::Borrowed("")
|
||||
}
|
||||
|
||||
/// TODO
|
||||
#[inline]
|
||||
pub(crate) const fn default_string() -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
/// TODO
|
||||
#[inline]
|
||||
pub(crate) const fn default_height() -> u64 {
|
||||
0
|
||||
}
|
||||
|
||||
/// TODO
|
||||
#[inline]
|
||||
pub(crate) const fn default_vec<T>() -> Vec<T> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// TODO
|
||||
#[inline]
|
||||
pub(crate) const fn default_u64() -> u64 {
|
||||
0
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::*;
|
||||
}
|
14
rpc/types/src/free.rs
Normal file
14
rpc/types/src/free.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
//! Macros.
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- TODO
|
||||
/// TODO
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)] // serde needs `&`
|
||||
pub(crate) const fn is_zero(u: &u64) -> bool {
|
||||
*u == 0
|
||||
}
|
||||
|
||||
/// TODO
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)] // serde needs `&`
|
||||
pub(crate) const fn is_one(u: &u64) -> bool {
|
||||
*u == 1
|
||||
}
|
|
@ -3,7 +3,14 @@
|
|||
//! <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::{default_bool, default_height, default_string, default_u64, default_vec},
|
||||
free::{is_one, is_zero},
|
||||
macros::define_request_and_response,
|
||||
misc::{BlockHeader, ChainInfo, ConnectionInfo, GetBan, HardforkEntry, HistogramEntry, SetBan},
|
||||
Status,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Struct definitions
|
||||
// This generates 2 structs:
|
||||
|
@ -45,10 +52,10 @@ define_request_and_response! {
|
|||
// $FIELD_NAME: $FIELD_TYPE,
|
||||
// ```
|
||||
// The struct generated and all fields are `pub`.
|
||||
extra_nonce: String,
|
||||
prev_block: String,
|
||||
reserve_size: u64,
|
||||
wallet_address: String,
|
||||
prev_block: String,
|
||||
extra_nonce: String,
|
||||
},
|
||||
|
||||
// The base response type.
|
||||
|
@ -72,18 +79,18 @@ define_request_and_response! {
|
|||
// status: crate::Status,
|
||||
// untrusted: bool,
|
||||
// ```
|
||||
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,
|
||||
blocktemplate_blob: String,
|
||||
difficulty_top64: u64,
|
||||
difficulty: u64,
|
||||
expected_reward: u64,
|
||||
height: u64,
|
||||
next_seed_hash: String,
|
||||
prev_hash: String,
|
||||
reserved_offset: u64,
|
||||
seed_hash: String,
|
||||
seed_height: u64,
|
||||
wide_difficulty: String,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,12 +116,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<u64>` 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 +179,338 @@ define_request_and_response! {
|
|||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
generateblocks,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 1130..=1161,
|
||||
GenerateBlocks,
|
||||
Request {
|
||||
amount_of_blocks: u64,
|
||||
prev_block: String,
|
||||
starting_nonce: u32,
|
||||
wallet_address: String,
|
||||
},
|
||||
ResponseBase {
|
||||
blocks: Vec<String>,
|
||||
height: u64,
|
||||
}
|
||||
}
|
||||
|
||||
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 = "default_bool"))]
|
||||
fill_pow_hash: bool = default_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 = "default_bool"))]
|
||||
fill_pow_hash: bool = default_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 = "default_bool"))]
|
||||
fill_pow_hash: bool = default_bool(),
|
||||
},
|
||||
AccessResponseBase {
|
||||
block_header: BlockHeader,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
get_block_headers_range,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 1756..=1783,
|
||||
GetBlockHeadersRange,
|
||||
Request {
|
||||
start_height: u64,
|
||||
end_height: u64,
|
||||
#[cfg_attr(feature = "serde", serde(default = "default_bool"))]
|
||||
fill_pow_hash: bool = default_bool(),
|
||||
},
|
||||
AccessResponseBase {
|
||||
headers: Vec<BlockHeader>,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
get_block,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 1298..=1313,
|
||||
GetBlock,
|
||||
Request {
|
||||
// `monerod` has both `hash` and `height` fields.
|
||||
// In the RPC handler, if `hash.is_empty()`, it will use it, else, it uses `height`.
|
||||
// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2674>
|
||||
#[cfg_attr(feature = "serde", serde(default = "default_string"))]
|
||||
hash: String = default_string(),
|
||||
#[cfg_attr(feature = "serde", serde(default = "default_height"))]
|
||||
height: u64 = default_height(),
|
||||
#[cfg_attr(feature = "serde", serde(default = "default_bool"))]
|
||||
fill_pow_hash: bool = default_bool(),
|
||||
},
|
||||
AccessResponseBase {
|
||||
blob: String,
|
||||
block_header: BlockHeader,
|
||||
json: String, // TODO: this should be defined in a struct, it has many fields.
|
||||
miner_tx_hash: String,
|
||||
tx_hashes: Vec<String>,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
get_connections,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 1734..=1754,
|
||||
GetConnections,
|
||||
Request {},
|
||||
ResponseBase {
|
||||
// TODO: This is a `std::list` in `monerod` because...?
|
||||
connections: Vec<ConnectionInfo>,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
get_info,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 693..=789,
|
||||
GetInfo,
|
||||
Request {},
|
||||
AccessResponseBase {
|
||||
adjusted_time: u64,
|
||||
alt_blocks_count: u64,
|
||||
block_size_limit: u64,
|
||||
block_size_median: u64,
|
||||
block_weight_limit: u64,
|
||||
block_weight_median: u64,
|
||||
bootstrap_daemon_address: String,
|
||||
busy_syncing: bool,
|
||||
cumulative_difficulty_top64: u64,
|
||||
cumulative_difficulty: u64,
|
||||
database_size: u64,
|
||||
difficulty_top64: u64,
|
||||
difficulty: u64,
|
||||
free_space: u64,
|
||||
grey_peerlist_size: u64,
|
||||
height: u64,
|
||||
height_without_bootstrap: u64,
|
||||
incoming_connections_count: u64,
|
||||
mainnet: bool,
|
||||
nettype: String,
|
||||
offline: bool,
|
||||
outgoing_connections_count: u64,
|
||||
restricted: bool,
|
||||
rpc_connections_count: u64,
|
||||
stagenet: bool,
|
||||
start_time: u64,
|
||||
synchronized: bool,
|
||||
target_height: u64,
|
||||
target: u64,
|
||||
testnet: bool,
|
||||
top_block_hash: String,
|
||||
tx_count: u64,
|
||||
tx_pool_size: u64,
|
||||
update_available: bool,
|
||||
version: String,
|
||||
was_bootstrap_ever_used: bool,
|
||||
white_peerlist_size: u64,
|
||||
wide_cumulative_difficulty: String,
|
||||
wide_difficulty: String,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
hard_fork_info,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 1958..=1995,
|
||||
HardForkInfo,
|
||||
Request {},
|
||||
AccessResponseBase {
|
||||
earliest_height: u64,
|
||||
enabled: bool,
|
||||
state: u32,
|
||||
threshold: u32,
|
||||
version: u8,
|
||||
votes: u32,
|
||||
voting: u8,
|
||||
window: u32,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
set_bans,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 2032..=2067,
|
||||
SetBans,
|
||||
Request {
|
||||
bans: Vec<SetBan>,
|
||||
},
|
||||
ResponseBase {}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
get_bans,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 1997..=2030,
|
||||
GetBans,
|
||||
Request {},
|
||||
ResponseBase {
|
||||
bans: Vec<GetBan>,
|
||||
}
|
||||
}
|
||||
|
||||
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<String> = default_vec::<String>(),
|
||||
},
|
||||
#[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<u64>,
|
||||
min_count: u64,
|
||||
max_count: u64,
|
||||
unlocked: bool,
|
||||
recent_cutoff: u64,
|
||||
},
|
||||
AccessResponseBase {
|
||||
histogram: Vec<HistogramEntry>,
|
||||
}
|
||||
}
|
||||
|
||||
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<HardforkEntry> = default_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
get_fee_estimate,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 2250..=2277,
|
||||
GetFeeEstimate,
|
||||
Request {},
|
||||
AccessResponseBase {
|
||||
fee: u64,
|
||||
fees: Vec<u64>,
|
||||
#[serde(skip_serializing_if = "is_one")]
|
||||
quantization_mask: u64,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
get_alternate_chains,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 2279..=2310,
|
||||
GetAlternateChains,
|
||||
Request {},
|
||||
ResponseBase {
|
||||
chains: Vec<ChainInfo>,
|
||||
}
|
||||
}
|
||||
|
||||
define_request_and_response! {
|
||||
relay_tx,
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454 =>
|
||||
core_rpc_server_commands_defs.h => 2361..=2381,
|
||||
RelayTx,
|
||||
Request {
|
||||
txids: Vec<String>,
|
||||
},
|
||||
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||
#[repr(transparent)]
|
||||
Response {
|
||||
status: Status,
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
unused_allocation,
|
||||
coherence_leak_check,
|
||||
while_true,
|
||||
clippy::missing_docs_in_private_items,
|
||||
|
||||
// Maybe can be put into `#[deny]`.
|
||||
unconditional_recursion,
|
||||
|
@ -100,6 +99,8 @@
|
|||
//---------------------------------------------------------------------------------------------------- Use
|
||||
mod binary_string;
|
||||
mod constants;
|
||||
mod defaults;
|
||||
mod free;
|
||||
mod macros;
|
||||
mod status;
|
||||
|
||||
|
@ -121,3 +122,8 @@ pub mod json;
|
|||
#[cfg(feature = "other")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "other")))]
|
||||
pub mod other;
|
||||
|
||||
mod misc;
|
||||
pub use misc::{
|
||||
BlockHeader, ChainInfo, ConnectionInfo, GetBan, HardforkEntry, HistogramEntry, SetBan,
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
@ -288,3 +288,22 @@ macro_rules! define_request_and_response_doc {
|
|||
};
|
||||
}
|
||||
pub(crate) use define_request_and_response_doc;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Macro
|
||||
/// Link the original `monerod` definition for RPC base types.
|
||||
macro_rules! monero_definition_link {
|
||||
($commit:ident, $file_path:literal, $start:literal..=$end:literal) => {
|
||||
concat!(
|
||||
"[Definition](https://github.com/monero-project/monero/blob/",
|
||||
stringify!($commit),
|
||||
"/src/",
|
||||
stringify!($file_path),
|
||||
"#L",
|
||||
stringify!($start),
|
||||
"-L",
|
||||
stringify!($end),
|
||||
")."
|
||||
)
|
||||
};
|
||||
}
|
||||
pub(crate) use monero_definition_link;
|
||||
|
|
221
rpc/types/src/misc.rs
Normal file
221
rpc/types/src/misc.rs
Normal file
|
@ -0,0 +1,221 @@
|
|||
//! TODO
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Lints
|
||||
#![allow(
|
||||
missing_docs, // Docs are at: <https://www.getmonero.org/resources/developer-guides/daemon-rpc.html>
|
||||
clippy::struct_excessive_bools, // hey man, tell that to the people who wrote `monerod`
|
||||
)]
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[cfg(feature = "epee")]
|
||||
use cuprate_epee_encoding::epee_object;
|
||||
|
||||
use crate::macros::monero_definition_link;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Macros
|
||||
/// TODO
|
||||
macro_rules! define_struct_and_impl_epee {
|
||||
(
|
||||
$( #[$struct_attr:meta] )*
|
||||
$struct_name:ident {
|
||||
// And any fields.
|
||||
$(
|
||||
$( #[$field_attr:meta] )*
|
||||
$field_name:ident: $field_type:ty,
|
||||
)*
|
||||
}
|
||||
) => {
|
||||
$( #[$struct_attr] )*
|
||||
pub struct $struct_name {
|
||||
$(
|
||||
$( #[$field_attr] )*
|
||||
pub $field_name: $field_type,
|
||||
)*
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "epee")]
|
||||
epee_object! {
|
||||
$struct_name,
|
||||
$(
|
||||
$field_name: $field_type,
|
||||
)*
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Type Definitions
|
||||
define_struct_and_impl_epee! {
|
||||
#[doc = monero_definition_link!(
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454,
|
||||
"rpc/core_rpc_server_commands_defs.h",
|
||||
1163..=1212
|
||||
)]
|
||||
///
|
||||
/// Used in:
|
||||
/// - [`crate::json::GetLastBlockHeaderResponse`]
|
||||
/// - [`crate::json::GetBlockHeaderByHashResponse`]
|
||||
/// - [`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,
|
||||
cumulative_difficulty_top64: u64,
|
||||
cumulative_difficulty: u64,
|
||||
depth: u64,
|
||||
difficulty_top64: u64,
|
||||
difficulty: u64,
|
||||
hash: String,
|
||||
height: u64,
|
||||
long_term_weight: u64,
|
||||
major_version: u8,
|
||||
miner_tx_hash: String,
|
||||
minor_version: u8,
|
||||
nonce: u32,
|
||||
num_txes: u64,
|
||||
orphan_status: bool,
|
||||
pow_hash: String,
|
||||
prev_hash: String,
|
||||
reward: u64,
|
||||
timestamp: u64,
|
||||
wide_cumulative_difficulty: String,
|
||||
wide_difficulty: String,
|
||||
}
|
||||
}
|
||||
|
||||
define_struct_and_impl_epee! {
|
||||
#[doc = monero_definition_link!(
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454,
|
||||
"cryptonote_protocol/cryptonote_protocol_defs.h",
|
||||
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,
|
||||
avg_download: u64,
|
||||
avg_upload: u64,
|
||||
connection_id: String,
|
||||
current_download: u64,
|
||||
current_upload: u64,
|
||||
height: u64,
|
||||
host: String,
|
||||
incoming: bool,
|
||||
ip: String,
|
||||
live_time: u64,
|
||||
localhost: bool,
|
||||
local_ip: bool,
|
||||
peer_id: String,
|
||||
port: String,
|
||||
pruning_seed: u32,
|
||||
recv_count: u64,
|
||||
recv_idle_time: u64,
|
||||
rpc_credits_per_hash: u32,
|
||||
rpc_port: u16,
|
||||
send_count: u64,
|
||||
send_idle_time: u64,
|
||||
ssl: bool,
|
||||
state: String,
|
||||
support_flags: u32,
|
||||
}
|
||||
}
|
||||
|
||||
define_struct_and_impl_epee! {
|
||||
#[doc = monero_definition_link!(
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454,
|
||||
"rpc/core_rpc_server_commands_defs.h",
|
||||
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,
|
||||
ban: bool,
|
||||
seconds: u32,
|
||||
}
|
||||
}
|
||||
|
||||
define_struct_and_impl_epee! {
|
||||
#[doc = monero_definition_link!(
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454,
|
||||
"rpc/core_rpc_server_commands_defs.h",
|
||||
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,
|
||||
seconds: u32,
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
define_struct_and_impl_epee! {
|
||||
#[doc = monero_definition_link!(
|
||||
cc73fe71162d564ffda8e549b79a350bca53c454,
|
||||
"rpc/core_rpc_server_commands_defs.h",
|
||||
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<String>,
|
||||
difficulty: u64,
|
||||
difficulty_top64: u64,
|
||||
height: u64,
|
||||
length: u64,
|
||||
main_chain_parent_block: String,
|
||||
wide_difficulty: String,
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::*;
|
||||
}
|
Loading…
Reference in a new issue