mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-28 07:15:57 +00:00
keep up with nim-eth
This commit is contained in:
parent
04cf6d30eb
commit
b9cc91aef8
@ -1,3 +1,7 @@
|
|||||||
|
# TODO Cannot use push here becaise it gets applied to PeerID.init (!)
|
||||||
|
# probably because it's a generic proc...
|
||||||
|
# {.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
os, net, strutils, strformat, parseutils,
|
os, net, strutils, strformat, parseutils,
|
||||||
chronicles, stew/[result, objects], eth/keys, eth/trie/db, eth/p2p/enode,
|
chronicles, stew/[result, objects], eth/keys, eth/trie/db, eth/p2p/enode,
|
||||||
@ -14,11 +18,11 @@ type
|
|||||||
export
|
export
|
||||||
Eth2DiscoveryProtocol, open, start, close, result
|
Eth2DiscoveryProtocol, open, start, close, result
|
||||||
|
|
||||||
proc toENode*(a: MultiAddress): Result[ENode, cstring] =
|
proc toENode*(a: MultiAddress): Result[ENode, cstring] {.raises: [Defect].} =
|
||||||
if not IPFS.match(a):
|
|
||||||
return err "Unsupported MultiAddress"
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if not IPFS.match(a):
|
||||||
|
return err "Unsupported MultiAddress"
|
||||||
|
|
||||||
# TODO. This code is quite messy with so much string handling.
|
# TODO. This code is quite messy with so much string handling.
|
||||||
# MultiAddress can offer a more type-safe API?
|
# MultiAddress can offer a more type-safe API?
|
||||||
var
|
var
|
||||||
@ -53,6 +57,10 @@ proc toENode*(a: MultiAddress): Result[ENode, cstring] =
|
|||||||
except CatchableError:
|
except CatchableError:
|
||||||
# This will reach the error exit path below
|
# This will reach the error exit path below
|
||||||
discard
|
discard
|
||||||
|
except Exception:
|
||||||
|
# TODO:
|
||||||
|
# libp2p/crypto/ecnist.nim(118, 20) Error: can raise an unlisted exception: Exception
|
||||||
|
discard
|
||||||
|
|
||||||
return err "Invalid MultiAddress"
|
return err "Invalid MultiAddress"
|
||||||
|
|
||||||
@ -61,7 +69,7 @@ proc toMultiAddressStr*(enode: ENode): string =
|
|||||||
scheme: Secp256k1, skkey: SkPublicKey(enode.pubkey)))
|
scheme: Secp256k1, skkey: SkPublicKey(enode.pubkey)))
|
||||||
&"/ip4/{enode.address.ip}/tcp/{enode.address.tcpPort}/p2p/{peerId.pretty}"
|
&"/ip4/{enode.address.ip}/tcp/{enode.address.tcpPort}/p2p/{peerId.pretty}"
|
||||||
|
|
||||||
proc toENode*(enrRec: enr.Record): Result[ENode, cstring] =
|
proc toENode*(enrRec: enr.Record): Result[ENode, cstring] {.raises: [Defect].} =
|
||||||
try:
|
try:
|
||||||
# TODO: handle IPv6
|
# TODO: handle IPv6
|
||||||
let ipBytes = enrRec.get("ip", seq[byte])
|
let ipBytes = enrRec.get("ip", seq[byte])
|
||||||
@ -72,10 +80,10 @@ proc toENode*(enrRec: enr.Record): Result[ENode, cstring] =
|
|||||||
address_v4: toArray(4, ipBytes))
|
address_v4: toArray(4, ipBytes))
|
||||||
tcpPort = Port enrRec.get("tcp", uint16)
|
tcpPort = Port enrRec.get("tcp", uint16)
|
||||||
udpPort = Port enrRec.get("udp", uint16)
|
udpPort = Port enrRec.get("udp", uint16)
|
||||||
var pubKey: PublicKey
|
let pubkey = enrRec.get(PublicKey)
|
||||||
if not enrRec.get(pubKey):
|
if pubkey.isNone:
|
||||||
return err "Failed to read public key from ENR record"
|
return err "Failed to read public key from ENR record"
|
||||||
return ok ENode(pubkey: pubkey,
|
return ok ENode(pubkey: pubkey.get(),
|
||||||
address: Address(ip: ip,
|
address: Address(ip: ip,
|
||||||
tcpPort: tcpPort,
|
tcpPort: tcpPort,
|
||||||
udpPort: udpPort))
|
udpPort: udpPort))
|
||||||
|
2
vendor/nim-eth
vendored
2
vendor/nim-eth
vendored
@ -1 +1 @@
|
|||||||
Subproject commit ac5bbe4d3d04ca1baf455f5a7e22a04692bcc73a
|
Subproject commit 19426e82f926277e9a8e602c9551da4382d568dd
|
Loading…
x
Reference in New Issue
Block a user