Skip to content

Commit 30a01b1

Browse files
author
Antoine Riard
committed
Add Event::ChannelClosed generation at channel shutdown
1 parent afae12e commit 30a01b1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lightning/src/util/events.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use bitcoin::blockdata::script::Script;
2424
use bitcoin::secp256k1::key::PublicKey;
2525

2626
use prelude::*;
27+
use core::cmp;
2728
use core::time::Duration;
2829
use core::ops::Deref;
2930

@@ -135,6 +136,14 @@ pub enum Event {
135136
/// The outputs which you should store as spendable by you.
136137
outputs: Vec<SpendableOutputDescriptor>,
137138
},
139+
/// Used to indicate that a channel was closed at the given timestamp.
140+
ChannelClosed {
141+
/// The channel_id which has been barren from further off-chain updates but
142+
/// funding output might still be not resolved yet.
143+
channel_id: [u8; 32],
144+
/// A human-readable error message
145+
err: String
146+
}
138147
}
139148

140149
impl Writeable for Event {
@@ -189,6 +198,13 @@ impl Writeable for Event {
189198
(0, VecWriteWrapper(outputs), required),
190199
});
191200
},
201+
&Event::ChannelClosed { ref channel_id, ref err } => {
202+
6u8.write(writer)?;
203+
channel_id.write(writer)?;
204+
(err.len() as u16).write(writer)?;
205+
writer.write_all(err.as_bytes())?;
206+
write_tlv_fields!(writer, {});
207+
},
192208
}
193209
Ok(())
194210
}
@@ -275,6 +291,24 @@ impl MaybeReadable for Event {
275291
};
276292
f()
277293
},
294+
6u8 => {
295+
let f = || {
296+
let channel_id = Readable::read(reader)?;
297+
let err = {
298+
let mut size: usize = <u16 as Readable>::read(reader)? as usize;
299+
let mut data = vec![];
300+
let data_len = reader.read_to_end(&mut data)?;
301+
size = cmp::min(data_len, size);
302+
match String::from_utf8(data[..size as usize].to_vec()) {
303+
Ok(s) => s,
304+
Err(_) => return Err(msgs::DecodeError::InvalidValue),
305+
}
306+
};
307+
read_tlv_fields!(reader, {});
308+
Ok(Some(Event::ChannelClosed { channel_id, err: err }))
309+
};
310+
f()
311+
},
278312
_ => Err(msgs::DecodeError::InvalidValue)
279313
}
280314
}

0 commit comments

Comments
 (0)