Skip to content

Commit 5194d73

Browse files
committed
impl Read/Write to ChannelDetails
1 parent 31bc04f commit 5194d73

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use util::errors::APIError;
4545

4646
use std::{cmp, mem};
4747
use std::collections::{HashMap, hash_map, HashSet};
48-
use std::io::{Cursor, Read};
48+
use std::io::{Cursor, Read, Error};
4949
use std::sync::{Arc, Mutex, MutexGuard, RwLock};
5050
use std::sync::atomic::{AtomicUsize, Ordering};
5151
use std::time::Duration;
@@ -485,6 +485,39 @@ pub struct ChannelDetails {
485485
pub is_live: bool,
486486
}
487487

488+
impl Writeable for ChannelDetails {
489+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
490+
self.channel_id.write(writer)?;
491+
self.short_channel_id.write(writer)?;
492+
self.remote_network_id.write(writer)?;
493+
self.counterparty_features.write(writer)?;
494+
self.channel_value_satoshis.write(writer)?;
495+
self.user_id.write(writer)?;
496+
self.outbound_capacity_msat.write(writer)?;
497+
self.inbound_capacity_msat.write(writer)?;
498+
self.is_live.write(writer)?;
499+
Ok(())
500+
}
501+
}
502+
503+
impl Readable for ChannelDetails {
504+
fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
505+
let channel_id: [u8; 32] = Readable::read(reader)?;
506+
let short_channel_id: Option<u64> = Readable::read(reader)?;
507+
let remote_network_id: PublicKey = Readable::read(reader)?;
508+
let counterparty_features: InitFeatures = Readable::read(reader)?;
509+
let channel_value_satoshis: u64 = Readable::read(reader)?;
510+
let user_id: u64 = Readable::read(reader)?;
511+
let outbound_capacity_msat: u64 = Readable::read(reader)?;
512+
let inbound_capacity_msat: u64 = Readable::read(reader)?;
513+
let is_live: bool = Readable::read(reader)?;
514+
Ok(ChannelDetails {
515+
channel_id, short_channel_id, remote_network_id, counterparty_features,
516+
channel_value_satoshis, user_id, outbound_capacity_msat, inbound_capacity_msat, is_live
517+
})
518+
}
519+
}
520+
488521
/// If a payment fails to send, it can be in one of several states. This enum is returned as the
489522
/// Err() type describing which state the payment is in, see the description of individual enum
490523
/// states for more.

0 commit comments

Comments
 (0)