@@ -162,8 +162,8 @@ impl AddrCache {
162162
163163fn peer_id_from_multiaddr ( addr : & Multiaddr ) -> Option < PeerId > {
164164 addr. iter ( ) . last ( ) . and_then ( |protocol| {
165- if let Protocol :: P2p ( peer_id ) = protocol {
166- Some ( peer_id )
165+ if let Protocol :: P2p ( multihash ) = protocol {
166+ PeerId :: from_multihash ( multihash ) . ok ( )
167167 } else {
168168 None
169169 }
@@ -178,8 +178,7 @@ fn addresses_to_peer_ids(addresses: &HashSet<Multiaddr>) -> HashSet<PeerId> {
178178mod tests {
179179 use super :: * ;
180180
181- use libp2p:: multihash:: Multihash ;
182- use multihash_codetable:: Code ;
181+ use libp2p:: multihash:: { self , Multihash } ;
183182 use quickcheck:: { Arbitrary , Gen , QuickCheck , TestResult } ;
184183
185184 use sp_authority_discovery:: { AuthorityId , AuthorityPair } ;
@@ -201,13 +200,14 @@ mod tests {
201200 impl Arbitrary for TestMultiaddr {
202201 fn arbitrary ( g : & mut Gen ) -> Self {
203202 let seed = ( 0 ..32 ) . map ( |_| u8:: arbitrary ( g) ) . collect :: < Vec < _ > > ( ) ;
204- let peer_id =
205- PeerId :: from_multihash ( Multihash :: wrap ( Code :: Sha2_256 . into ( ) , & seed) . unwrap ( ) )
206- . unwrap ( ) ;
203+ let peer_id = PeerId :: from_multihash (
204+ Multihash :: wrap ( multihash:: Code :: Sha2_256 . into ( ) , & seed) . unwrap ( ) ,
205+ )
206+ . unwrap ( ) ;
207207 let multiaddr = "/ip6/2001:db8:0:0:0:0:0:2/tcp/30333"
208208 . parse :: < Multiaddr > ( )
209209 . unwrap ( )
210- . with ( Protocol :: P2p ( peer_id) ) ;
210+ . with ( Protocol :: P2p ( peer_id. into ( ) ) ) ;
211211
212212 TestMultiaddr ( multiaddr)
213213 }
@@ -219,17 +219,18 @@ mod tests {
219219 impl Arbitrary for TestMultiaddrsSamePeerCombo {
220220 fn arbitrary ( g : & mut Gen ) -> Self {
221221 let seed = ( 0 ..32 ) . map ( |_| u8:: arbitrary ( g) ) . collect :: < Vec < _ > > ( ) ;
222- let peer_id =
223- PeerId :: from_multihash ( Multihash :: wrap ( Code :: Sha2_256 . into ( ) , & seed) . unwrap ( ) )
224- . unwrap ( ) ;
222+ let peer_id = PeerId :: from_multihash (
223+ Multihash :: wrap ( multihash:: Code :: Sha2_256 . into ( ) , & seed) . unwrap ( ) ,
224+ )
225+ . unwrap ( ) ;
225226 let multiaddr1 = "/ip6/2001:db8:0:0:0:0:0:2/tcp/30333"
226227 . parse :: < Multiaddr > ( )
227228 . unwrap ( )
228- . with ( Protocol :: P2p ( peer_id) ) ;
229+ . with ( Protocol :: P2p ( peer_id. into ( ) ) ) ;
229230 let multiaddr2 = "/ip6/2002:db8:0:0:0:0:0:2/tcp/30133"
230231 . parse :: < Multiaddr > ( )
231232 . unwrap ( )
232- . with ( Protocol :: P2p ( peer_id) ) ;
233+ . with ( Protocol :: P2p ( peer_id. into ( ) ) ) ;
233234 TestMultiaddrsSamePeerCombo ( multiaddr1, multiaddr2)
234235 }
235236 }
@@ -366,7 +367,7 @@ mod tests {
366367 let mut addr_cache = AddrCache :: new ( ) ;
367368
368369 let peer_id = PeerId :: random ( ) ;
369- let addr = Multiaddr :: empty ( ) . with ( Protocol :: P2p ( peer_id) ) ;
370+ let addr = Multiaddr :: empty ( ) . with ( Protocol :: P2p ( peer_id. into ( ) ) ) ;
370371
371372 let authority_id0 = AuthorityPair :: generate ( ) . 0 . public ( ) ;
372373 let authority_id1 = AuthorityPair :: generate ( ) . 0 . public ( ) ;
0 commit comments