diff --git a/packages/api/src/promise/index.ts b/packages/api/src/promise/index.ts index 47b6672e3d..d92ef83db2 100644 --- a/packages/api/src/promise/index.ts +++ b/packages/api/src/promise/index.ts @@ -209,8 +209,6 @@ export default class ApiPromise extends ApiBase { - console.error(error); - if (!isCompleted) { isCompleted = true; diff --git a/packages/type-jsonrpc/src/system.ts b/packages/type-jsonrpc/src/system.ts index 229e807781..ff8e3c52ab 100644 --- a/packages/type-jsonrpc/src/system.ts +++ b/packages/type-jsonrpc/src/system.ts @@ -38,6 +38,13 @@ const health: RpcMethodOpt = { type: 'Health' }; +const peers: RpcMethodOpt = { + description: 'Returns the currently connected peers', + params: [], + // @ts-ignore the Vec<> wrap is fine + type: 'Vec' +}; + const section = 'system'; /** @@ -52,6 +59,7 @@ export default { chain: createMethod(section, 'chain', chain), health: createMethod(section, 'health', health), name: createMethod(section, 'name', name), + peers: createMethod(section, 'peers', peers), properties: createMethod(section, 'properties', properties), version: createMethod(section, 'version', version) } diff --git a/packages/types/src/Health.ts b/packages/types/src/Health.ts index f71f3ce3d2..10364b9214 100644 --- a/packages/types/src/Health.ts +++ b/packages/types/src/Health.ts @@ -4,16 +4,21 @@ import Struct from './codec/Struct'; import Bool from './Bool'; -import U32 from './U32'; +import USize from './USize'; const JSON_MAP = new Map([ ['isSyncing', 'is_syncing'] ]); +/** + * @name Health + * @description + * A system health indicator, reported back over RPC + */ export default class Health extends Struct { constructor (value?: any) { super({ - peers: U32, + peers: USize, isSyncing: Bool }, value, JSON_MAP); } @@ -28,7 +33,7 @@ export default class Health extends Struct { /** * @description The numbers of peers as [[U32]] */ - get peers (): U32 { - return this.get('peers') as U32; + get peers (): USize { + return this.get('peers') as USize; } } diff --git a/packages/types/src/PeerInfo.ts b/packages/types/src/PeerInfo.ts new file mode 100644 index 0000000000..fe8eb1390c --- /dev/null +++ b/packages/types/src/PeerInfo.ts @@ -0,0 +1,76 @@ +// 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 BlockNumber from './BlockNumber'; +import Hash from './Hash'; +import Text from './Text'; +import U32 from './U32'; +import USize from './USize'; + +const JSON_MAP = new Map([ + ['bestHash', 'best_hash'], + ['bestNumber', 'best_number'], + ['protocolVersion', 'protocol_version'] +]); + +/** + * @name PeerInfo + * @description + * A system peer info indicator, reported back over RPC + */ +export default class PeerInfo extends Struct { + constructor (value?: any) { + super({ + index: USize, + peerId: Text, + roles: Text, + protocolVersion: U32, + bestHash: Hash, + bestNumber: BlockNumber + }, value, JSON_MAP); + } + + /** + * @description The best block hash for the peer + */ + get bestHash (): Hash { + return this.get('bestHash') as Hash; + } + + /** + * @description The best block hash for the peer + */ + get bestNumber (): BlockNumber { + return this.get('bestNumber') as BlockNumber; + } + + /** + * @description The index of the peer in our list + */ + get index (): USize { + return this.get('index') as USize; + } + + /** + * @description The p2p network id for the peer + */ + get peerId (): Text { + return this.get('peerId') as Text; + } + + /** + * @description The index of the peer in our list + */ + get protocolVersion (): U32 { + return this.get('protocolVersion') as U32; + } + + /** + * @description The roles of the peer on the network + */ + get roles (): Text { + return this.get('roles') as Text; + } +} diff --git a/packages/types/src/USize.ts b/packages/types/src/USize.ts new file mode 100644 index 0000000000..3e356dbc9f --- /dev/null +++ b/packages/types/src/USize.ts @@ -0,0 +1,14 @@ +// 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 U64 from './U64'; + +/** + * @name USize + * @description + * A System default unsigned number, typically used in RPC to report non-consensus + * data. It is a wrapper for [[U64]] as a 64-binary default + */ +export default class USize extends U64 { +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 34b29cfb7b..4272141e11 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -64,6 +64,7 @@ export { default as IndexCompact } from './NonceCompact'; export { default as Justification } from './Justification'; export { default as Origin } from './Origin'; export { default as ParaId } from './ParaId'; +export { default as PeerInfo } from './PeerInfo'; export { default as PendingExtrinsics } from './PendingExtrinsics'; export { default as Permill } from './Permill'; export { default as Perbill } from './Perbill'; @@ -89,6 +90,7 @@ export { default as u32 } from './U32'; export { default as u64 } from './U64'; export { default as u128 } from './U128'; export { default as u256 } from './U256'; +export { default as usize } from './USize'; export { default as ValidatorPrefs } from './ValidatorPrefs'; export { default as Vote } from './Vote'; export { default as VoteThreshold } from './VoteThreshold';