mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 14:26:26 +00:00
parent
1a5bcb479e
commit
e1f47bb27a
@ -176,24 +176,19 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||
if state.isErr():
|
||||
return RestApiResponse.jsonError(Http400, InvalidPeerStateValueError,
|
||||
$state.error())
|
||||
let sres = validateState(state.get())
|
||||
if sres.isErr():
|
||||
validateState(state.get()).valueOr:
|
||||
return RestApiResponse.jsonError(Http400, InvalidPeerStateValueError,
|
||||
$sres.error())
|
||||
sres.get()
|
||||
$error)
|
||||
let directionMask =
|
||||
block:
|
||||
if direction.isErr():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
InvalidPeerDirectionValueError,
|
||||
$direction.error())
|
||||
let dres = validateDirection(direction.get())
|
||||
if dres.isErr():
|
||||
validateDirection(direction.get()).valueOr:
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
InvalidPeerDirectionValueError,
|
||||
$dres.error())
|
||||
dres.get()
|
||||
|
||||
$error)
|
||||
var res: seq[RestNodePeer]
|
||||
for peer in node.network.peers.values():
|
||||
if (peer.connectionState in connectionMask) and
|
||||
@ -209,7 +204,8 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||
proto: node.network.switch.peerStore[ProtoVersionBook][peer.peerId]
|
||||
)
|
||||
res.add(peer)
|
||||
return RestApiResponse.jsonResponseWMeta(res, (count: uint64(len(res))))
|
||||
return RestApiResponse.jsonResponseWMeta(res,
|
||||
(count: RestNumeric(len(res))))
|
||||
|
||||
# https://ethereum.github.io/beacon-APIs/#/Node/getPeerCount
|
||||
router.api(MethodGet, "/eth/v1/node/peer_count") do () -> RestApiResponse:
|
||||
|
@ -642,6 +642,16 @@ proc readValue*(reader: var JsonReader[RestJson], value: var uint8) {.
|
||||
else:
|
||||
reader.raiseUnexpectedValue($res.error() & ": " & svalue)
|
||||
|
||||
## RestNumeric
|
||||
proc writeValue*(w: var JsonWriter[RestJson],
|
||||
value: RestNumeric) {.raises: [IOError].} =
|
||||
writeValue(w, int(value))
|
||||
|
||||
proc readValue*(reader: var JsonReader[RestJson],
|
||||
value: var RestNumeric) {.
|
||||
raises: [IOError, SerializationError].} =
|
||||
value = RestNumeric(reader.readValue(int))
|
||||
|
||||
## JustificationBits
|
||||
proc writeValue*(
|
||||
w: var JsonWriter[RestJson], value: JustificationBits
|
||||
|
@ -116,6 +116,8 @@ type
|
||||
PeerDirectKind* {.pure.} = enum
|
||||
Inbound, Outbound
|
||||
|
||||
RestNumeric* = distinct int
|
||||
|
||||
RestAttesterDuty* = object
|
||||
pubkey*: ValidatorPubKey
|
||||
validator_index*: ValidatorIndex
|
||||
|
@ -2899,7 +2899,7 @@
|
||||
"response": {
|
||||
"status": {"operator": "equals", "value": "200"},
|
||||
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}],
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": ""}}}]
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": 0}}}]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2911,7 +2911,7 @@
|
||||
"response": {
|
||||
"status": {"operator": "equals", "value": "200"},
|
||||
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}],
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": ""}}}]
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": 0}}}]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2923,7 +2923,7 @@
|
||||
"response": {
|
||||
"status": {"operator": "equals", "value": "200"},
|
||||
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}],
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": ""}}}]
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": 0}}}]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2935,7 +2935,7 @@
|
||||
"response": {
|
||||
"status": {"operator": "equals", "value": "200"},
|
||||
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}],
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": ""}}}]
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": 0}}}]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2947,7 +2947,7 @@
|
||||
"response": {
|
||||
"status": {"operator": "equals", "value": "200"},
|
||||
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}],
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": ""}}}]
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": 0}}}]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2959,7 +2959,7 @@
|
||||
"response": {
|
||||
"status": {"operator": "equals", "value": "200"},
|
||||
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}],
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": ""}}}]
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": 0}}}]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2971,7 +2971,7 @@
|
||||
"response": {
|
||||
"status": {"operator": "equals", "value": "200"},
|
||||
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}],
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": ""}}}]
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": 0}}}]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2983,7 +2983,7 @@
|
||||
"response": {
|
||||
"status": {"operator": "equals", "value": "200"},
|
||||
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}],
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": ""}}}]
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": 0}}}]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2995,7 +2995,7 @@
|
||||
"response": {
|
||||
"status": {"operator": "equals", "value": "200"},
|
||||
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}],
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": ""}}}]
|
||||
"body": [{"operator": "jstructcmpns", "value": {"data": [{"peer_id": "", "enr": "", "last_seen_p2p_address": "", "state": "", "direction": ""}], "meta": {"count": 0}}}]
|
||||
}
|
||||
},
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user