From c06d0a47a27e6cc88663261603907864766d60a1 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Thu, 26 Sep 2024 16:52:41 -0400 Subject: [PATCH] cuprate-rpc-types: common `TxEntry` fields into prefix struct --- rpc/types/src/misc/tx_entry.rs | 47 ++++++++++++++++------------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/rpc/types/src/misc/tx_entry.rs b/rpc/types/src/misc/tx_entry.rs index 807c202..fb5b705 100644 --- a/rpc/types/src/misc/tx_entry.rs +++ b/rpc/types/src/misc/tx_entry.rs @@ -71,36 +71,24 @@ use cuprate_epee_encoding::{ pub enum TxEntry { /// This entry exists in the transaction pool. InPool { - as_hex: String, - /// `cuprate_rpc_types::json::tx::Transaction` should be used - /// to create this JSON string in a type-safe manner. - as_json: String, + /// This field is flattened. + #[cfg_attr(feature = "serde", serde(flatten))] + prefix: TxEntryPrefix, block_height: u64, block_timestamp: u64, confirmations: u64, - double_spend_seen: bool, output_indices: Vec, - prunable_as_hex: String, - prunable_hash: String, - pruned_as_hex: String, - tx_hash: String, #[cfg_attr(feature = "serde", serde(serialize_with = "serde_true"))] /// Will always be serialized as `true`. in_pool: bool, }, /// This entry _does not_ exist in the transaction pool. NotInPool { - as_hex: String, - /// `cuprate_rpc_types::json::tx::Transaction` should be used - /// to create this JSON string in a type-safe manner. - as_json: String, - double_spend_seen: bool, - prunable_as_hex: String, - prunable_hash: String, - pruned_as_hex: String, + /// This field is flattened. + #[cfg_attr(feature = "serde", serde(flatten))] + prefix: TxEntryPrefix, received_timestamp: u64, relayed: bool, - tx_hash: String, #[cfg_attr(feature = "serde", serde(serialize_with = "serde_false"))] /// Will always be serialized as `false`. in_pool: bool, @@ -110,20 +98,29 @@ pub enum TxEntry { impl Default for TxEntry { fn default() -> Self { Self::NotInPool { - as_hex: String::default(), - as_json: String::default(), - double_spend_seen: bool::default(), - prunable_as_hex: String::default(), - prunable_hash: String::default(), - pruned_as_hex: String::default(), + prefix: Default::default(), received_timestamp: u64::default(), relayed: bool::default(), - tx_hash: String::default(), in_pool: false, } } } +/// Common fields in all [`TxEntry`] variants. +#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct TxEntryPrefix { + as_hex: String, + /// `cuprate_rpc_types::json::tx::Transaction` should be used + /// to create this JSON string in a type-safe manner. + as_json: String, + double_spend_seen: bool, + tx_hash: String, + prunable_as_hex: String, + prunable_hash: String, + pruned_as_hex: String, +} + //---------------------------------------------------------------------------------------------------- Epee #[cfg(feature = "epee")] impl EpeeObjectBuilder for () {