Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support IpAddress in contexts ValidIpAddress is supported #95

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions confutils/toml/std/net.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import
export
net, toml_serialization

proc readValue*(r: var TomlReader, val: var IpAddress)
{.raises: [SerializationError, IOError, Defect].} =
val = try: parseIpAddress(r.readValue(string))
except ValueError as err:
r.lex.raiseUnexpectedValue("IP address")

proc readValue*(r: var TomlReader, val: var ValidIpAddress)
{.raises: [SerializationError, IOError, Defect].} =
val = try: ValidIpAddress.init(r.readValue(string))
Expand Down
20 changes: 17 additions & 3 deletions tests/test_config_file.nim
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ type
name: "rpc-port" }: Port

rpcAddress* {.
defaultValue: defaultAdminListenAddress(config)
defaultValue: ValidIpAddress.init(defaultAdminListenAddress(config))
desc: "Address of the server to connect to for RPC - for the validator duties in the pull model"
name: "rpc-address" }: ValidIpAddress

restAddress* {.
defaultValue: defaultAdminListenAddress(config)
desc: "Address of the server to connect to for RPC - for the validator duties in the pull model"
name: "rest-address" }: IpAddress

retryDelay* {.
defaultValue: 10
desc: "Delay in seconds between retries after unsuccessful attempts to connect to a beacon node"
Expand Down Expand Up @@ -127,8 +132,8 @@ func parseCmdArg*(T: type GraffitiBytes, input: string): T
func completeCmdArg*(T: type GraffitiBytes, input: string): seq[string] =
@[]

func defaultAdminListenAddress*(conf: TestConf): ValidIpAddress =
(static ValidIpAddress.init("127.0.0.1"))
func defaultAdminListenAddress*(conf: TestConf): IpAddress =
(static parseIpAddress("127.0.0.1"))

const
defaultEth2TcpPort* = 9000
Expand All @@ -148,6 +153,12 @@ proc readValue(r: var TomlReader,
type T = type value
value = T r.parseAsString()

proc readValue(r: var TomlReader, value: var IpAddress) =
try:
value = parseIpAddress(r.parseAsString())
except ValueError as ex:
raise newException(SerializationError, ex.msg)

proc readValue(r: var TomlReader, value: var ValidIpAddress) =
try:
value = ValidIpAddress.init(r.parseAsString())
Expand All @@ -168,6 +179,9 @@ proc readValue(r: var WinregReader,
type T = type value
value = r.readValue(string).T

proc readValue(r: var WinregReader, value: var IpAddress) {.used.} =
value = parseIpAddress(r.readValue(string))

proc readValue(r: var WinregReader, value: var ValidIpAddress) {.used.} =
value = ValidIpAddress.init(r.readValue(string))

Expand Down