From 2104bb0e17db45a093164125f3a7f7ea342e57bd Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Thu, 5 Dec 2024 16:05:22 -0500 Subject: [PATCH] `cuprate_types::rpc`, `from` module for `cuprate_rpc_types` --- binaries/cuprated/Cargo.toml | 2 +- binaries/cuprated/src/rpc/bin.rs | 48 +- binaries/cuprated/src/rpc/json.rs | 6 +- .../cuprated/src/rpc/request/blockchain.rs | 4 +- .../src/rpc/request/blockchain_context.rs | 5 +- binaries/cuprated/src/rpc/request/txpool.rs | 31 +- consensus/context/src/lib.rs | 5 +- rpc/types/src/bin.rs | 4 +- rpc/types/src/from.rs | 380 ++++++++++++ rpc/types/src/lib.rs | 1 + rpc/types/src/misc/mod.rs | 19 +- rpc/types/src/misc/{misc.rs => types.rs} | 58 +- storage/blockchain/src/service/read.rs | 3 +- storage/txpool/src/service/interface.rs | 17 +- storage/txpool/src/service/read.rs | 15 + types/Cargo.toml | 6 +- types/src/blockchain.rs | 5 +- types/src/lib.rs | 10 +- .../types/src/misc => types/src}/pool_info.rs | 46 +- .../misc => types/src}/pool_info_extent.rs | 7 +- types/src/rpc.rs | 586 ++++++++++++++++++ types/src/types.rs | 112 ---- 22 files changed, 1132 insertions(+), 238 deletions(-) create mode 100644 rpc/types/src/from.rs rename rpc/types/src/misc/{misc.rs => types.rs} (92%) rename {rpc/types/src/misc => types/src}/pool_info.rs (75%) rename {rpc/types/src/misc => types/src}/pool_info_extent.rs (91%) create mode 100644 types/src/rpc.rs diff --git a/binaries/cuprated/Cargo.toml b/binaries/cuprated/Cargo.toml index 70a5c50..9f7a699 100644 --- a/binaries/cuprated/Cargo.toml +++ b/binaries/cuprated/Cargo.toml @@ -31,7 +31,7 @@ cuprate-txpool = { workspace = true } cuprate-database = { workspace = true, features = ["serde"] } cuprate-pruning = { workspace = true } cuprate-test-utils = { workspace = true } -cuprate-types = { workspace = true } +cuprate-types = { workspace = true, features = ["json"] } cuprate-json-rpc = { workspace = true } cuprate-rpc-interface = { workspace = true } cuprate-rpc-types = { workspace = true } diff --git a/binaries/cuprated/src/rpc/bin.rs b/binaries/cuprated/src/rpc/bin.rs index 87b4a53..d1b8f22 100644 --- a/binaries/cuprated/src/rpc/bin.rs +++ b/binaries/cuprated/src/rpc/bin.rs @@ -15,7 +15,7 @@ use cuprate_rpc_types::{ json::{GetOutputDistributionRequest, GetOutputDistributionResponse}, misc::RequestedInfo, }; -use cuprate_types::BlockCompleteEntry; +use cuprate_types::{BlockCompleteEntry, PoolInfoExtent}; use crate::rpc::{helper, request::blockchain, CupratedRpcHandler}; @@ -61,14 +61,44 @@ async fn get_blocks( RequestedInfo::PoolOnly => (false, true), }; + let pool_info_extent = PoolInfoExtent::None; + if get_pool { + let allow_sensitive = !state.is_restricted(); let max_tx_count = if state.is_restricted() { RESTRICTED_TRANSACTIONS_COUNT } else { usize::MAX }; - todo!(); + // bool incremental; + // std::vector> added_pool_txs; + // bool success = m_core.get_pool_info((time_t)req.pool_info_since, allow_sensitive, max_tx_count, added_pool_txs, res.remaining_added_pool_txids, res.removed_pool_txids, incremental); + // if (success) + // { + // res.added_pool_txs.clear(); + // if (m_rpc_payment) + // { + // CHECK_PAYMENT_SAME_TS(req, res, added_pool_txs.size() * COST_PER_TX + (res.remaining_added_pool_txids.size() + res.removed_pool_txids.size()) * COST_PER_POOL_HASH); + // } + // for (const auto &added_pool_tx: added_pool_txs) + // { + // COMMAND_RPC_GET_BLOCKS_FAST::pool_tx_info info; + // info.tx_hash = added_pool_tx.first; + // std::stringstream oss; + // binary_archive ar(oss); + // bool r = req.prune + // ? const_cast(added_pool_tx.second.tx).serialize_base(ar) + // : ::serialization::serialize(ar, const_cast(added_pool_tx.second.tx)); + // if (!r) + // { + // res.status = "Failed to serialize transaction"; + // return true; + // } + // info.tx_blob = oss.str(); + // info.double_spend_seen = added_pool_tx.second.double_spend_seen; + // res.added_pool_txs.push_back(std::move(info)); + // } } if get_blocks { @@ -79,11 +109,15 @@ async fn get_blocks( todo!(); } - // Ok(GetBlocksResponse { - // base: ResponseBase::OK, - // ..todo!() - // }) - Ok(todo!()) + Ok(GetBlocksResponse { + base: AccessResponseBase::OK, + blocks: todo!(), + start_height: todo!(), + current_height: todo!(), + output_indices: todo!(), + daemon_time: todo!(), + pool_info: todo!(), + }) } /// diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs index 54dac12..d82235e 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/json.rs @@ -669,7 +669,7 @@ async fn get_output_histogram( mut state: CupratedRpcHandler, request: GetOutputHistogramRequest, ) -> Result { - let input = cuprate_types::OutputHistogramInput { + let input = cuprate_types::rpc::OutputHistogramInput { amounts: request.amounts, min_count: request.min_count, max_count: request.max_count, @@ -1042,7 +1042,7 @@ fn add_aux_pow_inner( .map(|aux| { let id = helper::hex_to_hash(aux.id)?; let hash = helper::hex_to_hash(aux.hash)?; - Ok(cuprate_types::AuxPow { id, hash }) + Ok(cuprate_types::rpc::AuxPow { id, hash }) }) .collect::, Error>>()?; // Some of the code below requires that the @@ -1058,7 +1058,7 @@ fn add_aux_pow_inner( // } fn find_nonce( - aux_pow: &[cuprate_types::AuxPow], + aux_pow: &[cuprate_types::rpc::AuxPow], non_zero_len: NonZero, aux_pow_len: usize, ) -> Result<(u32, Box<[u32]>), Error> { diff --git a/binaries/cuprated/src/rpc/request/blockchain.rs b/binaries/cuprated/src/rpc/request/blockchain.rs index 003708d..32dd59e 100644 --- a/binaries/cuprated/src/rpc/request/blockchain.rs +++ b/binaries/cuprated/src/rpc/request/blockchain.rs @@ -13,8 +13,8 @@ use cuprate_blockchain::service::BlockchainReadHandle; use cuprate_helper::cast::{u64_to_usize, usize_to_u64}; use cuprate_types::{ blockchain::{BlockchainReadRequest, BlockchainResponse}, - Chain, ChainInfo, CoinbaseTxSum, ExtendedBlockHeader, OutputHistogramEntry, - OutputHistogramInput, OutputOnChain, + rpc::{ChainInfo, CoinbaseTxSum, OutputHistogramEntry, OutputHistogramInput}, + Chain, ExtendedBlockHeader, OutputOnChain, }; /// [`BlockchainReadRequest::Block`]. diff --git a/binaries/cuprated/src/rpc/request/blockchain_context.rs b/binaries/cuprated/src/rpc/request/blockchain_context.rs index 4fd650e..f2fc97f 100644 --- a/binaries/cuprated/src/rpc/request/blockchain_context.rs +++ b/binaries/cuprated/src/rpc/request/blockchain_context.rs @@ -8,7 +8,10 @@ use cuprate_consensus_context::{ BlockChainContext, BlockChainContextRequest, BlockChainContextResponse, BlockChainContextService, }; -use cuprate_types::{FeeEstimate, HardFork, HardForkInfo}; +use cuprate_types::{ + rpc::{FeeEstimate, HardForkInfo}, + HardFork, +}; // FIXME: use `anyhow::Error` over `tower::BoxError` in blockchain context. diff --git a/binaries/cuprated/src/rpc/request/txpool.rs b/binaries/cuprated/src/rpc/request/txpool.rs index 78dfc53..91a9f7d 100644 --- a/binaries/cuprated/src/rpc/request/txpool.rs +++ b/binaries/cuprated/src/rpc/request/txpool.rs @@ -1,6 +1,6 @@ //! Functions to send [`TxpoolReadRequest`]s. -use std::convert::Infallible; +use std::{convert::Infallible, num::NonZero}; use anyhow::{anyhow, Error}; use tower::{Service, ServiceExt}; @@ -13,6 +13,10 @@ use cuprate_txpool::{ }, TxEntry, }; +use cuprate_types::{ + rpc::{PoolInfoFull, PoolInfoIncremental, PoolTxInfo}, + PoolInfo, +}; // FIXME: use `anyhow::Error` over `tower::BoxError` in txpool. @@ -53,6 +57,31 @@ pub(crate) async fn size( Ok(usize_to_u64(size)) } +/// TODO +pub(crate) async fn pool_info( + txpool_read: &mut TxpoolReadHandle, + include_sensitive_txs: bool, + max_tx_count: usize, + start_time: Option>, +) -> Result, Error> { + let TxpoolReadResponse::PoolInfo(vec) = txpool_read + .ready() + .await + .map_err(|e| anyhow!(e))? + .call(TxpoolReadRequest::PoolInfo { + include_sensitive_txs, + max_tx_count, + start_time, + }) + .await + .map_err(|e| anyhow!(e))? + else { + unreachable!(); + }; + + Ok(vec) +} + /// TODO pub(crate) async fn flush( txpool_manager: &mut Infallible, diff --git a/consensus/context/src/lib.rs b/consensus/context/src/lib.rs index acc4d23..9d96597 100644 --- a/consensus/context/src/lib.rs +++ b/consensus/context/src/lib.rs @@ -36,7 +36,10 @@ mod alt_chains; mod task; mod tokens; -use cuprate_types::{Chain, ChainInfo, FeeEstimate, HardForkInfo}; +use cuprate_types::{ + rpc::{ChainInfo, FeeEstimate, HardForkInfo}, + Chain, +}; use difficulty::DifficultyCache; use rx_vms::RandomXVm; use weight::BlockWeightsCache; diff --git a/rpc/types/src/bin.rs b/rpc/types/src/bin.rs index 414214c..d3ff68f 100644 --- a/rpc/types/src/bin.rs +++ b/rpc/types/src/bin.rs @@ -11,12 +11,12 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "epee")] use cuprate_epee_encoding::container_as_blob::ContainerAsBlob; -use cuprate_types::BlockCompleteEntry; +use cuprate_types::{BlockCompleteEntry, PoolInfo}; use crate::{ base::AccessResponseBase, macros::define_request_and_response, - misc::{BlockOutputIndices, GetOutputsOut, OutKeyBin, PoolInfo}, + misc::{BlockOutputIndices, GetOutputsOut, OutKeyBin}, rpc_call::RpcCallValue, }; diff --git a/rpc/types/src/from.rs b/rpc/types/src/from.rs new file mode 100644 index 0000000..cc86876 --- /dev/null +++ b/rpc/types/src/from.rs @@ -0,0 +1,380 @@ +//! [`From`] implementations from other crate's types into [`crate`] types. + +#![allow(unused_variables, unreachable_code, reason = "TODO")] + +use cuprate_types::rpc::{ + AuxPow, BlockHeader, BlockOutputIndices, ChainInfo, ConnectionInfo, GetBan, + GetMinerDataTxBacklogEntry, GetOutputsOut, HardforkEntry, HistogramEntry, OutKey, OutKeyBin, + OutputDistributionData, Peer, PublicNode, SetBan, Span, SpentKeyImageInfo, SyncInfoPeer, + TxBacklogEntry, TxInfo, TxOutputIndices, TxpoolHisto, TxpoolStats, +}; + +impl From for crate::misc::BlockHeader { + fn from(x: BlockHeader) -> Self { + todo!(); + + // Self { + // 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, + // } + } +} + +impl From for crate::misc::ConnectionInfo { + fn from(x: ConnectionInfo) -> Self { + todo!(); + + // Self { + // address: String, + // address_type: AddressType, + // 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, + // // Exists in the original definition, but isn't + // // used or (de)serialized for RPC purposes. + // // ssl: bool, + // state: ConnectionState, + // support_flags: u32, + // } + } +} + +impl From for crate::misc::SetBan { + fn from(x: SetBan) -> Self { + todo!(); + + // Self { + // #[cfg_attr(feature = "serde", serde(default = "default_string"))] + // host: String, + // #[cfg_attr(feature = "serde", serde(default = "default_zero"))] + // ip: u32, + // ban: bool, + // seconds: u32, + // } + } +} + +impl From for crate::misc::GetBan { + fn from(x: GetBan) -> Self { + todo!(); + + // Self { + // host: String, + // ip: u32, + // seconds: u32, + // } + } +} + +impl From for crate::misc::HistogramEntry { + fn from(x: HistogramEntry) -> Self { + todo!(); + + // Self { + // amount: u64, + // total_instances: u64, + // unlocked_instances: u64, + // recent_instances: u64, + // } + } +} + +impl From for crate::misc::HardforkEntry { + fn from(x: HardforkEntry) -> Self { + todo!(); + + // Self { + // height: u64, + // hf_version: u8, + // } + } +} + +impl From for crate::misc::ChainInfo { + fn from(x: ChainInfo) -> Self { + todo!(); + + // Self { + // block_hash: [u8; 32], + // block_hashes: Vec<[u8; 32]>, + // difficulty_top64: u64, + // difficulty_low64: u64, + // height: u64, + // length: u64, + // main_chain_parent_block: [u8; 32], + // } + } +} + +impl From for crate::misc::SyncInfoPeer { + fn from(x: SyncInfoPeer) -> Self { + todo!(); + + // Self { + // info: ConnectionInfo, + // } + } +} + +impl From for crate::misc::Span { + fn from(x: Span) -> Self { + todo!(); + + // Self { + // connection_id: String, + // nblocks: u64, + // rate: u32, + // remote_address: String, + // size: u64, + // speed: u32, + // start_block_height: u64, + // } + } +} + +impl From for crate::misc::TxBacklogEntry { + fn from(x: TxBacklogEntry) -> Self { + todo!(); + + // Self { + // weight: u64, + // fee: u64, + // time_in_pool: u64, + // } + } +} + +impl From for crate::misc::OutputDistributionData { + fn from(x: OutputDistributionData) -> Self { + todo!(); + + // Self { + // distribution: Vec, + // start_height: u64, + // base: u64, + // } + } +} + +impl From for crate::misc::GetMinerDataTxBacklogEntry { + fn from(x: GetMinerDataTxBacklogEntry) -> Self { + todo!(); + + // Self { + // id: String, + // weight: u64, + // fee: u64, + // } + } +} + +impl From for crate::misc::AuxPow { + fn from(x: AuxPow) -> Self { + todo!(); + + // Self { + // id: [u8; 32], + // hash: [u8; 32], + // } + } +} + +impl From for crate::misc::TxOutputIndices { + fn from(x: TxOutputIndices) -> Self { + todo!(); + + // Self { + // indices: Vec, + // } + } +} + +impl From for crate::misc::BlockOutputIndices { + fn from(x: BlockOutputIndices) -> Self { + todo!(); + + // Self { + // indices: Vec, + // } + } +} + +impl From for crate::misc::GetOutputsOut { + fn from(x: GetOutputsOut) -> Self { + todo!(); + + // Self { + // amount: u64, + // index: u64, + // } + } +} + +impl From for crate::misc::OutKeyBin { + fn from(x: OutKeyBin) -> Self { + todo!(); + + // Self { + // key: [u8; 32], + // mask: [u8; 32], + // unlocked: bool, + // height: u64, + // txid: [u8; 32], + // } + } +} + +impl From for crate::misc::Peer { + fn from(x: Peer) -> Self { + todo!(); + + // Self { + // id: u64, + // host: String, + // ip: u32, + // port: u16, + // #[cfg_attr(feature = "serde", serde(default = "default_zero"))] + // rpc_port: u16 = default_zero::(), + // #[cfg_attr(feature = "serde", serde(default = "default_zero"))] + // rpc_credits_per_hash: u32 = default_zero::(), + // last_seen: u64, + // #[cfg_attr(feature = "serde", serde(default = "default_zero"))] + // pruning_seed: u32 = default_zero::(), + // } + } +} + +impl From for crate::misc::PublicNode { + fn from(x: PublicNode) -> Self { + todo!(); + + // Self { + // host: String, + // last_seen: u64, + // rpc_port: u16, + // rpc_credits_per_hash: u32, + // } + } +} + +impl From for crate::misc::TxInfo { + fn from(x: TxInfo) -> Self { + todo!(); + + // Self { + // blob_size: u64, + // do_not_relay: bool, + // double_spend_seen: bool, + // fee: u64, + // id_hash: String, + // kept_by_block: bool, + // last_failed_height: u64, + // last_failed_id_hash: String, + // last_relayed_time: u64, + // max_used_block_height: u64, + // max_used_block_id_hash: String, + // receive_time: u64, + // relayed: bool, + // tx_blob: String, + // tx_json: String, // TODO: this should be another struct + // #[cfg_attr(feature = "serde", serde(default = "default_zero"))] + // weight: u64 = default_zero::(), + // } + } +} + +impl From for crate::misc::SpentKeyImageInfo { + fn from(x: SpentKeyImageInfo) -> Self { + todo!(); + + // Self { + // id_hash: String, + // txs_hashes: Vec, + // } + } +} + +impl From for crate::misc::TxpoolHisto { + fn from(x: TxpoolHisto) -> Self { + todo!(); + + // Self { + // txs: u32, + // bytes: u64, + // } + } +} + +impl From for crate::misc::TxpoolStats { + fn from(x: TxpoolStats) -> Self { + todo!(); + + // Self { + // bytes_max: u32, + // bytes_med: u32, + // bytes_min: u32, + // bytes_total: u64, + // fee_total: u64, + // histo_98pc: u64, + // histo: Vec, + // num_10m: u32, + // num_double_spends: u32, + // num_failing: u32, + // num_not_relayed: u32, + // oldest: u64, + // txs_total: u32, + // } + } +} + +impl From for crate::misc::OutKey { + fn from(x: OutKey) -> Self { + todo!(); + + // Self { + // key: String, + // mask: String, + // unlocked: bool, + // height: u64, + // txid: String, + // } + } +} diff --git a/rpc/types/src/lib.rs b/rpc/types/src/lib.rs index 403a3ea..4d3f5ac 100644 --- a/rpc/types/src/lib.rs +++ b/rpc/types/src/lib.rs @@ -9,6 +9,7 @@ mod constants; #[cfg(any(feature = "serde", feature = "epee"))] mod defaults; mod free; +mod from; mod macros; mod rpc_call; diff --git a/rpc/types/src/misc/mod.rs b/rpc/types/src/misc/mod.rs index 026e9ae..7734356 100644 --- a/rpc/types/src/misc/mod.rs +++ b/rpc/types/src/misc/mod.rs @@ -15,25 +15,20 @@ mod binary_string; mod distribution; mod key_image_spent_status; -#[expect(clippy::module_inception)] -mod misc; -mod pool_info; -mod pool_info_extent; mod requested_info; mod status; mod tx_entry; +mod types; pub use binary_string::BinaryString; pub use distribution::{Distribution, DistributionCompressedBinary, DistributionUncompressed}; pub use key_image_spent_status::KeyImageSpentStatus; -pub use misc::{ - AuxPow, BlockHeader, BlockOutputIndices, ChainInfo, ConnectionInfo, GetBan, - GetMinerDataTxBacklogEntry, GetOutputsOut, HardforkEntry, HistogramEntry, OutKey, OutKeyBin, - OutputDistributionData, Peer, PoolTxInfo, PublicNode, SetBan, Span, SpentKeyImageInfo, - SyncInfoPeer, TxBacklogEntry, TxInfo, TxOutputIndices, TxpoolHisto, TxpoolStats, -}; -pub use pool_info::PoolInfo; -pub use pool_info_extent::PoolInfoExtent; pub use requested_info::RequestedInfo; pub use status::Status; pub use tx_entry::TxEntry; +pub use types::{ + AuxPow, BlockHeader, BlockOutputIndices, ChainInfo, ConnectionInfo, GetBan, + GetMinerDataTxBacklogEntry, GetOutputsOut, HardforkEntry, HistogramEntry, OutKey, OutKeyBin, + OutputDistributionData, Peer, PublicNode, SetBan, Span, SpentKeyImageInfo, SyncInfoPeer, + TxBacklogEntry, TxInfo, TxOutputIndices, TxpoolHisto, TxpoolStats, +}; diff --git a/rpc/types/src/misc/misc.rs b/rpc/types/src/misc/types.rs similarity index 92% rename from rpc/types/src/misc/misc.rs rename to rpc/types/src/misc/types.rs index 2d88f2a..d405726 100644 --- a/rpc/types/src/misc/misc.rs +++ b/rpc/types/src/misc/types.rs @@ -5,12 +5,6 @@ //! the [`crate::misc::ConnectionInfo`] struct defined here. //---------------------------------------------------------------------------------------------------- Import -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - -#[cfg(feature = "epee")] -use cuprate_epee_encoding::epee_object; - #[cfg(any(feature = "epee", feature = "serde"))] use crate::defaults::default_zero; @@ -28,7 +22,7 @@ use crate::macros::monero_definition_link; /// - The original Monero definition site with [`monero_definition_link`] /// - The request/responses where the `struct` is used macro_rules! define_struct_and_impl_epee { - ( + ($( // Optional `struct` attributes. $( #[$struct_attr:meta] )* // The `struct`'s name. @@ -40,24 +34,26 @@ macro_rules! define_struct_and_impl_epee { $field_name:ident: $field_type:ty $(= $field_default:expr_2021)?, )* } - ) => { - #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] - $( #[$struct_attr] )* - pub struct $struct_name { - $( - $( #[$field_attr] )* - pub $field_name: $field_type, - )* - } + )*) => { + $( + #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + $( #[$struct_attr] )* + pub struct $struct_name { + $( + $( #[$field_attr] )* + pub $field_name: $field_type, + )* + } - #[cfg(feature = "epee")] - epee_object! { - $struct_name, - $( - $field_name: $field_type $(= $field_default)?, - )* - } + #[cfg(feature = "epee")] + cuprate_epee_encoding::epee_object! { + $struct_name, + $( + $field_name: $field_type $(= $field_default)?, + )* + } + )* }; } @@ -332,20 +328,6 @@ define_struct_and_impl_epee! { } } -define_struct_and_impl_epee! { - #[doc = monero_definition_link!( - cc73fe71162d564ffda8e549b79a350bca53c454, - "rpc/core_rpc_server_commands_defs.h", - 210..=221 - )] - /// Used in [`crate::bin::GetBlocksResponse`]. - PoolTxInfo { - tx_hash: [u8; 32], - tx_blob: String, - double_spend_seen: bool, - } -} - define_struct_and_impl_epee! { #[doc = monero_definition_link!( cc73fe71162d564ffda8e549b79a350bca53c454, diff --git a/storage/blockchain/src/service/read.rs b/storage/blockchain/src/service/read.rs index 84b1b92..2f46400 100644 --- a/storage/blockchain/src/service/read.rs +++ b/storage/blockchain/src/service/read.rs @@ -29,7 +29,8 @@ use cuprate_database_service::{init_thread_pool, DatabaseReadService, ReaderThre use cuprate_helper::map::combine_low_high_bits_to_u128; use cuprate_types::{ blockchain::{BlockchainReadRequest, BlockchainResponse}, - Chain, ChainId, ExtendedBlockHeader, OutputHistogramInput, OutputOnChain, TxsInBlock, + rpc::OutputHistogramInput, + Chain, ChainId, ExtendedBlockHeader, OutputOnChain, TxsInBlock, }; use crate::{ diff --git a/storage/txpool/src/service/interface.rs b/storage/txpool/src/service/interface.rs index a27c630..f2fb144 100644 --- a/storage/txpool/src/service/interface.rs +++ b/storage/txpool/src/service/interface.rs @@ -3,10 +3,11 @@ //! This module contains `cuprate_txpool`'s [`tower::Service`] request and response enums. use std::{ collections::{HashMap, HashSet}, + num::NonZero, sync::Arc, }; -use cuprate_types::TransactionVerificationData; +use cuprate_types::{PoolInfo, TransactionVerificationData}; use crate::{ tx::TxEntry, @@ -40,6 +41,17 @@ pub enum TxpoolReadRequest { /// include private transactions in the pool. include_sensitive_txs: bool, }, + + /// Get general information on the txpool. + PoolInfo { + /// If this is [`true`], the size returned will + /// include private transactions in the pool. + include_sensitive_txs: bool, + /// TODO + max_tx_count: usize, + /// TODO + start_time: Option>, + }, } //---------------------------------------------------------------------------------------------------- TxpoolReadResponse @@ -79,6 +91,9 @@ pub enum TxpoolReadResponse { /// The inner value is the amount of /// transactions currently in the pool. Size(usize), + + /// Response to [`TxpoolReadRequest::PoolInfo`]. + PoolInfo(Vec), } //---------------------------------------------------------------------------------------------------- TxpoolWriteRequest diff --git a/storage/txpool/src/service/read.rs b/storage/txpool/src/service/read.rs index 44a29b3..6cf9b14 100644 --- a/storage/txpool/src/service/read.rs +++ b/storage/txpool/src/service/read.rs @@ -6,6 +6,7 @@ )] use std::{ collections::{HashMap, HashSet}, + num::NonZero, sync::Arc, }; @@ -74,6 +75,11 @@ fn map_request( TxpoolReadRequest::Size { include_sensitive_txs, } => size(env, include_sensitive_txs), + TxpoolReadRequest::PoolInfo { + include_sensitive_txs, + max_tx_count, + start_time, + } => pool_info(include_sensitive_txs, max_tx_count, start_time), } } @@ -206,3 +212,12 @@ fn backlog(env: &ConcreteEnv) -> ReadResponseResult { fn size(env: &ConcreteEnv, include_sensitive_txs: bool) -> ReadResponseResult { Ok(TxpoolReadResponse::Size(todo!())) } + +/// [`TxpoolReadRequest::PoolInfo`]. +fn pool_info( + include_sensitive_txs: bool, + max_tx_count: usize, + start_time: Option>, +) -> ReadResponseResult { + Ok(TxpoolReadResponse::PoolInfo(todo!())) +} diff --git a/types/Cargo.toml b/types/Cargo.toml index e1ffb19..b747319 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -20,9 +20,9 @@ json = ["hex", "dep:cuprate-helper"] hex = ["serde", "dep:hex"] [dependencies] -cuprate-epee-encoding = { workspace = true, optional = true, features = ["std"] } -cuprate-helper = { workspace = true, optional = true, features = ["cast"] } -cuprate-fixed-bytes = { workspace = true, features = ["std", "serde"] } +cuprate-epee-encoding = { workspace = true, optional = true, features = ["std"] } +cuprate-helper = { workspace = true, optional = true, features = ["cast"] } +cuprate-fixed-bytes = { workspace = true, features = ["std", "serde"] } bytes = { workspace = true } curve25519-dalek = { workspace = true } diff --git a/types/src/blockchain.rs b/types/src/blockchain.rs index 7518935..2f5e496 100644 --- a/types/src/blockchain.rs +++ b/types/src/blockchain.rs @@ -12,10 +12,11 @@ use monero_serai::block::Block; use crate::{ types::{Chain, ExtendedBlockHeader, OutputOnChain, TxsInBlock, VerifiedBlockInformation}, - AltBlockInformation, BlockCompleteEntry, ChainId, ChainInfo, CoinbaseTxSum, - OutputHistogramEntry, OutputHistogramInput, + AltBlockInformation, BlockCompleteEntry, ChainId, }; +use crate::rpc::{ChainInfo, CoinbaseTxSum, OutputHistogramEntry, OutputHistogramInput}; + //---------------------------------------------------------------------------------------------------- ReadRequest /// A read request to the blockchain database. /// diff --git a/types/src/lib.rs b/types/src/lib.rs index 7aaf0b9..2eed99f 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -13,20 +13,24 @@ mod address_type; mod block_complete_entry; mod connection_state; mod hard_fork; +mod pool_info; +mod pool_info_extent; mod transaction_verification_data; mod types; +pub mod rpc; + pub use address_type::AddressType; pub use block_complete_entry::{BlockCompleteEntry, PrunedTxBlobEntry, TransactionBlobs}; pub use connection_state::ConnectionState; pub use hard_fork::{HardFork, HardForkError}; +pub use pool_info::PoolInfo; +pub use pool_info_extent::PoolInfoExtent; pub use transaction_verification_data::{ CachedVerificationState, TransactionVerificationData, TxVersion, }; pub use types::{ - AddAuxPow, AltBlockInformation, AuxPow, Chain, ChainId, ChainInfo, CoinbaseTxSum, - ExtendedBlockHeader, FeeEstimate, HardForkInfo, MinerData, MinerDataTxBacklogEntry, - OutputHistogramEntry, OutputHistogramInput, OutputOnChain, TxsInBlock, + AltBlockInformation, Chain, ChainId, ExtendedBlockHeader, OutputOnChain, TxsInBlock, VerifiedBlockInformation, VerifiedTransactionInformation, }; diff --git a/rpc/types/src/misc/pool_info.rs b/types/src/pool_info.rs similarity index 75% rename from rpc/types/src/misc/pool_info.rs rename to types/src/pool_info.rs index e9ba875..6d7909e 100644 --- a/rpc/types/src/misc/pool_info.rs +++ b/types/src/pool_info.rs @@ -2,25 +2,20 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "epee")] -use crate::misc::PoolInfoExtent; +use crate::pool_info_extent::PoolInfoExtent; #[cfg(feature = "epee")] use cuprate_epee_encoding::{ - epee_object, error, + error, macros::bytes::{Buf, BufMut}, read_epee_value, write_field, EpeeObject, EpeeObjectBuilder, }; use cuprate_fixed_bytes::ByteArrayVec; -use crate::misc::PoolTxInfo; +use crate::rpc::{PoolInfoFull, PoolInfoIncremental, PoolTxInfo}; //---------------------------------------------------------------------------------------------------- PoolInfo -#[doc = crate::macros::monero_definition_link!( - cc73fe71162d564ffda8e549b79a350bca53c454, - "rpc/core_rpc_server_commands_defs.h", - 223..=228 -)] -/// Used in [`crate::bin::GetBlocksResponse`]. +/// Used in RPC's `get_blocks.bin`. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(u8)] @@ -31,39 +26,6 @@ pub enum PoolInfo { Full(PoolInfoFull), } -//---------------------------------------------------------------------------------------------------- Internal data -/// Data within [`PoolInfo::Incremental`]. -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct PoolInfoIncremental { - pub added_pool_txs: Vec, - pub remaining_added_pool_txids: ByteArrayVec<32>, - pub removed_pool_txids: ByteArrayVec<32>, -} - -#[cfg(feature = "epee")] -epee_object! { - PoolInfoIncremental, - added_pool_txs: Vec, - remaining_added_pool_txids: ByteArrayVec<32>, - removed_pool_txids: ByteArrayVec<32>, -} - -/// Data within [`PoolInfo::Full`]. -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct PoolInfoFull { - pub added_pool_txs: Vec, - pub remaining_added_pool_txids: ByteArrayVec<32>, -} - -#[cfg(feature = "epee")] -epee_object! { - PoolInfoFull, - added_pool_txs: Vec, - remaining_added_pool_txids: ByteArrayVec<32>, -} - //---------------------------------------------------------------------------------------------------- PoolInfo epee impl #[cfg(feature = "epee")] /// [`EpeeObjectBuilder`] for [`GetBlocksResponse`]. diff --git a/rpc/types/src/misc/pool_info_extent.rs b/types/src/pool_info_extent.rs similarity index 91% rename from rpc/types/src/misc/pool_info_extent.rs rename to types/src/pool_info_extent.rs index 6372cd6..3bea5c3 100644 --- a/rpc/types/src/misc/pool_info_extent.rs +++ b/types/src/pool_info_extent.rs @@ -12,12 +12,7 @@ use cuprate_epee_encoding::{ }; //---------------------------------------------------------------------------------------------------- PoolInfoExtent -#[doc = crate::macros::monero_definition_link!( - cc73fe71162d564ffda8e549b79a350bca53c454, - "rpc/core_rpc_server_commands_defs.h", - 223..=228 -)] -/// Used in [`crate::bin::GetBlocksResponse`]. +/// Used in RPC's `get_blocks.bin`. #[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[repr(u8)] diff --git a/types/src/rpc.rs b/types/src/rpc.rs new file mode 100644 index 0000000..43cc37c --- /dev/null +++ b/types/src/rpc.rs @@ -0,0 +1,586 @@ +//! Various types (in)directly used in RPC. +//! +//! These types map very closely to types within `cuprate-rpc-types`, +//! however they use more canonical types when appropriate, for example, +//! instead of `hash: String`, this module's types would use something like +//! `hash: [u8; 32]`. +//! +//! - TODO: finish making fields canonical after +//! - TODO: can epee handle `u128`? there are a lot of `(top_64 | low_64)` fields + +use cuprate_fixed_bytes::ByteArrayVec; + +use crate::{AddressType, ConnectionState}; + +const fn default_string() -> String { + String::new() +} + +fn default_zero>() -> T { + T::from(0) +} + +/// Output a string link to `monerod` source code. +macro_rules! monero_definition_link { + ( + $commit:literal, // Git commit hash + $file_path:literal, // File path within `monerod`'s `src/`, e.g. `rpc/core_rpc_server_commands_defs.h` + $start:literal$(..=$end:literal)? // File lines, e.g. `0..=123` or `0` + ) => { + concat!( + "[Definition](https://github.com/monero-project/monero/blob/", + stringify!($commit), + "/src/", + $file_path, + "#L", + stringify!($start), + $( + "-L", + stringify!($end), + )? + ")." + ) + }; +} + +/// This macro (local to this file) defines all the misc types. +/// +/// This macro: +/// 1. Defines a `struct` with all `pub` fields +/// 2. Implements `serde` on the struct +/// 3. Implements `epee` on the struct +/// +/// When using, consider documenting: +/// - The original Monero definition site with [`monero_definition_link`] +/// - The request/responses where the `struct` is used +macro_rules! define_struct_and_impl_epee { + ($( + // Optional `struct` attributes. + $( #[$struct_attr:meta] )* + // The `struct`'s name. + $struct_name:ident { + // And any fields. + $( + $( #[$field_attr:meta] )* // Field attributes + // Field name => the type => optional `epee_object` default value. + $field_name:ident: $field_type:ty $(= $field_default:expr_2021)?, + )* + } + )*) => { + $( + #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + $( #[$struct_attr] )* + pub struct $struct_name { + $( + $( #[$field_attr] )* + pub $field_name: $field_type, + )* + } + + #[cfg(feature = "epee")] + cuprate_epee_encoding::epee_object! { + $struct_name, + $( + $field_name: $field_type $(= $field_default)?, + )* + } + )* + }; +} + +define_struct_and_impl_epee! { + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1163..=1212 + )] + 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, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "cryptonote_protocol/cryptonote_protocol_defs.h", + 47..=116 + )] + ConnectionInfo { + address: String, + address_type: AddressType, + 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, + // Exists in the original definition, but isn't + // used or (de)serialized for RPC purposes. + // ssl: bool, + state: ConnectionState, + support_flags: u32, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 2034..=2047 + )] + SetBan { + #[cfg_attr(feature = "serde", serde(default = "default_string"))] + host: String, + #[cfg_attr(feature = "serde", serde(default = "default_zero"))] + ip: u32, + ban: bool, + seconds: u32, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1999..=2010 + )] + GetBan { + host: String, + ip: u32, + seconds: u32, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 2139..=2156 + )] + #[derive(Copy)] + HistogramEntry { + amount: u64, + total_instances: u64, + unlocked_instances: u64, + recent_instances: u64, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 2180..=2191 + )] + #[derive(Copy)] + HardforkEntry { + height: u64, + hf_version: u8, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 2289..=2310 + )] + ChainInfo { + block_hash: [u8; 32], + block_hashes: Vec<[u8; 32]>, + difficulty_top64: u64, + difficulty_low64: u64, + height: u64, + length: u64, + main_chain_parent_block: [u8; 32], + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 2393..=2400 + )] + SyncInfoPeer { + info: ConnectionInfo, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 2402..=2421 + )] + Span { + connection_id: String, + nblocks: u64, + rate: u32, + remote_address: String, + size: u64, + speed: u32, + start_block_height: u64, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1637..=1642 + )] + #[derive(Copy)] + TxBacklogEntry { + weight: u64, + fee: u64, + time_in_pool: u64, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/rpc_handler.h", + 45..=50 + )] + OutputDistributionData { + distribution: Vec, + start_height: u64, + base: u64, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1016..=1027 + )] + GetMinerDataTxBacklogEntry { + id: String, + weight: u64, + fee: u64, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1070..=1079 + )] + AuxPow { + id: [u8; 32], + hash: [u8; 32], + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 192..=199 + )] + TxOutputIndices { + indices: Vec, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 201..=208 + )] + BlockOutputIndices { + indices: Vec, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 512..=521 + )] + #[derive(Copy)] + GetOutputsOut { + amount: u64, + index: u64, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 538..=553 + )] + OutKeyBin { + key: [u8; 32], + mask: [u8; 32], + unlocked: bool, + height: u64, + txid: [u8; 32], + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1335..=1367 + )] + Peer { + id: u64, + host: String, + ip: u32, + port: u16, + #[cfg_attr(feature = "serde", serde(default = "default_zero"))] + rpc_port: u16 = default_zero::(), + #[cfg_attr(feature = "serde", serde(default = "default_zero"))] + rpc_credits_per_hash: u32 = default_zero::(), + last_seen: u64, + #[cfg_attr(feature = "serde", serde(default = "default_zero"))] + pruning_seed: u32 = default_zero::(), + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1398..=1417 + )] + PublicNode { + host: String, + last_seen: u64, + rpc_port: u16, + rpc_credits_per_hash: u32, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1519..=1556 + )] + TxInfo { + blob_size: u64, + do_not_relay: bool, + double_spend_seen: bool, + fee: u64, + id_hash: String, + kept_by_block: bool, + last_failed_height: u64, + last_failed_id_hash: String, + last_relayed_time: u64, + max_used_block_height: u64, + max_used_block_id_hash: String, + receive_time: u64, + relayed: bool, + tx_blob: String, + tx_json: String, // TODO: this should be another struct + #[cfg_attr(feature = "serde", serde(default = "default_zero"))] + weight: u64 = default_zero::(), + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1558..=1567 + )] + SpentKeyImageInfo { + id_hash: String, + txs_hashes: Vec, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1666..=1675 + )] + #[derive(Copy)] + TxpoolHisto { + txs: u32, + bytes: u64, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 1677..=1710 + )] + TxpoolStats { + bytes_max: u32, + bytes_med: u32, + bytes_min: u32, + bytes_total: u64, + fee_total: u64, + histo_98pc: u64, + histo: Vec, + num_10m: u32, + num_double_spends: u32, + num_failing: u32, + num_not_relayed: u32, + oldest: u64, + txs_total: u32, + } + + #[doc = monero_definition_link!( + "cc73fe71162d564ffda8e549b79a350bca53c454", + "rpc/core_rpc_server_commands_defs.h", + 582..=597 + )] + OutKey { + key: String, + mask: String, + unlocked: bool, + height: u64, + txid: String, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "blockchain_db/lmdb/db_lmdb.cpp", + 4222 + )] + OutputHistogramInput { + amounts: Vec, + min_count: u64, + max_count: u64, + unlocked: bool, + recent_cutoff: u64, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "rpc/core_rpc_server_commands_defs.h", + 2139..=2156 + )] + OutputHistogramEntry { + amount: u64, + total_instances: u64, + unlocked_instances: u64, + recent_instances: u64, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "rpc/core_rpc_server_commands_defs.h", + 2228..=2247 + )] + CoinbaseTxSum { + emission_amount_top64: u64, + emission_amount_low64: u64, + fee_amount_top64: u64, + fee_amount_low64: u64, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "rpc/core_rpc_server_commands_defs.h", + 1027..=1033 + )] + MinerData { + major_version: u8, + height: u64, + prev_id: [u8; 32], + seed_hash: [u8; 32], + difficulty_top64: u64, + difficulty_low64: u64, + median_weight: u64, + already_generated_coins: u64, + tx_backlog: Vec, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "rpc/core_rpc_server_commands_defs.h", + 1037..=1039 + )] + MinerDataTxBacklogEntry { + id: [u8; 32], + weight: u64, + fee: u64, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "rpc/core_rpc_server_commands_defs.h", + 1973..=1980 + )] + HardForkInfo { + earliest_height: u64, + enabled: bool, + state: u32, + threshold: u32, + version: u8, + votes: u32, + voting: u8, + window: u32, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "rpc/core_rpc_server_commands_defs.h", + 2264..=2267 + )] + FeeEstimate { + fee: u64, + fees: Vec, + quantization_mask: u64, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "rpc/core_rpc_server_commands_defs.h", + 1115..=1119 + )] + AddAuxPow { + blocktemplate_blob: Vec, + blockhashing_blob: Vec, + merkle_root: [u8; 32], + merkle_tree_depth: u64, + aux_pow: Vec, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "rpc/core_rpc_server_commands_defs.h", + 227..=229 + )] + PoolTxInfo { + tx_hash: [u8; 32], + tx_blob: Vec, + double_spend_seen: bool, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "rpc/core_rpc_server_commands_defs.h", + 254..=256 + )] + PoolInfoIncremental { + added_pool_txs: Vec, + remaining_added_pool_txids: ByteArrayVec<32>, + removed_pool_txids: ByteArrayVec<32>, + } + + #[doc = monero_definition_link!( + "893916ad091a92e765ce3241b94e706ad012b62a", + "rpc/core_rpc_server_commands_defs.h", + 254..=256 + )] + PoolInfoFull { + added_pool_txs: Vec, + remaining_added_pool_txids: ByteArrayVec<32>, + } +} + +//---------------------------------------------------------------------------------------------------- Tests +#[cfg(test)] +mod test { + // use super::*; +} diff --git a/types/src/types.rs b/types/src/types.rs index 8a5b5aa..24ce98a 100644 --- a/types/src/types.rs +++ b/types/src/types.rs @@ -147,118 +147,6 @@ pub struct OutputOnChain { pub commitment: EdwardsPoint, } -/// Input required to generate an output histogram. -/// -/// Used in RPC's `get_output_histogram`. -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct OutputHistogramInput { - pub amounts: Vec, - pub min_count: u64, - pub max_count: u64, - pub unlocked: bool, - pub recent_cutoff: u64, -} - -/// A single entry in an output histogram. -/// -/// Used in RPC's `get_output_histogram`. -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct OutputHistogramEntry { - pub amount: u64, - pub total_instances: u64, - pub unlocked_instances: u64, - pub recent_instances: u64, -} - -/// Data of summed coinbase transactions. -/// -/// Used in RPC's `get_coinbase_tx_sum`. -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct CoinbaseTxSum { - pub emission_amount: u128, - pub fee_amount: u128, -} - -/// Data to create a custom block template. -/// -/// Used in RPC's `get_miner_data`. -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct MinerData { - pub major_version: u8, - pub height: u64, - pub prev_id: [u8; 32], - pub seed_hash: [u8; 32], - pub difficulty: u128, - pub median_weight: u64, - pub already_generated_coins: u64, - pub tx_backlog: Vec, -} - -/// A transaction in the txpool. -/// -/// Used in [`MinerData::tx_backlog`]. -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct MinerDataTxBacklogEntry { - pub id: [u8; 32], - pub weight: u64, - pub fee: u64, -} - -/// Information on a [`HardFork`]. -/// -/// Used in RPC's `hard_fork_info`. -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct HardForkInfo { - pub earliest_height: u64, - pub enabled: bool, - pub state: u32, - pub threshold: u32, - pub version: u8, - pub votes: u32, - pub voting: u8, - pub window: u32, -} - -/// Estimated fee data. -/// -/// Used in RPC's `get_fee_estimate`. -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct FeeEstimate { - pub fee: u64, - pub fees: Vec, - pub quantization_mask: u64, -} - -/// Information on a (maybe alternate) chain. -/// -/// Used in RPC's `get_alternate_chains`. -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct ChainInfo { - pub block_hash: [u8; 32], - pub block_hashes: Vec<[u8; 32]>, - pub difficulty: u128, - pub height: u64, - pub length: u64, - pub main_chain_parent_block: [u8; 32], -} - -/// Used in RPC's `add_aux_pow`. -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct AuxPow { - pub id: [u8; 32], - pub hash: [u8; 32], -} - -/// Used in RPC's `add_aux_pow`. -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct AddAuxPow { - pub blocktemplate_blob: Vec, - pub blockhashing_blob: Vec, - pub merkle_root: [u8; 32], - pub merkle_tree_depth: u64, - pub aux_pow: Vec, -} - /// The inner response for a request for txs in a block. #[derive(Clone, Debug, PartialEq, Eq)] pub struct TxsInBlock {