Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rpc/types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This crate ports the types used in Monero's RPC interface, including:
- Mixed types
- Other commonly used RPC types

It also includes some traits for these types.

# Modules
This crate's types are split in the following manner:

Expand Down Expand Up @@ -94,6 +96,12 @@ The invariants that can be relied upon:
- Types in [`bin`] will implement `epee` correctly
- Misc types will implement `serde/epee` correctly as needed

# Requests and responses
For `enum`s that encapsulate all request/response types, see:
- [`crate::json::JsonRpcRequest`] & [`crate::json::JsonRpcResponse`]
- [`crate::bin::BinRequest`] & [`crate::bin::BinResponse`]
- [`crate::other::OtherRequest`] & [`crate::other::OtherResponse`]

# Feature flags
List of feature flags for `cuprate-rpc-types`.

Expand Down
67 changes: 67 additions & 0 deletions rpc/types/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::{
HardforkEntry, HistogramEntry, OutKeyBin, OutputDistributionData, Peer, PoolInfoExtent,
PoolTxInfo, SetBan, Span, Status, TxBacklogEntry,
},
rpc_call::{RpcCall, RpcCallValue},
};

//---------------------------------------------------------------------------------------------------- Definitions
Expand Down Expand Up @@ -393,6 +394,72 @@ impl EpeeObject for GetBlocksResponse {
}
}

//---------------------------------------------------------------------------------------------------- Request
/// Binary requests.
///
/// This enum contains all [`crate::bin`] requests.
///
/// See also: [`BinResponse`].
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(untagged))]
#[allow(missing_docs)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum BinRequest {
GetBlocks(GetBlocksRequest),
GetBlocksByHeight(GetBlocksByHeightRequest),
GetHashes(GetHashesRequest),
GetOutputIndexes(GetOutputIndexesRequest),
GetOuts(GetOutsRequest),
GetTransactionPoolHashes(GetTransactionPoolHashesRequest),
GetOutputDistribution(crate::json::GetOutputDistributionRequest),
}

impl RpcCallValue for BinRequest {
fn is_restricted(&self) -> bool {
match self {
Self::GetBlocks(x) => x.is_restricted(),
Self::GetBlocksByHeight(x) => x.is_restricted(),
Self::GetHashes(x) => x.is_restricted(),
Self::GetOutputIndexes(x) => x.is_restricted(),
Self::GetOuts(x) => x.is_restricted(),
Self::GetTransactionPoolHashes(x) => x.is_restricted(),
Self::GetOutputDistribution(x) => x.is_restricted(),
}
}

fn is_empty(&self) -> bool {
match self {
Self::GetBlocks(x) => x.is_empty(),
Self::GetBlocksByHeight(x) => x.is_empty(),
Self::GetHashes(x) => x.is_empty(),
Self::GetOutputIndexes(x) => x.is_empty(),
Self::GetOuts(x) => x.is_empty(),
Self::GetTransactionPoolHashes(x) => x.is_empty(),
Self::GetOutputDistribution(x) => x.is_empty(),
}
}
}

//---------------------------------------------------------------------------------------------------- Response
/// Binary responses.
///
/// This enum contains all [`crate::bin`] responses.
///
/// See also: [`BinRequest`].
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(untagged))]
#[allow(missing_docs)]
pub enum BinResponse {
GetBlocks(GetBlocksResponse),
GetBlocksByHeight(GetBlocksByHeightResponse),
GetHashes(GetHashesResponse),
GetOutputIndexes(GetOutputIndexesResponse),
GetOuts(GetOutsResponse),
GetTransactionPoolHashes(GetTransactionPoolHashesResponse),
GetOutputDistribution(crate::json::GetOutputDistributionResponse),
}

//---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)]
mod test {
Expand Down
Loading