mirror of https://github.com/vacp2p/nim-libp2p.git
ensure all multiaddress routines use Result
This commit is contained in:
parent
75b023c9e5
commit
3d9948a65e
|
@ -841,7 +841,7 @@ proc init*(mtype: typedesc[MultiAddress]): MultiAddress =
|
||||||
proc init*(mtype: typedesc[MultiAddress],
|
proc init*(mtype: typedesc[MultiAddress],
|
||||||
address: ValidIpAddress,
|
address: ValidIpAddress,
|
||||||
protocol: IpTransportProtocol,
|
protocol: IpTransportProtocol,
|
||||||
port: Port): MultiAddress =
|
port: Port): MaResult[MultiAddress] =
|
||||||
let
|
let
|
||||||
familyProto = case address.family
|
familyProto = case address.family
|
||||||
of IpAddressFamily.IPv4: getProtocol("ip4")
|
of IpAddressFamily.IPv4: getProtocol("ip4")
|
||||||
|
@ -854,15 +854,17 @@ proc init*(mtype: typedesc[MultiAddress],
|
||||||
var data = initVBuffer()
|
var data = initVBuffer()
|
||||||
data.write(familyProto.mcodec)
|
data.write(familyProto.mcodec)
|
||||||
var written = familyProto.coder.stringToBuffer($address, data)
|
var written = familyProto.coder.stringToBuffer($address, data)
|
||||||
doAssert written,
|
if not written:
|
||||||
"Merely writing a string to a buffer should always be possible, address: " & $address
|
return err("multiaddress: Merely writing a string to a buffer should always be possible, address")
|
||||||
|
|
||||||
data.write(protoProto.mcodec)
|
data.write(protoProto.mcodec)
|
||||||
written = protoProto.coder.stringToBuffer($port, data)
|
written = protoProto.coder.stringToBuffer($port, data)
|
||||||
doAssert written,
|
if not written:
|
||||||
"Merely writing a string to a buffer should always be possible, port: " & $address
|
return err("multiaddress: Merely writing a string to a buffer should always be possible, port")
|
||||||
|
|
||||||
data.finish()
|
data.finish()
|
||||||
|
|
||||||
MultiAddress(data: data)
|
ok(MultiAddress(data: data))
|
||||||
|
|
||||||
proc init*(mtype: typedesc[MultiAddress], address: TransportAddress,
|
proc init*(mtype: typedesc[MultiAddress], address: TransportAddress,
|
||||||
protocol = IPPROTO_TCP): MaResult[MultiAddress] =
|
protocol = IPPROTO_TCP): MaResult[MultiAddress] =
|
||||||
|
|
Loading…
Reference in New Issue