fuel_core/service/adapters/
tx_status_manager.rs

1use super::P2PAdapter;
2use fuel_core_chain_config::ConsensusConfig;
3use fuel_core_services::stream::BoxStream;
4use fuel_core_tx_status_manager::{
5    ports::P2PPreConfirmationGossipData,
6    service::ProtocolPublicKey,
7};
8use fuel_core_types::{
9    fuel_tx::Address,
10    services::p2p::{
11        GossipsubMessageAcceptance,
12        GossipsubMessageInfo,
13    },
14};
15
16#[cfg(feature = "p2p")]
17impl fuel_core_tx_status_manager::ports::P2PSubscriptions for P2PAdapter {
18    type GossipedStatuses = P2PPreConfirmationGossipData;
19
20    fn gossiped_tx_statuses(&self) -> BoxStream<Self::GossipedStatuses> {
21        use tokio_stream::{
22            StreamExt,
23            wrappers::BroadcastStream,
24        };
25
26        match &self.service {
27            Some(service) => Box::pin(
28                BroadcastStream::new(service.subscribe_preconfirmations())
29                    .filter_map(|result| result.ok()),
30            ),
31            _ => fuel_core_services::stream::IntoBoxStream::into_boxed(
32                tokio_stream::pending(),
33            ),
34        }
35    }
36
37    fn notify_gossip_transaction_validity(
38        &self,
39        message_info: GossipsubMessageInfo,
40        validity: GossipsubMessageAcceptance,
41    ) -> anyhow::Result<()> {
42        match &self.service {
43            Some(service) => {
44                service.notify_gossip_transaction_validity(message_info, validity)
45            }
46            _ => Ok(()),
47        }
48    }
49}
50
51#[cfg(not(feature = "p2p"))]
52impl fuel_core_tx_status_manager::ports::P2PSubscriptions for P2PAdapter {
53    type GossipedStatuses = P2PPreConfirmationGossipData;
54
55    fn gossiped_tx_statuses(&self) -> BoxStream<Self::GossipedStatuses> {
56        Box::pin(fuel_core_services::stream::pending())
57    }
58
59    fn notify_gossip_transaction_validity(
60        &self,
61        _message_info: GossipsubMessageInfo,
62        _validity: GossipsubMessageAcceptance,
63    ) -> anyhow::Result<()> {
64        Ok(())
65    }
66}
67
68pub struct ConsensusConfigProtocolPublicKey {
69    inner: ConsensusConfig,
70}
71
72impl ConsensusConfigProtocolPublicKey {
73    pub fn new(inner: ConsensusConfig) -> Self {
74        Self { inner }
75    }
76}
77
78impl ProtocolPublicKey for ConsensusConfigProtocolPublicKey {
79    fn latest_address(&self) -> Address {
80        match &self.inner {
81            ConsensusConfig::PoA { signing_key } => *signing_key,
82            ConsensusConfig::PoAV2(poa_v2) => poa_v2.latest_address(),
83        }
84    }
85}