use crate::ln::msgs::DecodeError;
use crate::util::ser::{Readable, Writeable, Writer};
use std::io;
#[allow(unused_imports)]
use crate::prelude::*;
use bitcoin::hex::display::impl_fmt_traits;
use core::borrow::Borrow;
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ChannelId(pub [u8; 32]);
impl ChannelId {
pub fn from_bytes(data: [u8; 32]) -> Self {
Self(data)
}
pub fn new_zero() -> Self {
Self([0; 32])
}
pub fn is_zero(&self) -> bool {
self.0[..] == [0; 32]
}
}
impl Writeable for ChannelId {
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
self.0.write(w)
}
}
impl Readable for ChannelId {
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
let buf: [u8; 32] = Readable::read(r)?;
Ok(ChannelId(buf))
}
}
impl Borrow<[u8]> for ChannelId {
fn borrow(&self) -> &[u8] {
&self.0[..]
}
}
impl_fmt_traits! {
impl fmt_traits for ChannelId {
const LENGTH: usize = 32;
}
}