fromMultiaddr static method
Implementation
static AddrInfo fromMultiaddr(MultiAddr addr){
// Extract the peer ID from the multiaddress string
final addrStr = addr.toString();
final parts = addrStr.split('/');
// Find the p2p component and extract the peer ID
int p2pIndex = parts.indexOf('p2p');
if (p2pIndex == -1 || p2pIndex + 1 >= parts.length) {
throw Exception('Failed to extract peer ID from address: $addrStr');
}
final peerIdStr = parts[p2pIndex + 1];
// Create a PeerId from the string
final peerId = PeerId.fromString(peerIdStr);
// Create an AddrInfo with the peer ID and the multiaddress
return AddrInfo(peerId, [addr]);
}