hopr_chain_types/
chain_events.rsuse hopr_crypto_types::types::Hash;
use hopr_internal_types::prelude::*;
use hopr_primitive_types::prelude::*;
use libp2p_identity::PeerId;
use multiaddr::Multiaddr;
use std::fmt::{Display, Formatter};
#[derive(Debug, Clone, PartialEq)]
pub struct SignificantChainEvent {
pub tx_hash: Hash,
pub event_type: ChainEventType,
}
impl Display for SignificantChainEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{} @ tx {}", self.event_type, self.tx_hash)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NetworkRegistryStatus {
Allowed,
Denied,
}
#[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, PartialEq)]
pub enum ChainEventType {
Announcement {
peer: PeerId,
address: Address,
multiaddresses: Vec<Multiaddr>,
},
ChannelOpened(ChannelEntry),
ChannelClosureInitiated(ChannelEntry),
ChannelClosed(ChannelEntry),
ChannelBalanceIncreased(ChannelEntry, Balance),
ChannelBalanceDecreased(ChannelEntry, Balance),
TicketRedeemed(ChannelEntry, Option<AcknowledgedTicket>),
NodeSafeRegistered(Address),
NetworkRegistryUpdate(Address, NetworkRegistryStatus),
}
impl Display for ChainEventType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ChainEventType::Announcement {
peer,
address,
multiaddresses,
} => write!(f, "announcement event of {peer} ({address}): {:?}", multiaddresses),
ChainEventType::ChannelOpened(c) => write!(f, "open channel event {}", c.get_id()),
ChainEventType::ChannelClosureInitiated(c) => write!(f, "close channel initiation event {}", c.get_id()),
ChainEventType::ChannelClosed(c) => write!(f, "close channel event {}", c.get_id()),
ChainEventType::ChannelBalanceIncreased(c, _) => write!(f, "channel increase balance event {}", c.get_id()),
ChainEventType::ChannelBalanceDecreased(c, _) => write!(f, "channel decrease balance event {}", c.get_id()),
ChainEventType::TicketRedeemed(c, _) => write!(f, "ticket redeem event in channel {}", c.get_id()),
ChainEventType::NodeSafeRegistered(s) => write!(f, "safe registered event {s}"),
ChainEventType::NetworkRegistryUpdate(a, s) => write!(f, "network registry update event {a}: {:?}", s),
}
}
}