@@ -132,6 +132,15 @@ pub struct Init {
132
132
pub local_features : LocalFeatures ,
133
133
}
134
134
135
+ pub struct Ping {
136
+ pub ponglen : u16 ,
137
+ pub byteslen : u16 ,
138
+ }
139
+
140
+ pub struct Pong {
141
+ pub byteslen : u16 ,
142
+ }
143
+
135
144
pub struct OpenChannel {
136
145
pub chain_hash : Sha256dHash ,
137
146
pub temporary_channel_id : Uint256 ,
@@ -572,6 +581,54 @@ impl MsgEncodable for Init {
572
581
}
573
582
}
574
583
584
+ impl MsgDecodable for Ping {
585
+ fn decode ( v : & [ u8 ] ) -> Result < Self , DecodeError > {
586
+ if v. len ( ) < 4 {
587
+ return Err ( DecodeError :: WrongLength ) ;
588
+ }
589
+ let ponglen = byte_utils:: slice_to_be16 ( & v[ 0 ..2 ] ) ;
590
+ let byteslen = byte_utils:: slice_to_be16 ( & v[ 2 ..4 ] ) ;
591
+ if v. len ( ) < 4 + byteslen as usize {
592
+ return Err ( DecodeError :: WrongLength ) ;
593
+ }
594
+ Ok ( Self {
595
+ ponglen,
596
+ byteslen,
597
+ } )
598
+ }
599
+ }
600
+ impl MsgEncodable for Ping {
601
+ fn encode ( & self ) -> Vec < u8 > {
602
+ let mut res = Vec :: with_capacity ( self . byteslen as usize + 2 ) ;
603
+ res. extend_from_slice ( & byte_utils:: be16_to_array ( self . byteslen ) ) ;
604
+ res. resize ( 2 + self . byteslen as usize , 0 ) ;
605
+ res
606
+ }
607
+ }
608
+
609
+ impl MsgDecodable for Pong {
610
+ fn decode ( v : & [ u8 ] ) -> Result < Self , DecodeError > {
611
+ if v. len ( ) < 2 {
612
+ return Err ( DecodeError :: WrongLength ) ;
613
+ }
614
+ let byteslen = byte_utils:: slice_to_be16 ( & v[ 0 ..2 ] ) ;
615
+ if v. len ( ) < 2 + byteslen as usize {
616
+ return Err ( DecodeError :: WrongLength ) ;
617
+ }
618
+ Ok ( Self {
619
+ byteslen
620
+ } )
621
+ }
622
+ }
623
+ impl MsgEncodable for Pong {
624
+ fn encode ( & self ) -> Vec < u8 > {
625
+ let mut res = Vec :: with_capacity ( self . byteslen as usize + 2 ) ;
626
+ res. extend_from_slice ( & byte_utils:: be16_to_array ( self . byteslen ) ) ;
627
+ res. resize ( 2 + self . byteslen as usize , 0 ) ;
628
+ res
629
+ }
630
+ }
631
+
575
632
impl MsgDecodable for OpenChannel {
576
633
fn decode ( v : & [ u8 ] ) -> Result < Self , DecodeError > {
577
634
if v. len ( ) < 2 * 32 +6 * 8 +4 +2 * 2 +6 * 33 +1 {
0 commit comments