From 6cae25701b80769777821a1ba359a03437e06ea2 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Mon, 30 Nov 2020 05:14:40 +0200 Subject: [PATCH] Implementation of beacon_pool_attester_slashings(), beacon_pool_proposer_slashings() and beacon_pool_voluntary_exits(). --- beacon_chain/rpc/beacon_api.nim | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/beacon_chain/rpc/beacon_api.nim b/beacon_chain/rpc/beacon_api.nim index 1116e8caf..ac7de0981 100644 --- a/beacon_chain/rpc/beacon_api.nim +++ b/beacon_chain/rpc/beacon_api.nim @@ -5,7 +5,7 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import - std/[parseutils, sequtils, strutils], + std/[parseutils, sequtils, strutils, deques], json_rpc/[rpcserver, jsonmarshal], chronicles, @@ -245,20 +245,35 @@ proc installBeaconApiHandlers*(rpcServer: RpcServer, node: BeaconNode) = node.sendAttestation(attestation) return true - rpcServer.rpc("get_v1_beacon_pool_attester_slahsings") do () -> JsonNode: + rpcServer.rpc("get_v1_beacon_pool_attester_slashings") do ( + ) -> seq[AttesterSlashing]: + let length = len(node.exitPool.attester_slashings) + var res = newSeqOfCap[AttesterSlashing](length) + for item in node.exitPool.attester_slashings.items(): + res.add(item) + return res + + rpcServer.rpc("post_v1_beacon_pool_attester_slashings") do () -> JsonNode: unimplemented() - rpcServer.rpc("post_v1_beacon_pool_attester_slahsings") do () -> JsonNode: - unimplemented() - - rpcServer.rpc("get_v1_beacon_pool_proposer_slashings") do () -> JsonNode: - unimplemented() + rpcServer.rpc("get_v1_beacon_pool_proposer_slashings") do ( + ) -> seq[ProposerSlashing]: + let length = len(node.exitPool.proposer_slashings) + var res = newSeqOfCap[ProposerSlashing](length) + for item in node.exitPool.proposer_slashings.items(): + res.add(item) + return res rpcServer.rpc("post_v1_beacon_pool_proposer_slashings") do () -> JsonNode: unimplemented() - rpcServer.rpc("get_v1_beacon_pool_voluntary_exits") do () -> JsonNode: - unimplemented() + rpcServer.rpc("get_v1_beacon_pool_voluntary_exits") do ( + ) -> seq[SignedVoluntaryExit]: + let length = len(node.exitPool.voluntary_exits) + var res = newSeqOfCap[SignedVoluntaryExit](length) + for item in node.exitPool.voluntary_exits.items(): + res.add(item) + return res rpcServer.rpc("post_v1_beacon_pool_voluntary_exits") do ( exit: SignedVoluntaryExit) -> bool: