1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use fedimint_core::PeerId;

use super::data_provider::UnitData;

pub struct FinalizationHandler {
    sender: async_channel::Sender<(UnitData, PeerId)>,
}

impl FinalizationHandler {
    pub fn new(sender: async_channel::Sender<(UnitData, PeerId)>) -> Self {
        Self { sender }
    }
}

impl aleph_bft::FinalizationHandler<UnitData> for FinalizationHandler {
    fn data_finalized(&mut self, unit_data: UnitData, creator: aleph_bft::NodeIndex) {
        // the channel is unbounded
        self.sender
            .try_send((unit_data, super::to_peer_id(creator)))
            .ok();
    }
}