@@ -6,6 +6,7 @@ use crate::{
66use crate :: logger:: { log_error, log_info, Logger } ;
77
88use lightning:: chain:: chaininterface:: { BroadcasterInterface , ConfirmationTarget , FeeEstimator } ;
9+ use lightning:: impl_writeable_tlv_based_enum;
910use lightning:: ln:: PaymentHash ;
1011use lightning:: routing:: gossip:: NodeId ;
1112use lightning:: util:: errors:: APIError ;
@@ -63,74 +64,26 @@ pub enum Event {
6364 } ,
6465}
6566
66- // TODO: Figure out serialization more concretely - see issue #30
67- impl Readable for Event {
68- fn read < R : lightning:: io:: Read > (
69- reader : & mut R ,
70- ) -> Result < Self , lightning:: ln:: msgs:: DecodeError > {
71- match Readable :: read ( reader) ? {
72- 0u8 => {
73- let payment_hash: PaymentHash = Readable :: read ( reader) ?;
74- Ok ( Self :: PaymentSuccessful { payment_hash } )
75- }
76- 1u8 => {
77- let payment_hash: PaymentHash = Readable :: read ( reader) ?;
78- Ok ( Self :: PaymentFailed { payment_hash } )
79- }
80- 2u8 => {
81- let payment_hash: PaymentHash = Readable :: read ( reader) ?;
82- let amount_msat: u64 = Readable :: read ( reader) ?;
83- Ok ( Self :: PaymentReceived { payment_hash, amount_msat } )
84- }
85- 3u8 => {
86- let channel_id: [ u8 ; 32 ] = Readable :: read ( reader) ?;
87- let user_channel_id: u128 = Readable :: read ( reader) ?;
88- Ok ( Self :: ChannelReady { channel_id, user_channel_id } )
89- }
90- 4u8 => {
91- let channel_id: [ u8 ; 32 ] = Readable :: read ( reader) ?;
92- let user_channel_id: u128 = Readable :: read ( reader) ?;
93- Ok ( Self :: ChannelClosed { channel_id, user_channel_id } )
94- }
95- _ => Err ( lightning:: ln:: msgs:: DecodeError :: InvalidValue ) ,
96- }
97- }
98- }
99-
100- impl Writeable for Event {
101- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , lightning:: io:: Error > {
102- match self {
103- Self :: PaymentSuccessful { payment_hash } => {
104- 0u8 . write ( writer) ?;
105- payment_hash. write ( writer) ?;
106- Ok ( ( ) )
107- }
108- Self :: PaymentFailed { payment_hash } => {
109- 1u8 . write ( writer) ?;
110- payment_hash. write ( writer) ?;
111- Ok ( ( ) )
112- }
113- Self :: PaymentReceived { payment_hash, amount_msat } => {
114- 2u8 . write ( writer) ?;
115- payment_hash. write ( writer) ?;
116- amount_msat. write ( writer) ?;
117- Ok ( ( ) )
118- }
119- Self :: ChannelReady { channel_id, user_channel_id } => {
120- 3u8 . write ( writer) ?;
121- channel_id. write ( writer) ?;
122- user_channel_id. write ( writer) ?;
123- Ok ( ( ) )
124- }
125- Self :: ChannelClosed { channel_id, user_channel_id } => {
126- 4u8 . write ( writer) ?;
127- channel_id. write ( writer) ?;
128- user_channel_id. write ( writer) ?;
129- Ok ( ( ) )
130- }
131- }
132- }
133- }
67+ impl_writeable_tlv_based_enum ! ( Event ,
68+ ( 0 , PaymentSuccessful ) => {
69+ ( 0 , payment_hash, required) ,
70+ } ,
71+ ( 1 , PaymentFailed ) => {
72+ ( 0 , payment_hash, required) ,
73+ } ,
74+ ( 2 , PaymentReceived ) => {
75+ ( 0 , payment_hash, required) ,
76+ ( 1 , amount_msat, required) ,
77+ } ,
78+ ( 3 , ChannelReady ) => {
79+ ( 0 , channel_id, required) ,
80+ ( 1 , user_channel_id, required) ,
81+ } ,
82+ ( 4 , ChannelClosed ) => {
83+ ( 0 , channel_id, required) ,
84+ ( 1 , user_channel_id, required) ,
85+ } ;
86+ ) ;
13487
13588pub ( crate ) struct EventQueue < K : Deref >
13689where
0 commit comments