mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
impl Readable/Writable for Route
This commit is contained in:
parent
74cec623fd
commit
4eafd37d20
1 changed files with 33 additions and 2 deletions
|
@ -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<RouteHop>,
|
||||
}
|
||||
|
||||
impl Writeable for Route {
|
||||
fn write<W: ::util::ser::Writer>(&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<R: ::std::io::Read> Readable<R> for Route {
|
||||
fn read(reader: &mut R) -> Result<Route, DecodeError> {
|
||||
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,
|
||||
|
|
Loading…
Add table
Reference in a new issue