Replace deprecated ENR functions (#6419)
This commit is contained in:
parent
738bc0e98f
commit
ca15c4e433
|
@ -1269,8 +1269,11 @@ func completeCmdArg*(T: type WalletName, input: string): seq[string] =
|
|||
return @[]
|
||||
|
||||
proc parseCmdArg*(T: type enr.Record, p: string): T {.raises: [ValueError].} =
|
||||
if not fromURI(result, p):
|
||||
raise newException(ValueError, "Invalid ENR")
|
||||
let res = enr.Record.fromURI(p)
|
||||
if res.isErr:
|
||||
raise newException(ValueError, "Invalid ENR:" & $res.error)
|
||||
|
||||
res.value
|
||||
|
||||
func completeCmdArg*(T: type enr.Record, val: string): seq[string] =
|
||||
return @[]
|
||||
|
|
|
@ -25,13 +25,13 @@ type
|
|||
Eth2DiscoveryId* = NodeId
|
||||
|
||||
func parseBootstrapAddress*(address: string):
|
||||
Result[enr.Record, cstring] =
|
||||
Result[enr.Record, string] =
|
||||
let lowerCaseAddress = toLowerAscii(address)
|
||||
if lowerCaseAddress.startsWith("enr:"):
|
||||
var enrRec: enr.Record
|
||||
if enrRec.fromURI(address):
|
||||
return ok enrRec
|
||||
return err "Invalid ENR bootstrap record"
|
||||
let res = enr.Record.fromURI(address)
|
||||
if res.isOk():
|
||||
return ok res.value
|
||||
return err "Invalid bootstrap ENR: " & $res.error
|
||||
elif lowerCaseAddress.startsWith("enode:"):
|
||||
return err "ENode bootstrap addresses are not supported"
|
||||
else:
|
||||
|
|
|
@ -1391,7 +1391,7 @@ proc connectWorker(node: Eth2Node, index: int) {.async: (raises: [CancelledError
|
|||
node.connTable.excl(remotePeerAddr.peerId)
|
||||
|
||||
proc toPeerAddr(node: Node): Result[PeerAddr, cstring] =
|
||||
let nodeRecord = ? node.record.toTypedRecord()
|
||||
let nodeRecord = TypedRecord.fromRecord(node.record)
|
||||
let peerAddr = ? nodeRecord.toPeerAddr(tcpProtocol)
|
||||
ok(peerAddr)
|
||||
|
||||
|
@ -1883,11 +1883,9 @@ proc start*(node: Eth2Node) {.async: (raises: [CancelledError]).} =
|
|||
notice "Discovery disabled; trying bootstrap nodes",
|
||||
nodes = node.discovery.bootstrapRecords.len
|
||||
for enr in node.discovery.bootstrapRecords:
|
||||
let tr = enr.toTypedRecord()
|
||||
if tr.isOk():
|
||||
let pa = tr.get().toPeerAddr(tcpProtocol)
|
||||
if pa.isOk():
|
||||
await node.connQueue.addLast(pa.get())
|
||||
let pa = TypedRecord.fromRecord(enr).toPeerAddr(tcpProtocol)
|
||||
if pa.isOk():
|
||||
await node.connQueue.addLast(pa.get())
|
||||
node.peerPingerHeartbeatFut = node.peerPingerHeartbeat()
|
||||
node.peerTrimmerHeartbeatFut = node.peerTrimmerHeartbeat()
|
||||
|
||||
|
@ -2279,7 +2277,10 @@ proc createEth2Node*(rng: ref HmacDrbgContext,
|
|||
let (peerId, address) =
|
||||
if s.startsWith("enr:"):
|
||||
let
|
||||
typedEnr = parseBootstrapAddress(s).get().toTypedRecord().get()
|
||||
enr = parseBootstrapAddress(s).valueOr:
|
||||
fatal "Failed to parse bootstrap address", enr=s
|
||||
quit 1
|
||||
typedEnr = TypedRecord.fromRecord(enr)
|
||||
peerAddress = toPeerAddr(typedEnr, tcpProtocol).get()
|
||||
(peerAddress.peerId, peerAddress.addrs[0])
|
||||
elif s.startsWith("/"):
|
||||
|
|
|
@ -108,8 +108,7 @@ proc getLastSeenAddress(node: BeaconNode, id: PeerId): string =
|
|||
""
|
||||
proc getDiscoveryAddresses(node: BeaconNode): seq[string] =
|
||||
let
|
||||
typedRec = node.network.enrRecord().toTypedRecord().valueOr:
|
||||
return default(seq[string])
|
||||
typedRec = TypedRecord.fromRecord(node.network.enrRecord())
|
||||
peerAddr = typedRec.toPeerAddr(udpProtocol).valueOr:
|
||||
return default(seq[string])
|
||||
maddress = MultiAddress.init(multiCodec("p2p"), peerAddr.peerId).valueOr:
|
||||
|
|
Loading…
Reference in New Issue