LDK – Earlybirds Invest https://earlybirdsinvest.com Latest Crypto News Mon, 10 Mar 2025 16:23:06 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.7 https://i0.wp.com/earlybirdsinvest.com/wp-content/uploads/2024/12/cropped-New-Project-2024-12-17T235703.455.png?fit=32%2C32&ssl=1 LDK – Earlybirds Invest https://earlybirdsinvest.com 32 32 240146708 The best way to add your own wire message to your LDK https://earlybirdsinvest.com/the-best-way-to-add-your-own-wire-message-to-your-ldk/ https://earlybirdsinvest.com/the-best-way-to-add-your-own-wire-message-to-your-ldk/#respond Mon, 10 Mar 2025 16:23:06 +0000 https://earlybirdsinvest.com/the-best-way-to-add-your-own-wire-message-to-your-ldk/

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

]]>
https://earlybirdsinvest.com/the-best-way-to-add-your-own-wire-message-to-your-ldk/feed/ 0 24344