Skip to content

Commit

Permalink
fix: replace TaintedString type deprecated in nim 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo Delgado committed Nov 2, 2022
1 parent 8fee1b9 commit 98b8136
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
12 changes: 6 additions & 6 deletions apps/chat2/config_chat2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -297,33 +297,33 @@ type
name: "rln-relay-cred-password" }: string

# NOTE: Keys are different in nim-libp2p
proc parseCmdArg*(T: type crypto.PrivateKey, p: TaintedString): T =
proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
try:
let key = SkPrivateKey.init(utils.fromHex(p)).tryGet()
# XXX: Here at the moment
result = crypto.PrivateKey(scheme: Secp256k1, skkey: key)
except CatchableError as e:
raise newException(ConfigurationError, "Invalid private key")

proc completeCmdArg*(T: type crypto.PrivateKey, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type ValidIpAddress, p: TaintedString): T =
proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
try:
result = ValidIpAddress.init(p)
except CatchableError as e:
raise newException(ConfigurationError, "Invalid IP address")

proc completeCmdArg*(T: type ValidIpAddress, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type Port, p: TaintedString): T =
proc parseCmdArg*(T: type Port, p: string): T =
try:
result = Port(parseInt(p))
except CatchableError as e:
raise newException(ConfigurationError, "Invalid Port number")

proc completeCmdArg*(T: type Port, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type Port, val: string): seq[string] =
return @[]

func defaultListenAddress*(conf: Chat2Conf): ValidIpAddress =
Expand Down
12 changes: 6 additions & 6 deletions apps/chat2bridge/config_chat2bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,33 @@ type
defaultValue: "/toy-chat/2/huilong/proto"
name: "content-topic" }: string

proc parseCmdArg*(T: type keys.KeyPair, p: TaintedString): T =
proc parseCmdArg*(T: type keys.KeyPair, p: string): T =
try:
let privkey = keys.PrivateKey.fromHex(string(p)).tryGet()
result = privkey.toKeyPair()
except CatchableError:
raise newException(ConfigurationError, "Invalid private key")

proc completeCmdArg*(T: type keys.KeyPair, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type keys.KeyPair, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type crypto.PrivateKey, p: TaintedString): T =
proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
let key = SkPrivateKey.init(p)
if key.isOk():
crypto.PrivateKey(scheme: Secp256k1, skkey: key.get())
else:
raise newException(ConfigurationError, "Invalid private key")

proc completeCmdArg*(T: type crypto.PrivateKey, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type ValidIpAddress, p: TaintedString): T =
proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
try:
result = ValidIpAddress.init(p)
except CatchableError:
raise newException(ConfigurationError, "Invalid IP address")

proc completeCmdArg*(T: type ValidIpAddress, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
return @[]

func defaultListenAddress*(conf: Chat2MatterbridgeConf): ValidIpAddress =
Expand Down
12 changes: 6 additions & 6 deletions apps/wakubridge/config_bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -151,33 +151,33 @@ type
defaultValue: "/waku/2/default-waku/proto"
name: "bridge-pubsub-topic" }: string

proc parseCmdArg*(T: type keys.KeyPair, p: TaintedString): T =
proc parseCmdArg*(T: type keys.KeyPair, p: string): T =
try:
let privkey = keys.PrivateKey.fromHex(string(p)).tryGet()
result = privkey.toKeyPair()
except CatchableError:
raise newException(ConfigurationError, "Invalid private key")

proc completeCmdArg*(T: type keys.KeyPair, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type keys.KeyPair, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type crypto.PrivateKey, p: TaintedString): T =
proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
let key = SkPrivateKey.init(p)
if key.isOk():
crypto.PrivateKey(scheme: Secp256k1, skkey: key.get())
else:
raise newException(ConfigurationError, "Invalid private key")

proc completeCmdArg*(T: type crypto.PrivateKey, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type ValidIpAddress, p: TaintedString): T =
proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
try:
result = ValidIpAddress.init(p)
except CatchableError:
raise newException(ConfigurationError, "Invalid IP address")

proc completeCmdArg*(T: type ValidIpAddress, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
return @[]

func defaultListenAddress*(conf: WakuNodeConf): ValidIpAddress =
Expand Down
12 changes: 6 additions & 6 deletions apps/wakunode2/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -436,33 +436,33 @@ type
name: "websocket-secure-cert-path"}: string

# NOTE: Keys are different in nim-libp2p
proc parseCmdArg*(T: type crypto.PrivateKey, p: TaintedString): T =
proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
try:
let key = SkPrivateKey.init(utils.fromHex(p)).tryGet()
# XXX: Here at the moment
result = crypto.PrivateKey(scheme: Secp256k1, skkey: key)
except CatchableError as e:
raise newException(ConfigurationError, "Invalid private key")

proc completeCmdArg*(T: type crypto.PrivateKey, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type ValidIpAddress, p: TaintedString): T =
proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
try:
result = ValidIpAddress.init(p)
except CatchableError as e:
raise newException(ConfigurationError, "Invalid IP address")

proc completeCmdArg*(T: type ValidIpAddress, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type Port, p: TaintedString): T =
proc parseCmdArg*(T: type Port, p: string): T =
try:
result = Port(parseInt(p))
except CatchableError as e:
raise newException(ConfigurationError, "Invalid Port number")

proc completeCmdArg*(T: type Port, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type Port, val: string): seq[string] =
return @[]

proc defaultListenAddress*(): ValidIpAddress =
Expand Down
8 changes: 4 additions & 4 deletions examples/v1/config_example.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ type
defaultValue: KeyPair.random(keys.newRng()[])
name: "nodekey" .}: KeyPair

proc parseCmdArg*(T: type KeyPair, p: TaintedString): T =
proc parseCmdArg*(T: type KeyPair, p: string): T =
try:
let privkey = PrivateKey.fromHex(string(p)).tryGet()
result = privkey.toKeyPair()
except CatchableError as e:
raise newException(ConfigurationError, "Invalid private key")

proc completeCmdArg*(T: type KeyPair, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type KeyPair, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type IpAddress, p: TaintedString): T =
proc parseCmdArg*(T: type IpAddress, p: string): T =
try:
result = parseIpAddress(p)
except CatchableError as e:
raise newException(ConfigurationError, "Invalid IP address")

proc completeCmdArg*(T: type IpAddress, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type IpAddress, val: string): seq[string] =
return @[]
4 changes: 2 additions & 2 deletions tools/wakucanary/wakucanary.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ type
abbr: "l" .}: LogLevel


proc parseCmdArg*(T: type chronos.Duration, p: TaintedString): T =
proc parseCmdArg*(T: type chronos.Duration, p: string): T =
try:
result = chronos.seconds(parseInt(p))
except CatchableError as e:
raise newException(ConfigurationError, "Invalid timeout value")

proc completeCmdArg*(T: type chronos.Duration, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type chronos.Duration, val: string): seq[string] =
return @[]

# checks if rawProtocols (skipping version) are supported in nodeProtocols
Expand Down
8 changes: 4 additions & 4 deletions waku/v1/node/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,21 @@ type
of genNodekey:
discard

proc parseCmdArg*(T: type KeyPair, p: TaintedString): T =
proc parseCmdArg*(T: type KeyPair, p: string): T =
try:
let privkey = PrivateKey.fromHex(string(p)).tryGet()
result = privkey.toKeyPair()
except CatchableError:
raise newException(ConfigurationError, "Invalid private key")

proc completeCmdArg*(T: type KeyPair, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type KeyPair, val: string): seq[string] =
return @[]

proc parseCmdArg*(T: type IpAddress, p: TaintedString): T =
proc parseCmdArg*(T: type IpAddress, p: string): T =
try:
result = parseIpAddress(p)
except CatchableError:
raise newException(ConfigurationError, "Invalid IP address")

proc completeCmdArg*(T: type IpAddress, val: TaintedString): seq[string] =
proc completeCmdArg*(T: type IpAddress, val: string): seq[string] =
return @[]
2 changes: 1 addition & 1 deletion waku/v2/node/discv5/waku_discv5.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type
# Helper functions #
####################

proc parseBootstrapAddress(address: TaintedString):
proc parseBootstrapAddress(address: string):
Result[enr.Record, cstring] =
logScope:
address = string(address)
Expand Down
2 changes: 1 addition & 1 deletion waku/v2/protocol/waku_swap/waku_swap_contracts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type NodeTaskJsonResult = Result[JsonNode, string]
const taskPrelude = "npx hardhat --network localhost "
const cmdPrelude = "cd ../swap-contracts-module; " & taskPrelude

# proc execNodeTask(taskStr: string): tuple[output: TaintedString, exitCode: int] =
# proc execNodeTask(taskStr: string): tuple[output: string, exitCode: int] =
# let cmdString = $cmdPrelude & $taskStr
# debug "execNodeTask", cmdString
# return osproc.execCmdEx(cmdString)
Expand Down

0 comments on commit 98b8136

Please sign in to comment.