From af3862da482863c469140d7ade0693532f7e7acf Mon Sep 17 00:00:00 2001 From: cheatfate Date: Tue, 24 Nov 2020 21:14:49 +0200 Subject: [PATCH] Make depositAddress public in eth1_monitor. Fix representation of config. Add deposit_contract implementation. --- beacon_chain/rpc/config_api.nim | 45 ++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/beacon_chain/rpc/config_api.nim b/beacon_chain/rpc/config_api.nim index 65ba7c1c3..4147d1dd6 100644 --- a/beacon_chain/rpc/config_api.nim +++ b/beacon_chain/rpc/config_api.nim @@ -5,11 +5,11 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import - std/strutils, + stew/endians2, json_rpc/[rpcserver, jsonmarshal], chronicles, nimcrypto/utils as ncrutils, - ../beacon_node_common, + ../beacon_node_common, ../eth1_monitor, ../spec/[datatypes, digest, presets] logScope: topics = "configapi" @@ -25,6 +25,15 @@ proc installConfigApiHandlers*(rpcServer: RpcServer, node: BeaconNode) = return @[node.chainDag.headState.data.data.fork] rpcServer.rpc("get_v1_config_spec") do () -> JsonNode: + let depositAddress = + if isNil(node.eth1Monitor): + "" + else: + "0x" & $node.eth1Monitor.depositContractAddress() + + if len(depositAddress) == 0: + raise newException(CatchableError, "Internal server error") + return %{ "MAX_COMMITTEES_PER_SLOT": $MAX_COMMITTEES_PER_SLOT, "TARGET_COMMITTEE_SIZE": $TARGET_COMMITTEE_SIZE, @@ -47,13 +56,13 @@ proc installConfigApiHandlers*(rpcServer: RpcServer, node: BeaconNode) = "SECONDS_PER_ETH1_BLOCK": $SECONDS_PER_ETH1_BLOCK, "DEPOSIT_CHAIN_ID": $DEPOSIT_CHAIN_ID, "DEPOSIT_NETWORK_ID": $DEPOSIT_NETWORK_ID, - "DEPOSIT_CONTRACT_ADDRESS": $node.config.depositContractAddress, + "DEPOSIT_CONTRACT_ADDRESS": depositAddress, "MIN_DEPOSIT_AMOUNT": $MIN_DEPOSIT_AMOUNT, "MAX_EFFECTIVE_BALANCE": $MAX_EFFECTIVE_BALANCE, "EJECTION_BALANCE": $EJECTION_BALANCE, "EFFECTIVE_BALANCE_INCREMENT": $EFFECTIVE_BALANCE_INCREMENT, "GENESIS_FORK_VERSION": - $node.config.runtimePreset.GENESIS_FORK_VERSION, + "0x" & $node.config.runtimePreset.GENESIS_FORK_VERSION, "BLS_WITHDRAWAL_PREFIX": "0x" & ncrutils.toHex([BLS_WITHDRAWAL_PREFIX]), "GENESIS_DELAY": $node.config.runtimePreset.GENESIS_DELAY, "SECONDS_PER_SLOT": $SECONDS_PER_SLOT, @@ -83,20 +92,32 @@ proc installConfigApiHandlers*(rpcServer: RpcServer, node: BeaconNode) = "MAX_DEPOSITS": $MAX_DEPOSITS, "MAX_VOLUNTARY_EXITS": $MAX_VOLUNTARY_EXITS, "DOMAIN_BEACON_PROPOSER": - "0x" & strutils.toHex(cast[uint64](DOMAIN_BEACON_PROPOSER)), + "0x" & ncrutils.toHex(uint32(DOMAIN_BEACON_PROPOSER).toBytesLE()), "DOMAIN_BEACON_ATTESTER": - "0x" & strutils.toHex(cast[uint64](DOMAIN_BEACON_ATTESTER)), + "0x" & ncrutils.toHex(uint32(DOMAIN_BEACON_ATTESTER).toBytesLE()), "DOMAIN_RANDAO": - "0x" & strutils.toHex(cast[uint64](DOMAIN_RANDAO)), + "0x" & ncrutils.toHex(uint32(DOMAIN_RANDAO).toBytesLE()), "DOMAIN_DEPOSIT": - "0x" & strutils.toHex(cast[uint64](DOMAIN_DEPOSIT)), + "0x" & ncrutils.toHex(uint32(DOMAIN_DEPOSIT).toBytesLE()), "DOMAIN_VOLUNTARY_EXIT": - "0x" & strutils.toHex(cast[uint64](DOMAIN_VOLUNTARY_EXIT)), + "0x" & ncrutils.toHex(uint32(DOMAIN_VOLUNTARY_EXIT).toBytesLE()), "DOMAIN_SELECTION_PROOF": - "0x" & strutils.toHex(cast[uint64](DOMAIN_SELECTION_PROOF)), + "0x" & ncrutils.toHex(uint32(DOMAIN_SELECTION_PROOF).toBytesLE()), "DOMAIN_AGGREGATE_AND_PROOF": - "0x" & strutils.toHex(cast[uint64](DOMAIN_AGGREGATE_AND_PROOF)) + "0x" & ncrutils.toHex(uint32(DOMAIN_AGGREGATE_AND_PROOF).toBytesLE()) } rpcServer.rpc("get_v1_config_deposit_contract") do () -> JsonNode: - unimplemented() + let depositAddress = + if isNil(node.eth1Monitor): + "" + else: + "0x" & $node.eth1Monitor.depositContractAddress() + + if len(depositAddress) == 0: + raise newException(CatchableError, "Internal server error") + + return %{ + "chain_id": $DEPOSIT_CHAIN_ID, + "address": depositAddress + }