Add network state to backend (#123)

This commit is contained in:
Gregory Terzian
2019-03-15 18:57:03 +08:00
committed by Maciej Hirsz
parent 1023b72fe7
commit 0134677c2d
3 changed files with 8 additions and 0 deletions
+6
View File
@@ -31,6 +31,7 @@ export default class Node {
public readonly events = new EventEmitter() as EventEmitter & NodeEvents;
public networkState: Maybe<Types.NetworkState> = null;
public location: Maybe<Location> = null;
public lastMessage: Types.Timestamp;
public config: string;
@@ -239,6 +240,7 @@ export default class Node {
private onSystemInterval(message: SystemInterval) {
const {
network_state,
peers,
txcount,
cpu,
@@ -249,6 +251,10 @@ export default class Node {
finalized_hash: finalizedHash
} = message;
if (this.networkState !== network_state && network_state) {
this.networkState = network_state;
};
if (this.peers !== peers || this.txcount !== txcount) {
this.peers = peers;
this.txcount = txcount;
+1
View File
@@ -53,6 +53,7 @@ export interface SystemConnected {
export interface SystemInterval extends BestBlock {
msg: 'system.interval';
network_state: Maybe<Types.NetworkState>;
txcount: Types.TransactionCount;
peers: Types.PeerCount;
memory: Maybe<Types.MemoryUse>;
+1
View File
@@ -24,6 +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 BlockDetails = [BlockNumber, BlockHash, Milliseconds, Timestamp, Maybe<PropagationTime>];
export type NodeDetails = [NodeName, NodeImplementation, NodeVersion, Maybe<Address>, Maybe<NetworkId>];