From 34536b0d2559ad2641e55d0f311c1aeda0bb33ce Mon Sep 17 00:00:00 2001 From: jangko Date: Sat, 24 Apr 2021 10:58:05 +0700 Subject: [PATCH] add --graphql and --graphqlbind to cli parser --- nimbus/config.nim | 52 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/nimbus/config.nim b/nimbus/config.nim index c0fc0c275..1b786f24f 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -70,6 +70,10 @@ type flags*: set[RpcFlags] ## RPC flags binds*: seq[TransportAddress] ## RPC bind address + GraphqlConfiguration* = object + enabled*: bool + address*: TransportAddress + PublicNetwork* = enum CustomNet = 0 MainNet = 1 @@ -156,6 +160,7 @@ type dataDir*: string keyStore*: string prune*: PruneMode + graphql*: GraphqlConfiguration rpc*: RpcConfiguration ## JSON-RPC configuration net*: NetConfiguration ## Network configuration debug*: DebugConfiguration ## Debug configuration @@ -167,7 +172,7 @@ type accounts*: Table[EthAddress, NimbusAccount] importFile*: string - CustomGenesisConfig = object + CustomGenesisConfig* = object chainId*: ChainId homesteadBlock*: BlockNumber daoForkBlock*: BlockNumber @@ -478,28 +483,24 @@ proc processFloat*(v: string, o: var float): ConfigStatus = except ValueError: result = ErrorParseOption +proc processAddressPort(addrStr: string, ta: var TransportAddress): ConfigStatus = + try: + ta = initTAddress(addrStr) + return Success + except CatchableError: + return ErrorParseOption + proc processAddressPortsList(v: string, o: var seq[TransportAddress]): ConfigStatus = ## Convert ;...; to list of `TransportAddress`. var list = newSeq[string]() processList(v, list) for item in list: - var tas4: seq[TransportAddress] - var tas6: seq[TransportAddress] - try: - tas4 = resolveTAddress(item, AddressFamily.IPv4) - except CatchableError: - discard - try: - tas6 = resolveTAddress(item, AddressFamily.IPv6) - except CatchableError: - discard - if len(tas4) == 0 and len(tas6) == 0: - result = ErrorParseOption - break + var ta: TransportAddress + if processAddressPort(item, ta) == Success: + o.add ta else: - for a in tas4: o.add(a) - for a in tas6: o.add(a) + return ErrorParseOption result = Success proc processRpcApiList(v: string, flags: var set[RpcFlags]): ConfigStatus = @@ -607,6 +608,18 @@ proc processRpcArguments(key, value: string): ConfigStatus = else: result = EmptyOption +proc processGraphqlArguments(key, value: string): ConfigStatus = + ## Processes only `Graphql` related command line options + result = Success + let conf = getConfiguration() + case key.toLowerAscii() + of "graphql": + conf.graphql.enabled = true + of "graphqlbind": + result = processAddressPort(value, conf.graphql.address) + else: + result = EmptyOption + proc setBootnodes(onodes: var seq[ENode], nodeUris: openarray[string]) = var node: ENode onodes = newSeqOfCap[ENode](nodeUris.len) @@ -843,6 +856,10 @@ proc initConfiguration(): NimbusConfiguration = result.rng = newRng() result.accounts = initTable[EthAddress, NimbusAccount]() + ## Graphql defaults + result.graphql.enabled = false + result.graphql.address = initTAddress("127.0.0.1:8547") + ## RPC defaults result.rpc.flags = {} result.rpc.binds = @[initTAddress("127.0.0.1:8545")] @@ -936,6 +953,8 @@ API AND CONSOLE OPTIONS: --rpc Enable the HTTP-RPC server --rpcbind: HTTP-RPC server will bind to given comma separated address:port pairs (default: 127.0.0.1:8545) --rpcapi: Enable specific set of rpc api from comma separated list(eth, shh, debug) + --graphql Enable the HTTP-Graphql server + --graphqlbind: HTTP-Graphql server will bind to given address:port pair (default: 127.0.0.1:8547) LOGGING AND DEBUGGING OPTIONS: --log-level: One of: $2 (default: $3) @@ -996,6 +1015,7 @@ when declared(os.paramCount): # not available with `--app:lib` processArgument processNetArguments, key, value, msg processArgument processShhArguments, key, value, msg processArgument processDebugArguments, key, value, msg + processArgument processGraphqlArguments, key, value, msg if result != Success: msg = "Unknown option: '" & key & "'." break