fix: Stringify network state on demand (#146)

This commit is contained in:
Maciej Hirsz
2019-05-14 15:19:00 +02:00
committed by GitHub
parent 74c784c62d
commit 4a48a6eecf
2 changed files with 5 additions and 3 deletions
+4 -2
View File
@@ -62,9 +62,11 @@ http.createServer((request, response) => {
const nodeList = Array.from(chain.nodeList());
const nodeId = Number(strNodeId);
const node = nodeList.filter((node) => node.id == nodeId)[0];
if (node && typeof node.networkState === 'string') {
if (node && node.networkState) {
const { networkState } = node;
response.writeHead(200, {"Content-Type": "application/json"});
response.write(node.networkState);
response.write(typeof networkState === 'string' ? networkState : JSON.stringify(networkState));
} else {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("Node has disconnected or has not submitted its network state yet");
+1 -1
View File
@@ -24,7 +24,7 @@ export type MemoryUse = Opaque<number, 'MemoryUse'>;
export type CPUUse = Opaque<number, 'CPUUse'>;
export type BytesPerSecond = Opaque<number, 'BytesPerSecond'>;
export type NetworkId = Opaque<string, 'NetworkId'>;
export type NetworkState = Opaque<string, 'NetworkState'>;
export type NetworkState = Opaque<string | object, 'NetworkState'>;
export type BlockDetails = [BlockNumber, BlockHash, Milliseconds, Timestamp, Maybe<PropagationTime>];
export type NodeDetails = [NodeName, NodeImplementation, NodeVersion, Maybe<Address>, Maybe<NetworkId>];