@@ -17,7 +17,7 @@ import debug from "debug";
17
17
18
18
import { ERR_INVALID_ID } from "./constants.js" ;
19
19
import { keccak256 , verifySignature } from "./crypto.js" ;
20
- import { multiaddrFromFields } from "./multiaddr_from_fields .js" ;
20
+ import { locationMultiaddrFromEnrFields } from "./get_multiaddr .js" ;
21
21
import { decodeMultiaddrs , encodeMultiaddrs } from "./multiaddrs_codec.js" ;
22
22
import { createPeerIdFromPublicKey } from "./peer_id.js" ;
23
23
import * as v4 from "./v4.js" ;
@@ -231,49 +231,9 @@ export class ENR extends Map<ENRKey, ENRValue> implements IEnr {
231
231
}
232
232
}
233
233
234
- getLocationMultiaddr (
234
+ getLocationMultiaddr : (
235
235
protocol : "udp" | "udp4" | "udp6" | "tcp" | "tcp4" | "tcp6"
236
- ) : Multiaddr | undefined {
237
- if ( protocol === "udp" ) {
238
- return (
239
- this . getLocationMultiaddr ( "udp4" ) || this . getLocationMultiaddr ( "udp6" )
240
- ) ;
241
- }
242
- if ( protocol === "tcp" ) {
243
- return (
244
- this . getLocationMultiaddr ( "tcp4" ) || this . getLocationMultiaddr ( "tcp6" )
245
- ) ;
246
- }
247
- const isIpv6 = protocol . endsWith ( "6" ) ;
248
- const ipVal = this . get ( isIpv6 ? "ip6" : "ip" ) ;
249
- if ( ! ipVal ) {
250
- return ;
251
- }
252
-
253
- const isUdp = protocol . startsWith ( "udp" ) ;
254
- const isTcp = protocol . startsWith ( "tcp" ) ;
255
- let protoName , protoVal ;
256
- if ( isUdp ) {
257
- protoName = "udp" ;
258
- protoVal = isIpv6 ? this . get ( "udp6" ) : this . get ( "udp" ) ;
259
- } else if ( isTcp ) {
260
- protoName = "tcp" ;
261
- protoVal = isIpv6 ? this . get ( "tcp6" ) : this . get ( "tcp" ) ;
262
- } else {
263
- return ;
264
- }
265
-
266
- if ( ! protoVal ) {
267
- return ;
268
- }
269
-
270
- return multiaddrFromFields (
271
- isIpv6 ? "ip6" : "ip4" ,
272
- protoName ,
273
- ipVal ,
274
- protoVal
275
- ) ;
276
- }
236
+ ) => Multiaddr | undefined = locationMultiaddrFromEnrFields . bind ( { } , this ) ;
277
237
278
238
setLocationMultiaddr ( multiaddr : Multiaddr ) : void {
279
239
const protoNames = multiaddr . protoNames ( ) ;
0 commit comments