Add a RPC proc similar to /spec/eth2_config

This commit is contained in:
Zahary Karadjov 2020-03-17 01:49:53 +02:00 committed by zah
parent adcec61081
commit 5a2a52869e
3 changed files with 15 additions and 8 deletions

View File

@ -3,7 +3,7 @@ import
os, tables, random, strutils, times, sequtils,
# Nimble packages
stew/[objects, bitseqs, byteutils],
stew/[objects, bitseqs, byteutils], stew/shims/macros,
chronos, chronicles, confutils, metrics, json_rpc/[rpcserver, jsonmarshal],
json_serialization/std/[options, sets, net], serialization/errors,
kvstore, kvstore_sqlite3,
@ -11,7 +11,7 @@ import
# Local modules
spec/[datatypes, digest, crypto, beaconstate, helpers, validator, network,
state_transition_block],
state_transition_block], spec/presets/custom,
conf, time, state_transition, beacon_chain_db, validator_pool, extras,
attestation_pool, block_pool, eth2_network, eth2_discovery,
beacon_node_types, mainchain_monitor, version, ssz, ssz/dynamic_navigator,
@ -945,7 +945,17 @@ proc installBeaconApiHandlers(rpcServer: RpcServer, node: BeaconNode) =
return $node.network.discovery.localNode.record
proc installDebugApiHandlers(rpcServer: RpcServer, node: BeaconNode) =
discard
rpcServer.rpc("getSpecPreset") do () -> JsonNode:
var res = newJObject()
genCode:
for setting in BeaconChainConstants:
let
settingSym = ident($setting)
settingKey = newLit(toLowerAscii($setting))
yield quote do:
res[`settingKey`] = %`settingSym`
return res
proc installRpcHandlers(rpcServer: RpcServer, node: BeaconNode) =
rpcServer.installValidatorApiHandlers(node)

View File

@ -82,7 +82,7 @@ type
# Domains
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/beacon-chain.md#domain-types
DomainType* {.pure.} = enum
DomainType* = enum
DOMAIN_BEACON_PROPOSER = 0
DOMAIN_BEACON_ATTESTER = 1
DOMAIN_RANDAO = 2
@ -510,9 +510,6 @@ proc writeValue*(writer: var JsonWriter, value: ValidatorIndex) =
proc readValue*(reader: var JsonReader, value: var ValidatorIndex) =
value = ValidatorIndex reader.readValue(uint32)
proc `%`*(i: uint64): JsonNode =
% int(i)
# `ValidatorIndex` seq handling.
proc max*(a: ValidatorIndex, b: int) : auto =
max(a.int, b)

View File

@ -2,7 +2,7 @@ import
macros, strutils, tables
type
BeaconChainConstants* = enum
BeaconChainConstants* {.pure.} = enum
BASE_REWARDS_PER_EPOCH
BASE_REWARD_FACTOR
BLS_WITHDRAWAL_PREFIX