1use std::marker::PhantomData;
2
3use super::packet::{rawchan::RawChannel, ProtocolError};
4use cardano_sdk::protocol::{Protocol, Time};
5
6pub struct Channel<P: Protocol> {
7 phantom: std::marker::PhantomData<P>,
8 channel: RawChannel,
9}
10
11impl<P: Protocol> Channel<P> {
12 pub const NUMBER: u16 = P::NUMBER;
13
14 pub fn new(channel: RawChannel) -> Self {
15 Self {
16 phantom: PhantomData,
17 channel,
18 }
19 }
20
21 pub(crate) async fn tx(&self, response: bool, t: P) -> Result<(), ProtocolError> {
22 self.channel
23 .tx_proto(Time::now(), response, t)
24 .await
25 .map_err(|e| e.into())
26 }
27
28 pub(crate) async fn rx(&mut self) -> Result<P, ProtocolError> {
29 self.channel.rx_cbor::<P>().await.map_err(|e| e.into())
30 }
31}