From: Matt Corallo Date: Fri, 19 Oct 2018 01:34:41 +0000 (-0400) Subject: impl Readable/Writable for Route X-Git-Tag: v0.0.12~283^2~7 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=4eafd37d2033a9825c76faef8bfdd68a7375dafe;p=rust-lightning impl Readable/Writable for Route --- diff --git a/src/ln/router.rs b/src/ln/router.rs index 0d049f5a7..9fe2cfb50 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -13,9 +13,9 @@ use bitcoin::blockdata::opcodes; use chain::chaininterface::{ChainError, ChainWatchInterface}; use ln::channelmanager; -use ln::msgs::{ErrorAction,HandleError,RoutingMessageHandler,NetAddress,GlobalFeatures}; +use ln::msgs::{DecodeError,ErrorAction,HandleError,RoutingMessageHandler,NetAddress,GlobalFeatures}; use ln::msgs; -use util::ser::Writeable; +use util::ser::{Writeable, Readable}; use util::logger::Logger; use std::cmp; @@ -47,6 +47,37 @@ pub struct Route { pub hops: Vec, } +impl Writeable for Route { + fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { + (self.hops.len() as u8).write(writer)?; + for hop in self.hops.iter() { + hop.pubkey.write(writer)?; + hop.short_channel_id.write(writer)?; + hop.fee_msat.write(writer)?; + hop.cltv_expiry_delta.write(writer)?; + } + Ok(()) + } +} + +impl Readable for Route { + fn read(reader: &mut R) -> Result { + let hops_count: u8 = Readable::read(reader)?; + let mut hops = Vec::with_capacity(hops_count as usize); + for _ in 0..hops_count { + hops.push(RouteHop { + pubkey: Readable::read(reader)?, + short_channel_id: Readable::read(reader)?, + fee_msat: Readable::read(reader)?, + cltv_expiry_delta: Readable::read(reader)?, + }); + } + Ok(Route { + hops + }) + } +} + struct DirectionalChannelInfo { src_node_id: PublicKey, last_update: u32,