Compare commits

...

4 commits

Author SHA1 Message Date
hinto.janai
57a98e58a0
json: add FlushCache, AddAuxPow 2024-07-04 20:52:42 -04:00
hinto.janai
6f1289507f
json: add GetMinerData, PruneBlockchain, CalcPow 2024-07-04 20:41:06 -04:00
hinto.janai
e19dfb40ee
json: add GetTransactionPoolBacklog, GetOutputDistribution 2024-07-04 17:33:03 -04:00
hinto.janai
32730272ea
json: add SyncInfo 2024-07-03 20:34:45 -04:00
5 changed files with 253 additions and 6 deletions

View file

@ -59,7 +59,8 @@ values inside JSON strings, for example:
`binary` here is (de)serialized as a normal [`String`]. In order to be clear on which fields contain binary data, the struct fields that have them will use [`crate::BinaryString`] instead of [`String`].
TODO: list the specific types.
- TODO: list the specific types.
- TODO: we need to figure out a type that (de)serializes correctly, `String` errors with `serde_json`
# Feature flags
List of feature flags for `cuprate-rpc-types`.

View file

@ -3,7 +3,7 @@
//---------------------------------------------------------------------------------------------------- Import
//---------------------------------------------------------------------------------------------------- BinaryString
/// TODO
/// TODO: we need to figure out a type that (de)serializes correctly, `String` errors with `serde_json`
///
/// ```rust
/// use serde::Deserialize;

View file

@ -8,8 +8,11 @@ use crate::{
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,
misc::{
AuxPow, BlockHeader, ChainInfo, ConnectionInfo, GetBan, HardforkEntry, HistogramEntry,
Peer, SetBan, Span, TxBacklogEntry,
},
OutputDistributionData, Status,
};
//---------------------------------------------------------------------------------------------------- Struct definitions
@ -105,6 +108,7 @@ define_request_and_response! {
// type alias to `()` instead of a `struct`.
Request {},
#[derive(Copy)]
ResponseBase {
count: u64,
}
@ -115,7 +119,6 @@ define_request_and_response! {
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 935..=939,
OnGetBlockHash,
#[derive(Copy)]
/// ```rust
/// use serde_json::*;
/// use cuprate_rpc_types::json::*;
@ -126,6 +129,7 @@ define_request_and_response! {
/// ```
#[cfg_attr(feature = "serde", serde(transparent))]
#[repr(transparent)]
#[derive(Copy)]
Request {
// This is `std::vector<u64>` in `monerod` but
// it must be a 1 length array or else it will error.
@ -201,6 +205,7 @@ define_request_and_response! {
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 1214..=1238,
GetLastBlockHeader,
#[derive(Copy)]
Request {
#[cfg_attr(feature = "serde", serde(default = "default_bool"))]
fill_pow_hash: bool = default_bool(),
@ -232,6 +237,7 @@ define_request_and_response! {
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 1271..=1296,
GetBlockHeaderByHeight,
#[derive(Copy)]
Request {
height: u64,
#[cfg_attr(feature = "serde", serde(default = "default_bool"))]
@ -247,6 +253,7 @@ define_request_and_response! {
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 1756..=1783,
GetBlockHeadersRange,
#[derive(Copy)]
Request {
start_height: u64,
end_height: u64,
@ -394,6 +401,7 @@ define_request_and_response! {
Request {
address: String,
},
#[derive(Copy)]
Response {
banned: bool,
seconds: u32,
@ -410,6 +418,7 @@ define_request_and_response! {
#[cfg_attr(feature = "serde", serde(default = "default_vec"))]
txids: Vec<String> = default_vec::<String>(),
},
#[derive(Copy)]
#[cfg_attr(feature = "serde", serde(transparent))]
#[repr(transparent)]
Response {
@ -504,6 +513,7 @@ define_request_and_response! {
Request {
txids: Vec<String>,
},
#[derive(Copy)]
#[cfg_attr(feature = "serde", serde(transparent))]
#[repr(transparent)]
Response {
@ -511,6 +521,139 @@ define_request_and_response! {
}
}
define_request_and_response! {
sync_info,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 2383..=2443,
SyncInfo,
Request {},
AccessResponseBase {
height: u64,
next_needed_pruning_seed: u32,
overview: String,
// TODO: This is a `std::list` in `monerod` because...?
peers: Vec<Peer>,
// TODO: This is a `std::list` in `monerod` because...?
spans: Vec<Span>,
target_height: u64,
}
}
define_request_and_response! {
get_txpool_backlog,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 1637..=1664,
GetTransactionPoolBacklog,
Request {},
ResponseBase {
backlog: Vec<TxBacklogEntry>,
}
}
define_request_and_response! {
get_output_distribution,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 2445..=2520,
GetOutputDistribution,
Request {
amounts: Vec<u64>,
binary: bool,
compress: bool,
cumulative: bool,
from_height: u64,
to_height: u64,
},
/// TODO: this request has custom serde:
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server_commands_defs.h#L2468-L2508>
AccessResponseBase {
distributions: Vec<OutputDistributionData>,
}
}
define_request_and_response! {
get_miner_data,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 996..=1044,
GetMinerData,
Request {},
ResponseBase {
major_version: u8,
height: u64,
prev_id: String,
seed_hash: String,
difficulty: String,
median_weight: u64,
already_generated_coins: u64,
}
}
define_request_and_response! {
prune_blockchain,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 2747..=2772,
PruneBlockchain,
#[derive(Copy)]
Request {
#[cfg_attr(feature = "serde", serde(default = "default_bool"))]
check: bool = default_bool(),
},
#[derive(Copy)]
ResponseBase {
pruned: bool,
pruning_seed: u32,
}
}
define_request_and_response! {
calc_pow,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 1046..=1066,
CalcPow,
Request {
major_version: u8,
height: u64,
block_blob: String,
seed_hash: String,
},
#[cfg_attr(feature = "serde", serde(transparent))]
#[repr(transparent)]
Response {
pow_hash: String,
}
}
define_request_and_response! {
flush_cache,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 2774..=2796,
FlushCache,
Request {
#[cfg_attr(feature = "serde", serde(default = "default_bool"))]
bad_txs: bool = default_bool(),
#[cfg_attr(feature = "serde", serde(default = "default_bool"))]
bad_blocks: bool = default_bool(),
},
ResponseBase {}
}
define_request_and_response! {
add_aux_pow,
cc73fe71162d564ffda8e549b79a350bca53c454 =>
core_rpc_server_commands_defs.h => 1068..=1112,
AddAuxPow,
Request {
blocktemplate_blob: String,
aux_pow: Vec<AuxPow>,
},
ResponseBase {
blocktemplate_blob: String,
blockhashing_blob: String,
merkle_root: String,
merkle_tree_depth: u64,
aux_pow: Vec<AuxPow>,
}
}
//---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)]
mod test {

View file

@ -125,5 +125,6 @@ pub mod other;
mod misc;
pub use misc::{
BlockHeader, ChainInfo, ConnectionInfo, GetBan, HardforkEntry, HistogramEntry, SetBan,
AuxPow, BlockHeader, ChainInfo, ConnectionInfo, GetBan, GetMinerDataTxBacklogEntry,
HardforkEntry, HistogramEntry, OutputDistributionData, Peer, SetBan, Span, TxBacklogEntry,
};

View file

@ -214,6 +214,108 @@ define_struct_and_impl_epee! {
}
}
define_struct_and_impl_epee! {
#[doc = monero_definition_link!(
cc73fe71162d564ffda8e549b79a350bca53c454,
"rpc/core_rpc_server_commands_defs.h",
2393..=2400
)]
/// Used in [`crate::json::SyncInfoResponse`].
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Peer {
info: ConnectionInfo,
}
}
define_struct_and_impl_epee! {
#[doc = monero_definition_link!(
cc73fe71162d564ffda8e549b79a350bca53c454,
"rpc/core_rpc_server_commands_defs.h",
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,
rate: u32,
remote_address: String,
size: u64,
speed: u32,
start_block_height: u64,
}
}
define_struct_and_impl_epee! {
#[doc = monero_definition_link!(
cc73fe71162d564ffda8e549b79a350bca53c454,
"rpc/core_rpc_server_commands_defs.h",
1637..=1642
)]
/// Used in [`crate::json::GetTransactionPoolBacklog`].
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
TxBacklogEntry {
weight: u64,
fee: u64,
time_in_pool: u64,
}
}
define_struct_and_impl_epee! {
#[doc = monero_definition_link!(
cc73fe71162d564ffda8e549b79a350bca53c454,
"rpc/rpc_handler.h",
45..=50
)]
/// Used in [`crate::json::GetOutputDistribution`].
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
OutputDistributionData {
distribution: Vec<u64>,
start_height: u64,
base: u64,
}
}
define_struct_and_impl_epee! {
#[doc = monero_definition_link!(
cc73fe71162d564ffda8e549b79a350bca53c454,
"rpc/core_rpc_server_commands_defs.h",
1016..=1027
)]
/// 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,
fee: u64,
}
}
define_struct_and_impl_epee! {
#[doc = monero_definition_link!(
cc73fe71162d564ffda8e549b79a350bca53c454,
"rpc/core_rpc_server_commands_defs.h",
1070..=1079
)]
/// Used in [`crate::json::GetAuxPowRequest`].
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
AuxPow {
id: String,
hash: String,
}
}
//---------------------------------------------------------------------------------------------------- Custom serde
// This section is for `struct`s that have custom (de)serialization code.
//---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)]
mod test {