I think it has to be implemented Readable
and Writable
For wire messages (+other things) in Rust-Lightning/Lightning/SRC/LN/MSGS.RS#L3673-L3698.
However, I did not make any difference using existing use ( WarningMessage
(For example):
impl Writeable for WarningMessage {
fn write(&self, w: &mut W) -> Result<(), io::Error> {
self.channel_id.write(w)?;
(self.data.len() as u16).write(w)?;
w.write_all(self.data.as_bytes())?;
Ok(())
}
}
impl Readable for WarningMessage {
fn read(r: &mut R) -> Result {
Ok(Self {
channel_id: Readable::read(r)?,
data: {
let sz: usize = ::read(r)? as usize;
let mut data = Vec::with_capacity(sz);
data.resize(sz, 0);
r.read_exact(&mut data)?;
match String::from_utf8(data) {
Ok(s) => s,
Err(_) => return Err(DecodeError::InvalidValue),
}
}
})
}
}
and:
impl_writeable_msg!(WarningMessage, {
channel_id,
data,
}, {});
Both pass the test.
cargo test --package lightning --lib -- ln::msgs::tests::encoding_warning --exact --show-output
Discover more from Earlybirds Invest
Subscribe to get the latest posts sent to your email.