From 4eafd37d2033a9825c76faef8bfdd68a7375dafe Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 18 Oct 2018 21:34:41 -0400 Subject: [PATCH] impl Readable/Writable for Route --- src/ln/router.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) 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, -- 2.39.5