add --graphql and --graphqlbind to cli parser

This commit is contained in:
jangko 2021-04-24 10:58:05 +07:00
parent 3dfc1501f0
commit 34536b0d25
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 36 additions and 16 deletions

View File

@ -70,6 +70,10 @@ type
flags*: set[RpcFlags] ## RPC flags flags*: set[RpcFlags] ## RPC flags
binds*: seq[TransportAddress] ## RPC bind address binds*: seq[TransportAddress] ## RPC bind address
GraphqlConfiguration* = object
enabled*: bool
address*: TransportAddress
PublicNetwork* = enum PublicNetwork* = enum
CustomNet = 0 CustomNet = 0
MainNet = 1 MainNet = 1
@ -156,6 +160,7 @@ type
dataDir*: string dataDir*: string
keyStore*: string keyStore*: string
prune*: PruneMode prune*: PruneMode
graphql*: GraphqlConfiguration
rpc*: RpcConfiguration ## JSON-RPC configuration rpc*: RpcConfiguration ## JSON-RPC configuration
net*: NetConfiguration ## Network configuration net*: NetConfiguration ## Network configuration
debug*: DebugConfiguration ## Debug configuration debug*: DebugConfiguration ## Debug configuration
@ -167,7 +172,7 @@ type
accounts*: Table[EthAddress, NimbusAccount] accounts*: Table[EthAddress, NimbusAccount]
importFile*: string importFile*: string
CustomGenesisConfig = object CustomGenesisConfig* = object
chainId*: ChainId chainId*: ChainId
homesteadBlock*: BlockNumber homesteadBlock*: BlockNumber
daoForkBlock*: BlockNumber daoForkBlock*: BlockNumber
@ -478,28 +483,24 @@ proc processFloat*(v: string, o: var float): ConfigStatus =
except ValueError: except ValueError:
result = ErrorParseOption result = ErrorParseOption
proc processAddressPort(addrStr: string, ta: var TransportAddress): ConfigStatus =
try:
ta = initTAddress(addrStr)
return Success
except CatchableError:
return ErrorParseOption
proc processAddressPortsList(v: string, proc processAddressPortsList(v: string,
o: var seq[TransportAddress]): ConfigStatus = o: var seq[TransportAddress]): ConfigStatus =
## Convert <hostname:port>;...;<hostname:port> to list of `TransportAddress`. ## Convert <hostname:port>;...;<hostname:port> to list of `TransportAddress`.
var list = newSeq[string]() var list = newSeq[string]()
processList(v, list) processList(v, list)
for item in list: for item in list:
var tas4: seq[TransportAddress] var ta: TransportAddress
var tas6: seq[TransportAddress] if processAddressPort(item, ta) == Success:
try: o.add ta
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
else: else:
for a in tas4: o.add(a) return ErrorParseOption
for a in tas6: o.add(a)
result = Success result = Success
proc processRpcApiList(v: string, flags: var set[RpcFlags]): ConfigStatus = proc processRpcApiList(v: string, flags: var set[RpcFlags]): ConfigStatus =
@ -607,6 +608,18 @@ proc processRpcArguments(key, value: string): ConfigStatus =
else: else:
result = EmptyOption 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]) = proc setBootnodes(onodes: var seq[ENode], nodeUris: openarray[string]) =
var node: ENode var node: ENode
onodes = newSeqOfCap[ENode](nodeUris.len) onodes = newSeqOfCap[ENode](nodeUris.len)
@ -843,6 +856,10 @@ proc initConfiguration(): NimbusConfiguration =
result.rng = newRng() result.rng = newRng()
result.accounts = initTable[EthAddress, NimbusAccount]() result.accounts = initTable[EthAddress, NimbusAccount]()
## Graphql defaults
result.graphql.enabled = false
result.graphql.address = initTAddress("127.0.0.1:8547")
## RPC defaults ## RPC defaults
result.rpc.flags = {} result.rpc.flags = {}
result.rpc.binds = @[initTAddress("127.0.0.1:8545")] result.rpc.binds = @[initTAddress("127.0.0.1:8545")]
@ -936,6 +953,8 @@ API AND CONSOLE OPTIONS:
--rpc Enable the HTTP-RPC server --rpc Enable the HTTP-RPC server
--rpcbind:<value> HTTP-RPC server will bind to given comma separated address:port pairs (default: 127.0.0.1:8545) --rpcbind:<value> HTTP-RPC server will bind to given comma separated address:port pairs (default: 127.0.0.1:8545)
--rpcapi:<value> Enable specific set of rpc api from comma separated list(eth, shh, debug) --rpcapi:<value> Enable specific set of rpc api from comma separated list(eth, shh, debug)
--graphql Enable the HTTP-Graphql server
--graphqlbind:<value> HTTP-Graphql server will bind to given address:port pair (default: 127.0.0.1:8547)
LOGGING AND DEBUGGING OPTIONS: LOGGING AND DEBUGGING OPTIONS:
--log-level:<value> One of: $2 (default: $3) --log-level:<value> One of: $2 (default: $3)
@ -996,6 +1015,7 @@ when declared(os.paramCount): # not available with `--app:lib`
processArgument processNetArguments, key, value, msg processArgument processNetArguments, key, value, msg
processArgument processShhArguments, key, value, msg processArgument processShhArguments, key, value, msg
processArgument processDebugArguments, key, value, msg processArgument processDebugArguments, key, value, msg
processArgument processGraphqlArguments, key, value, msg
if result != Success: if result != Success:
msg = "Unknown option: '" & key & "'." msg = "Unknown option: '" & key & "'."
break break