zebra_node_services/mempool/
gossip.rs

1//! Representation of a gossiped transaction to send to the mempool.
2
3use zebra_chain::transaction::{UnminedTx, UnminedTxId};
4
5/// A gossiped transaction, which can be the transaction itself or just its ID.
6#[derive(Clone, Debug, Eq, PartialEq)]
7pub enum Gossip {
8    /// Just the ID of an unmined transaction.
9    Id(UnminedTxId),
10
11    /// The full contents of an unmined transaction.
12    Tx(UnminedTx),
13}
14
15impl Gossip {
16    /// Return the [`UnminedTxId`] of a gossiped transaction.
17    pub fn id(&self) -> UnminedTxId {
18        match self {
19            Gossip::Id(txid) => *txid,
20            Gossip::Tx(tx) => tx.id,
21        }
22    }
23
24    /// Return the [`UnminedTx`] of a gossiped transaction, if we have it.
25    pub fn tx(&self) -> Option<UnminedTx> {
26        match self {
27            Gossip::Id(_) => None,
28            Gossip::Tx(tx) => Some(tx.clone()),
29        }
30    }
31}
32
33impl From<UnminedTxId> for Gossip {
34    fn from(txid: UnminedTxId) -> Self {
35        Gossip::Id(txid)
36    }
37}
38
39impl From<UnminedTx> for Gossip {
40    fn from(tx: UnminedTx) -> Self {
41        Gossip::Tx(tx)
42    }
43}