@@ -267,6 +267,60 @@ impl ShortChannelId {
267
267
}
268
268
}
269
269
270
+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
271
+ pub struct ShortChannelIdDir {
272
+ pub short_channel_id : ShortChannelId ,
273
+ pub direction : u32 ,
274
+ }
275
+ impl Serialize for ShortChannelIdDir {
276
+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
277
+ where
278
+ S : Serializer ,
279
+ {
280
+ serializer. serialize_str ( & self . to_string ( ) )
281
+ }
282
+ }
283
+
284
+ impl < ' de > Deserialize < ' de > for ShortChannelIdDir {
285
+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
286
+ where
287
+ D : Deserializer < ' de > ,
288
+ {
289
+ use serde:: de:: Error ;
290
+ let s: String = Deserialize :: deserialize ( deserializer) ?;
291
+ Ok ( Self :: from_str ( & s) . map_err ( |e| Error :: custom ( e. to_string ( ) ) ) ?)
292
+ }
293
+ }
294
+ impl FromStr for ShortChannelIdDir {
295
+ type Err = crate :: Error ;
296
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
297
+ let parts: Result < Vec < String > , _ > = s. split ( '/' ) . map ( |p| p. parse ( ) ) . collect ( ) ;
298
+ let parts = parts. with_context ( || format ! ( "Malformed short_channel_id_dir: {}" , s) ) ?;
299
+ if parts. len ( ) != 2 {
300
+ return Err ( anyhow ! (
301
+ "Malformed short_channel_id_dir: element count mismatch"
302
+ ) ) ;
303
+ }
304
+
305
+ Ok ( ShortChannelIdDir {
306
+ short_channel_id : ShortChannelId :: from_str ( & parts[ 0 ] ) ?,
307
+ direction : parts[ 1 ] . parse :: < u32 > ( ) ?,
308
+ } )
309
+ }
310
+ }
311
+ impl Display for ShortChannelIdDir {
312
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
313
+ write ! (
314
+ f,
315
+ "{}x{}x{}/{}" ,
316
+ self . short_channel_id. block( ) ,
317
+ self . short_channel_id. txindex( ) ,
318
+ self . short_channel_id. outnum( ) ,
319
+ self . direction
320
+ )
321
+ }
322
+ }
323
+
270
324
#[ derive( Clone , Copy , Debug ) ]
271
325
pub struct Secret ( [ u8 ; 32 ] ) ;
272
326
0 commit comments