Add system_networkState RPC (with cleanups) (#745)

* Ad system_networkState RPC (with cleanups)

* Bump external dependencies

* s/network_state/networkState/ (as per Rust PR comments)

* Bump common (latest)
This commit is contained in:
Jaco Greeff
2019-02-28 13:53:36 +01:00
committed by GitHub
parent 177e5ec519
commit 1ea1f6f9f5
34 changed files with 510 additions and 1108 deletions
+9 -5
View File
@@ -8,12 +8,16 @@ There primitive types are available: [[Bool]], [[Bytes]], [[Data]], [[H160]], [[
## Substrate types
These types implement specific types that are found as part of the Substrate base: [[AccountId]], [[AccountIndex]], [[Address]], [[Amount]], [[AssetOf]], [[AttestedCandidate]], [[AuthorityId]], [[Balance]], [[BalanceOf]], [[Block]], [[BlockNumber]], [[ChainProperties]], [[CodeHash]], [[Digest]], [[Event]], [[EventRecord]], [[Extrinsic]], [[Extrinsics]], [[ExtrinsicEra]], [[ExtrinsicSignature]], [[ExtrinsicStatus]], [[Gas]], [[Hash]], [[Header]], [[Health]], [[InherentOfflineReport]], [[Justification]], [[KeyValue]], [[Metadata]], [[MisbehaviorReport]], [[NewAccountOutcome]], [[Nonce]], [[Origin]], [[ParaId]], [[PendingExtrinsics]], [[Perbill]], [[Permill]], [[PrefabWasmModule]], [[PropIndex]], [[Proposal]], [[ProposalIndex]], [[ReferendumIndex]], [[ReferendumInfo]], [[RuntimeVersion]], [[Schedule]], [[SeedOf]], [[SessionKey]], [[Signature]], [[SignaturePayload]], [[SignedBlock]], [[StorageChangeSet]], [[StoredPendingChange]], [[ValidatorPrefs]], [[VestingSchedule]], [[Vote]], [[VoteIndex]], [[VoteThreshold]]
## Derived types
Some types are extended from the base to provide additional information: [[HeaderExtended]], [[ReferendumInfoExtended]]
These types implement specific types that are found as part of the Substrate base: [[AccountId]], [[AccountIndex]], [[Address]], [[Amount]], [[AssetOf]], [[AttestedCandidate]], [[AuthorityId]], [[Balance]], [[BalanceOf]], [[Block]], [[BlockNumber]], [[CodeHash]], [[Digest]], [[Event]], [[EventRecord]], [[Extrinsic]], [[ExtrinsicEra]], [[ExtrinsicSignature]], [[Gas]], [[Hash]], [[Header]], [[InherentOfflineReport]], [[Justification]], [[KeyValue]], [[MisbehaviorReport]], [[NewAccountOutcome]], [[Nonce]], [[Origin]], [[ParaId]], [[Perbill]], [[Permill]], [[PrefabWasmModule]], [[PropIndex]], [[Proposal]], [[ProposalIndex]], [[ReferendumIndex]], [[ReferendumInfo]], [[Schedule]], [[SeedOf]], [[SessionKey]], [[Signature]], [[SignaturePayload]], [[StoredPendingChange]], [[ValidatorPrefs]], [[VestingSchedule]], [[Vote]], [[VoteIndex]], [[VoteThreshold]]
## Codec types
These are the base types of the codec, typically not used directly, but rather inherited from to create specific types: [[Base]], [[Compact]], [[Enum]], [[EnumType]], [[Option]], [[Set]], [[Struct]], [[Tuple]], [[U8a]], [[U8aFixed]], [[UInt]], [[Vector]]
## RPC types
These types are not used in the runtime, but rather are used in RPC results: [[ChainProperties]], [[ExtrinsicStatus]], [[Health]], [[Json]], [[NetworkState]], [[Metadata]], [[PeerInfo]], [[PendingExtrinsics]], [[RuntimeVersion]], [[SignedBlock]], [[StorageChangeSet]]
## Derived types
Some types are extended from the base to provide additional information: [[HeaderExtended]], [[ReferendumInfoExtended]]
+3 -3
View File
@@ -29,9 +29,9 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
"dependencies": {
"@babel/runtime": "^7.3.1",
"@polkadot/keyring": "^0.34.31",
"@polkadot/util": "^0.34.31",
"@babel/runtime": "^7.3.4",
"@polkadot/keyring": "^0.34.33",
"@polkadot/util": "^0.34.33",
"core-js": "^2.6.5"
}
}
+1 -1
View File
@@ -2,6 +2,6 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import * as Classes from './index';
import * as Classes from './index.types';
export type CodecTypes = keyof typeof Classes;
+1
View File
@@ -10,4 +10,5 @@
*/
export { default as Metadata } from './Metadata';
export * from './primitive';
export * from './rpc';
export * from './type';
+26
View File
@@ -0,0 +1,26 @@
// 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 Json from './Json';
/**
* @name ChainProperties
* @description
* Wraps the properties retrieved from the chain via the `system.properties` RPC call.
*/
export default class ChainProperties extends Json {
/**
* @description The token decimals, if defined (de-facto standard only)
*/
get tokenDecimals (): number | undefined {
return this.get('tokenDecimals');
}
/**
* @description The token system, if defined (de-facto standard only)
*/
get tokenSymbol (): string | undefined {
return this.get('tokenSymbol');
}
}
@@ -6,7 +6,7 @@ import EnumType from '../codec/EnumType';
import Vector from '../codec/Vector';
import Null from '../primitive/Null';
import Text from '../primitive/Text';
import Hash from './Hash';
import Hash from '../type/Hash';
/**
* @name Broadcast
@@ -6,20 +6,19 @@ import { Codec } from '../types';
import { compareMap } from '../codec/utils';
/**
* @name ChainProperties
* @name Json
* @description
* Wraps the properties retrieved from the chain via the `system.properties` RPC call. It extends
* the standard JS Map with de-facto values exposed as getters. While it implements a Codec, it is
* limited in that it can only be used with input objects via RPC, i.e. no hex decoding. Unlike a
* struct, this wrasp a JSON object with unknown keys and any values for those
* Wraps the a JSON structure retrieve via RPC. It extends the standard JS Map with. While it
* implements a Codec, it is limited in that it can only be used with input objects via RPC,
* i.e. no hex decoding. Unlike a struct, this waps a JSON object with unknown keys
* @noInheritDoc
*/
export default class ChainProperties extends Map<string, any> implements Codec {
export default class Json extends Map<string, any> implements Codec {
constructor (value?: { [index: string]: any } | null) {
super(ChainProperties.decodeChainProperties(value));
super(Json.decodeJson(value));
}
private static decodeChainProperties (value?: { [index: string]: any } | null): Array<[string, any]> {
private static decodeJson (value?: { [index: string]: any } | null): Array<[string, any]> {
return Object.entries(value || {});
}
@@ -37,20 +36,6 @@ export default class ChainProperties extends Map<string, any> implements Codec {
return [...this.keys()].length === 0;
}
/**
* @description The token decimals, if defined (de-facto standard only)
*/
get tokenDecimals (): number | undefined {
return this.get('tokenDecimals');
}
/**
* @description The token system, if defined (de-facto standard only)
*/
get tokenSymbol (): string | undefined {
return this.get('tokenSymbol');
}
/**
* @description Compares the value of the input to see if there is a match
*/
+13
View File
@@ -0,0 +1,13 @@
// 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 Json from './Json';
/**
* @name NetworkState
* @description
* Wraps the properties retrieved from the chain via the `system.network_state` RPC call.
*/
export default class NetworkState extends Json {
}
@@ -6,8 +6,8 @@ import Struct from '../codec/Struct';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import USize from '../primitive/USize';
import BlockNumber from './BlockNumber';
import Hash from './Hash';
import BlockNumber from '../type/BlockNumber';
import Hash from '../type/Hash';
const JSON_MAP = new Map([
['bestHash', 'best_hash'],
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Extrinsics from './Extrinsics';
import Extrinsics from '../type/Extrinsics';
/**
* @name PendingExtrinsics
@@ -4,7 +4,7 @@
import extrinsics from '@polkadot/extrinsics/static';
import Extrinsics from './Extrinsics';
import Extrinsics from '../type/Extrinsics';
import Method from '../primitive/Method';
import rpc from '../json/SignedBlock.001.json';
import events from '../json/SignedBlock.002.json';
@@ -5,9 +5,9 @@
import { AnyU8a } from '../types';
import Struct from '../codec/Struct';
import Block, { BlockValue } from './Block';
import Hash from './Hash';
import Justification from './Justification';
import Block, { BlockValue } from '../type/Block';
import Hash from '../type/Hash';
import Justification from '../type/Justification';
type SignedBlockValue = {
block?: BlockValue,
@@ -6,8 +6,8 @@ import { AnyU8a } from '../types';
import Struct from '../codec/Struct';
import Vector from '../codec/Vector';
import Hash from './Hash';
import { KeyValueOption, KeyValueOptionValue } from './KeyValue';
import Hash from '../type/Hash';
import { KeyValueOption, KeyValueOptionValue } from '../type/KeyValue';
type StorageChangeSetValue = {
block?: AnyU8a,
+20
View File
@@ -0,0 +1,20 @@
// 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.
// NOTE When adding any types here, we need to update the coumentation links as
// well - <root>/docs/SUMMARY.md as well as ../README.md
/**
* @summary Type definitions that are used in the rpc
*/
export { default as ChainProperties } from './ChainProperties';
export { default as ExtrinsicStatus } from './ExtrinsicStatus';
export { default as Health } from './Health';
export { default as Json } from './Json';
export { default as NetworkState } from './NetworkState';
export { default as PeerInfo } from './PeerInfo';
export { default as PendingExtrinsics } from './PendingExtrinsics';
export { default as RuntimeVersion } from './RuntimeVersion';
export { default as SignedBlock } from './SignedBlock';
export { default as StorageChangeSet } from './StorageChangeSet';
@@ -11,7 +11,7 @@ import Method from '../primitive/Method';
import U8 from '../primitive/U8';
import ExtrinsicEra from './ExtrinsicEra';
import Nonce from './NonceCompact';
import RuntimeVersion from './RuntimeVersion';
import RuntimeVersion from '../rpc/RuntimeVersion';
import Signature from './Signature';
import SignaturePayload from './SignaturePayload';
+1 -1
View File
@@ -12,7 +12,7 @@ import ExtrinsicEra from './ExtrinsicEra';
import Hash from './Hash';
import Method from '../primitive/Method';
import Nonce from './NonceCompact';
import RuntimeVersion from './RuntimeVersion';
import RuntimeVersion from '../rpc/RuntimeVersion';
type SignaturePayloadValue = {
nonce?: AnyNumber,
+1 -8
View File
@@ -20,7 +20,6 @@ export { default as Balance, BalanceOf } from './Balance';
// export * from './Bft;
export { default as Block } from './Block';
export { default as BlockNumber } from './BlockNumber';
export { default as ChainProperties } from './ChainProperties';
export { default as CodeHash } from './CodeHash';
export { default as Digest, DigestItem } from './Digest';
export { default as Event } from './Event';
@@ -28,13 +27,11 @@ export { default as EventRecord } from './EventRecord';
export { default as Extrinsic } from './Extrinsic';
export { default as ExtrinsicEra } from './ExtrinsicEra';
export { default as ExtrinsicSignature } from './ExtrinsicSignature';
export { default as ExtrinsicStatus } from './ExtrinsicStatus';
// NOTE Only used internally, exported as PendingExtrinsics
// export { default as Extrinsics } from './Extrinsics';
export { default as Gas } from './Gas';
export { default as Hash } from './Hash';
export { default as Header, HeaderExtended } from './Header';
export { default as Health } from './Health';
export { default as InherentOfflineReport } from './InherentOfflineReport';
export { default as KeyValue } from './KeyValue';
export { default as LockPeriods } from './LockPeriods';
@@ -46,8 +43,6 @@ 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';
export { default as PrefabWasmModule } from './PrefabWasmModule';
@@ -56,13 +51,11 @@ export { default as Proposal } from './Proposal';
export { default as ProposalIndex } from './ProposalIndex';
export { default as ReferendumIndex } from './ReferendumIndex';
export { default as ReferendumInfo } from './ReferendumInfo';
export { default as RuntimeVersion } from './RuntimeVersion';
export { default as Schedule } from './Schedule';
export { default as SeedOf } from './SeedOf';
export { default as SessionKey } from './SessionKey';
export { default as Signature, Ed25519Signature, Sr25519Signature } from './Signature';
export { default as SignedBlock } from './SignedBlock';
export { default as StorageChangeSet } from './StorageChangeSet';
export { default as StoredPendingChange } from './StoredPendingChange';
export { default as ValidatorPrefs } from './ValidatorPrefs';
export { default as VestingSchedule } from './VestingSchedule';