cuprate_rpc_types/misc/
tx_entry.rs

1//! TODO
2
3//---------------------------------------------------------------------------------------------------- Use
4#[cfg(feature = "serde")]
5use serde::{Deserialize, Serialize};
6
7#[cfg(feature = "epee")]
8use cuprate_epee_encoding::{
9    error,
10    macros::bytes::{Buf, BufMut},
11    EpeeObject, EpeeObjectBuilder,
12};
13
14use cuprate_hex::{Hex, HexVec};
15
16#[cfg(feature = "serde")]
17use crate::serde::{serde_false, serde_true};
18
19//---------------------------------------------------------------------------------------------------- TxEntry
20#[doc = crate::macros::monero_definition_link!(
21    "cc73fe71162d564ffda8e549b79a350bca53c454",
22    "rpc/core_rpc_server_commands_defs.h",
23    389..=428
24)]
25/// Used in [`crate::other::GetTransactionsResponse`].
26///
27/// # Epee
28/// This type is only used in a JSON endpoint, so the
29/// epee implementation on this type only panics.
30///
31/// It is only implemented to satisfy the RPC type generator
32/// macro, which requires all objects to be serde + epee.
33#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
34#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
35pub struct TxEntry {
36    /// `cuprate_types::json::tx::Transaction` should be used
37    /// to create this JSON string in a type-safe manner.
38    pub as_json: String,
39
40    pub as_hex: HexVec,
41    pub double_spend_seen: bool,
42    pub tx_hash: Hex<32>,
43    pub prunable_as_hex: HexVec,
44    pub prunable_hash: Hex<32>,
45    pub pruned_as_hex: HexVec,
46
47    #[cfg_attr(feature = "serde", serde(flatten))]
48    pub tx_entry_type: TxEntryType,
49}
50
51/// Different fields in [`TxEntry`] variants.
52#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
53#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
54#[cfg_attr(feature = "serde", serde(untagged))]
55pub enum TxEntryType {
56    /// This transaction exists in the blockchain.
57    Blockchain {
58        block_height: u64,
59        block_timestamp: u64,
60        confirmations: u64,
61        output_indices: Vec<u64>,
62
63        /// Will always be serialized as `false`.
64        #[cfg_attr(feature = "serde", serde(serialize_with = "serde_false"))]
65        in_pool: bool,
66    },
67
68    /// This transaction exists in the transaction pool.
69    Pool {
70        received_timestamp: u64,
71        relayed: bool,
72
73        /// Will always be serialized as `true`.
74        #[cfg_attr(feature = "serde", serde(serialize_with = "serde_true"))]
75        in_pool: bool,
76    },
77}
78
79impl Default for TxEntryType {
80    fn default() -> Self {
81        Self::Blockchain {
82            block_height: Default::default(),
83            block_timestamp: Default::default(),
84            confirmations: Default::default(),
85            output_indices: Default::default(),
86            in_pool: Default::default(),
87        }
88    }
89}
90//---------------------------------------------------------------------------------------------------- Epee
91#[cfg(feature = "epee")]
92impl EpeeObjectBuilder<TxEntry> for () {
93    fn add_field<B: Buf>(&mut self, _: &str, _: &mut B) -> error::Result<bool> {
94        unreachable!()
95    }
96
97    fn finish(self) -> error::Result<TxEntry> {
98        unreachable!()
99    }
100}
101
102#[cfg(feature = "epee")]
103impl EpeeObject for TxEntry {
104    type Builder = ();
105
106    fn number_of_fields(&self) -> u64 {
107        unreachable!()
108    }
109
110    fn write_fields<B: BufMut>(self, _: &mut B) -> error::Result<()> {
111        unreachable!()
112    }
113}