-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove unnecessary conversion from Multiaddr to IP (#369)
* Remove unnecessary conversion from Multiaddr to IP * Uncomment un-implemented code * chore: use proper change:multiaddrs event handler * chore: add multiaddr as dependency Co-authored-by: Cayman <caymannava@gmail.com>
- Loading branch information
1 parent
053709e
commit e37c7c2
Showing
10 changed files
with
150 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Multiaddr } from '@multiformats/multiaddr' | ||
import { convertToString } from '@multiformats/multiaddr/convert' | ||
|
||
// Protocols https://github.com/multiformats/multiaddr/blob/master/protocols.csv | ||
// code size name | ||
// 4 32 ip4 | ||
// 41 128 ip6 | ||
enum Protocol { | ||
ip4 = 4, | ||
ip6 = 41 | ||
} | ||
|
||
export function multiaddrToIPStr(multiaddr: Multiaddr): string | null { | ||
for (const tuple of multiaddr.tuples()) { | ||
switch (tuple[0]) { | ||
case Protocol.ip4: | ||
case Protocol.ip6: | ||
return convertToString(tuple[0], tuple[1]!) | ||
} | ||
} | ||
|
||
return null | ||
} |
Oops, something went wrong.