File tree Expand file tree Collapse file tree 5 files changed +10
-12
lines changed
Expand file tree Collapse file tree 5 files changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ use fuel_core_chain_config::{
2525use fuel_core_p2p:: {
2626 codecs:: {
2727 request_response:: RequestResponseMessageHandler ,
28- unbounded :: GossipsubMessageHandler ,
28+ gossipsub :: GossipsubMessageHandler ,
2929 } ,
3030 network_service:: FuelP2PService ,
3131 p2p_service:: FuelP2PEvent ,
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ pub trait Encode<T: ?Sized> {
3737pub trait Decode < T > {
3838 type Error ;
3939 /// Decodes the type `T` from the bytes.
40- fn decode ( bytes : & [ u8 ] ) -> Result < T , Self :: Error > ;
40+ fn decode ( & self , bytes : & [ u8 ] ) -> Result < T , Self :: Error > ;
4141}
4242
4343impl < ' a > Encoder for Cow < ' a , [ u8 ] > {
Original file line number Diff line number Diff line change 4444 ) -> Result < Self :: ResponseMessage , io:: Error > {
4545 let decoded_response = match gossipsub_tag {
4646 GossipTopicTag :: NewTx => {
47- GossipsubMessage :: NewTx ( Format :: decode ( encoded_data) ?)
47+ GossipsubMessage :: NewTx ( self . data_format . decode ( encoded_data) ?)
4848 }
4949 } ;
5050
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ impl RequestResponseMessageHandler<PostcardDataFormat> {
3030impl GossipsubMessageHandler < PostcardDataFormat > {
3131 pub fn new ( ) -> Self {
3232 GossipsubMessageHandler {
33- data_format : PostcardDataFormat ,
33+ codec : PostcardDataFormat ,
3434 }
3535 }
3636}
5555{
5656 type Error = io:: Error ;
5757
58- fn decode ( bytes : & [ u8 ] ) -> Result < T , Self :: Error > {
58+ fn decode ( & self , bytes : & [ u8 ] ) -> Result < T , Self :: Error > {
5959 postcard:: from_bytes ( bytes)
6060 . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: Other , e. to_string ( ) ) )
6161 }
@@ -228,7 +228,7 @@ mod tests {
228228 let deserialized_as_v1 =
229229 // We cannot access the codec trait from an old node here,
230230 // so we deserialize directly using the `V1ResponseMessage` type.
231- < PostcardDataFormat as Decode < V1ResponseMessage > > :: decode ( & buf) . expect ( "Deserialization as V1ResponseMessage should succeed" ) ;
231+ codec . data_format . decode ( & buf) . expect ( "Deserialization as V1ResponseMessage should succeed" ) ;
232232
233233 // Then
234234 assert ! ( matches!(
Original file line number Diff line number Diff line change 6868 . take ( self . max_response_size as u64 )
6969 . read_to_end ( & mut response)
7070 . await ?;
71- Format :: decode ( & response)
71+ self . data_format . decode ( & response)
7272 }
7373
7474 async fn read_response < T > (
@@ -87,13 +87,11 @@ where
8787
8888 match protocol {
8989 RequestResponseProtocol :: V1 => {
90- let v1_response =
91- < Format as Decode < V1ResponseMessage > > :: decode ( & response) ?;
90+ let v1_response: V1ResponseMessage =
91+ self . data_format . decode ( & response) ?;
9292 Ok ( v1_response. into ( ) )
9393 }
94- RequestResponseProtocol :: V2 => {
95- <Format as Decode < V2ResponseMessage > >:: decode ( & response)
96- }
94+ RequestResponseProtocol :: V2 => self . data_format . decode ( & response) ,
9795 }
9896 }
9997
You can’t perform that action at this time.
0 commit comments