diff --git a/libp2p/multiaddress.nim b/libp2p/multiaddress.nim index 69915bd0d..e1668dade 100644 --- a/libp2p/multiaddress.nim +++ b/libp2p/multiaddress.nim @@ -12,7 +12,7 @@ {.push raises: [].} {.push public.} -import pkg/chronos, chronicles +import pkg/[chronos, chronicles, results] import std/[nativesockets, net, hashes] import tables, strutils, sets import @@ -25,8 +25,8 @@ import protobuf/minprotobuf, errors, utility -import stew/[base58, base32, endians2, results] -export results, minprotobuf, vbuffer, utility +import stew/[base58, base32, endians2] +export results, minprotobuf, vbuffer, errors, utility logScope: topics = "libp2p multiaddress" @@ -71,6 +71,9 @@ type tcpProtocol udpProtocol +func maErr*(msg: string): ref MaError = + (ref MaError)(msg: msg) + const # These are needed in order to avoid an ambiguity error stemming from # some cint constants with the same name defined in the posix modules @@ -970,23 +973,21 @@ proc append*(m1: var MultiAddress, m2: MultiAddress): MaResult[void] = else: ok() -proc `&`*(m1, m2: MultiAddress): MultiAddress {.raises: [LPError].} = +proc `&`*(m1, m2: MultiAddress): MultiAddress {.raises: [MaError].} = ## Concatenates two addresses ``m1`` and ``m2``, and returns result. ## ## This procedure performs validation of concatenated result and can raise ## exception on error. - ## + concat(m1, m2).valueOr: + raise maErr error - concat(m1, m2).tryGet() - -proc `&=`*(m1: var MultiAddress, m2: MultiAddress) {.raises: [LPError].} = +proc `&=`*(m1: var MultiAddress, m2: MultiAddress) {.raises: [MaError].} = ## Concatenates two addresses ``m1`` and ``m2``. ## ## This procedure performs validation of concatenated result and can raise ## exception on error. - ## - - m1.append(m2).tryGet() + m1.append(m2).isOkOr: + raise maErr error proc `==`*(m1: var MultiAddress, m2: MultiAddress): bool = ## Check of two MultiAddress are equal