diff --git a/packages/type-jsonrpc/src/system.ts b/packages/type-jsonrpc/src/system.ts index d6afa333a8..229e807781 100644 --- a/packages/type-jsonrpc/src/system.ts +++ b/packages/type-jsonrpc/src/system.ts @@ -32,6 +32,12 @@ const properties: RpcMethodOpt = { type: 'ChainProperties' }; +const health: RpcMethodOpt = { + description: 'Return health status of the node', + params: [], + type: 'Health' +}; + const section = 'system'; /** @@ -44,6 +50,7 @@ export default { section, methods: { chain: createMethod(section, 'chain', chain), + health: createMethod(section, 'health', health), name: createMethod(section, 'name', name), properties: createMethod(section, 'properties', properties), version: createMethod(section, 'version', version) diff --git a/packages/types/src/Health.ts b/packages/types/src/Health.ts new file mode 100644 index 0000000000..f71f3ce3d2 --- /dev/null +++ b/packages/types/src/Health.ts @@ -0,0 +1,34 @@ +// Copyright 2017-2019 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import Struct from './codec/Struct'; +import Bool from './Bool'; +import U32 from './U32'; + +const JSON_MAP = new Map([ + ['isSyncing', 'is_syncing'] +]); + +export default class Health extends Struct { + constructor (value?: any) { + super({ + peers: U32, + isSyncing: Bool + }, value, JSON_MAP); + } + + /** + * @description The sync status + */ + get isSyncing (): Bool { + return this.get('isSyncing') as Bool; + } + + /** + * @description The numbers of peers as [[U32]] + */ + get peers (): U32 { + return this.get('peers') as U32; + } +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index d3205cab5a..8b58ab6390 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -42,6 +42,7 @@ export { default as H256 } from './H256'; export { default as H512 } from './H512'; export { default as Hash } from './Hash'; export { default as Header } from './Header'; +export { default as Health } from './Health'; export { default as i8 } from './I8'; export { default as i16 } from './I16'; export { default as i32 } from './I32';