1//! Representation of a gossiped transaction to send to the mempool.
23use zebra_chain::transaction::{UnminedTx, UnminedTxId};
45/// 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.
9Id(UnminedTxId),
1011/// The full contents of an unmined transaction.
12Tx(UnminedTx),
13}
1415impl Gossip {
16/// Return the [`UnminedTxId`] of a gossiped transaction.
17pub fn id(&self) -> UnminedTxId {
18match self {
19 Gossip::Id(txid) => *txid,
20 Gossip::Tx(tx) => tx.id,
21 }
22 }
2324/// Return the [`UnminedTx`] of a gossiped transaction, if we have it.
25pub fn tx(&self) -> Option<UnminedTx> {
26match self {
27 Gossip::Id(_) => None,
28 Gossip::Tx(tx) => Some(tx.clone()),
29 }
30 }
31}
3233impl From<UnminedTxId> for Gossip {
34fn from(txid: UnminedTxId) -> Self {
35 Gossip::Id(txid)
36 }
37}
3839impl From<UnminedTx> for Gossip {
40fn from(tx: UnminedTx) -> Self {
41 Gossip::Tx(tx)
42 }
43}