Update system.networkState types (#1951)
This commit is contained in:
@@ -25,7 +25,7 @@ import { CallMetadataV0, DoubleMapTypeLatest, DoubleMapTypeV10, DoubleMapTypeV11
|
||||
import { Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
|
||||
import { AttestedCandidate, AuctionIndex, Bidder, CandidateReceipt, CollatorId, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaScheduling, ParachainDispatchOrigin, Retriable, SlotRange, SubId, UpwardMessage, ValidityAttestation, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
|
||||
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
|
||||
import { ApiId, BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
|
||||
import { ApiId, BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, DispatchClass, DispatchInfo, DispatchInfoTo190, Fixed64, H160, H256, H512, Hash, Header, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, Moment, Origin, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Seal, SealV0, SignedBlock, StorageData, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
|
||||
import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6 } from '@polkadot/types/interfaces/session';
|
||||
import { Bid, BidKind, BidKindVouch, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
|
||||
@@ -1523,6 +1523,27 @@ declare module '@polkadot/types/types/registry' {
|
||||
NetworkState: NetworkState;
|
||||
'Option<NetworkState>': Option<NetworkState>;
|
||||
'Vec<NetworkState>': Vec<NetworkState>;
|
||||
Peer: Peer;
|
||||
'Option<Peer>': Option<Peer>;
|
||||
'Vec<Peer>': Vec<Peer>;
|
||||
NotConnectedPeer: NotConnectedPeer;
|
||||
'Option<NotConnectedPeer>': Option<NotConnectedPeer>;
|
||||
'Vec<NotConnectedPeer>': Vec<NotConnectedPeer>;
|
||||
PeerEndpoint: PeerEndpoint;
|
||||
'Option<PeerEndpoint>': Option<PeerEndpoint>;
|
||||
'Vec<PeerEndpoint>': Vec<PeerEndpoint>;
|
||||
PeerEndpointAddr: PeerEndpointAddr;
|
||||
'Option<PeerEndpointAddr>': Option<PeerEndpointAddr>;
|
||||
'Vec<PeerEndpointAddr>': Vec<PeerEndpointAddr>;
|
||||
PeerPing: PeerPing;
|
||||
'Option<PeerPing>': Option<PeerPing>;
|
||||
'Vec<PeerPing>': Vec<PeerPing>;
|
||||
NetworkStatePeerset: NetworkStatePeerset;
|
||||
'Option<NetworkStatePeerset>': Option<NetworkStatePeerset>;
|
||||
'Vec<NetworkStatePeerset>': Vec<NetworkStatePeerset>;
|
||||
NetworkStatePeersetInfo: NetworkStatePeersetInfo;
|
||||
'Option<NetworkStatePeersetInfo>': Option<NetworkStatePeersetInfo>;
|
||||
'Vec<NetworkStatePeersetInfo>': Vec<NetworkStatePeersetInfo>;
|
||||
PeerInfo: PeerInfo;
|
||||
'Option<PeerInfo>': Option<PeerInfo>;
|
||||
'Vec<PeerInfo>': Vec<PeerInfo>;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { H256 } from '../interfaces/runtime';
|
||||
import { AnyJson, Constructor, Codec, InterfaceTypes, Registry } from '../types';
|
||||
|
||||
import { isHex, hexToU8a, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { isHex, hexToU8a, isObject, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Compact from './Compact';
|
||||
@@ -35,17 +35,21 @@ function decodeBTreeMapFromU8a<K extends Codec = Codec, V extends Codec = Codec>
|
||||
function decodeBTreeMapFromMap<K extends Codec = Codec, V extends Codec = Codec> (registry: Registry, KeyClass: Constructor<K>, ValClass: Constructor<V>, value: Map<any, any>): Map<K, V> {
|
||||
const output = new Map<K, V>();
|
||||
|
||||
value.forEach((v: any, k: any) => {
|
||||
let key, val;
|
||||
value.forEach((val: any, key: any) => {
|
||||
try {
|
||||
key = (k instanceof KeyClass) ? k : new KeyClass(registry, k);
|
||||
val = (v instanceof ValClass) ? v : new ValClass(registry, v);
|
||||
output.set(
|
||||
key instanceof KeyClass
|
||||
? key
|
||||
: new KeyClass(registry, key),
|
||||
val instanceof ValClass
|
||||
? val
|
||||
: new ValClass(registry, val)
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Failed to decode BTreeMap key or value:', error.message);
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
output.set(key, val);
|
||||
});
|
||||
|
||||
return output;
|
||||
@@ -78,6 +82,8 @@ function decodeBTreeMap<K extends Codec = Codec, V extends Codec = Codec> (regis
|
||||
return decodeBTreeMapFromU8a<K, V>(registry, KeyClass, ValClass, u8aToU8a(value));
|
||||
} else if (value instanceof Map) {
|
||||
return decodeBTreeMapFromMap<K, V>(registry, KeyClass, ValClass, value);
|
||||
} else if (isObject(value)) {
|
||||
return decodeBTreeMapFromMap<K, V>(registry, KeyClass, ValClass, new Map(Object.entries(value)));
|
||||
}
|
||||
|
||||
throw new Error('BTreeMap: cannot decode type');
|
||||
|
||||
@@ -119,9 +119,9 @@ export default class Struct<
|
||||
this.#Types = mapToTypeMap(registry, Types);
|
||||
}
|
||||
|
||||
public static with<S extends TypesDef> (Types: S): Constructor<Struct<S>> {
|
||||
public static with<S extends TypesDef> (Types: S, jsonMap?: Map<keyof S, string>): Constructor<Struct<S>> {
|
||||
return class extends Struct<S> {
|
||||
constructor (registry: Registry, value?: any, jsonMap?: Map<keyof S, string>) {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
super(registry, Types, value, jsonMap);
|
||||
|
||||
(Object.keys(Types) as (keyof S)[]).forEach((key): void => {
|
||||
@@ -233,10 +233,9 @@ export default class Struct<
|
||||
*/
|
||||
public toHuman (isExtended?: boolean): AnyJson {
|
||||
return [...this.keys()].reduce((json, key): any => {
|
||||
const jsonKey = this.#jsonMap.get(key) || key;
|
||||
const value = this.get(key);
|
||||
|
||||
json[jsonKey] = value && value.toHuman(isExtended);
|
||||
json[key] = value && value.toHuman(isExtended);
|
||||
|
||||
return json;
|
||||
}, {} as any);
|
||||
|
||||
@@ -139,7 +139,7 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
);
|
||||
},
|
||||
|
||||
[TypeDefInfo.Struct]: (registry: Registry, value: TypeDef): Constructor => Struct.with(getTypeClassMap(value)),
|
||||
[TypeDefInfo.Struct]: (registry: Registry, value: TypeDef): Constructor => Struct.with(getTypeClassMap(value), value.alias),
|
||||
|
||||
[TypeDefInfo.Tuple]: (registry: Registry, value: TypeDef): Constructor => Tuple.with(getTypeClassArray(value)),
|
||||
|
||||
|
||||
@@ -60,7 +60,10 @@ function _decodeStruct (value: TypeDef, type: string, _: string): TypeDef {
|
||||
return _decodeSet(value, parsed[keys[0]]);
|
||||
}
|
||||
|
||||
value.sub = keys.map((name): TypeDef =>
|
||||
value.alias = parsed._alias
|
||||
? new Map(Object.entries(parsed._alias))
|
||||
: undefined;
|
||||
value.sub = keys.filter((name) => !['_alias'].includes(name)).map((name): TypeDef =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
getTypeDef(parsed[name], { name })
|
||||
);
|
||||
|
||||
@@ -62,7 +62,12 @@ function _findClosing (value: string, start: number): number {
|
||||
function _alias (src: string[], dest: string): Mapper {
|
||||
return (value: string): string => {
|
||||
return src.reduce((value, src): string => {
|
||||
return value.replace(new RegExp(src, 'g'), dest);
|
||||
// HACK... f-ing HACK. This needs a fix, so this is a HUGE FIXME
|
||||
// ignore versionString, the replace just does global replace, check the box aliases
|
||||
// (versionString from network alias definitions)
|
||||
return value.includes('versionString')
|
||||
? value
|
||||
: value.replace(new RegExp(src, 'g'), dest);
|
||||
}, value);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ export interface TypeDefExtEnumDiscriminant {
|
||||
}
|
||||
|
||||
export interface TypeDef {
|
||||
alias?: Map<string, string>;
|
||||
info: TypeDefInfo;
|
||||
index?: number;
|
||||
displayName?: string;
|
||||
|
||||
@@ -38,7 +38,52 @@ export default {
|
||||
},
|
||||
KeyValueOption: '(StorageKey, Option<StorageData>)',
|
||||
NetworkState: {
|
||||
peerId: 'Text'
|
||||
peerId: 'Text',
|
||||
listenedAddresses: 'Vec<Text>',
|
||||
externalAddresses: 'Vec<Text>',
|
||||
// FIXME These are HashMap
|
||||
connectedPeers: 'BTreeMap<Text, Peer>',
|
||||
notConnectedPeers: 'BTreeMap<Text, NotConnectedPeer>',
|
||||
averageDownloadPerSec: 'u64',
|
||||
averageUploadPerSec: 'u64',
|
||||
peerset: 'NetworkStatePeerset'
|
||||
},
|
||||
Peer: {
|
||||
enabled: 'bool',
|
||||
endpoint: 'PeerEndpoint',
|
||||
knownAddresses: 'Vec<Text>',
|
||||
latestPingTime: 'PeerPing',
|
||||
open: 'bool',
|
||||
versionString: 'Text'
|
||||
},
|
||||
NotConnectedPeer: {
|
||||
knownAddresses: 'Vec<Text>',
|
||||
latestPingTime: 'Option<PeerPing>',
|
||||
versionString: 'Option<Text>'
|
||||
},
|
||||
PeerEndpoint: {
|
||||
listening: 'PeerEndpointAddr'
|
||||
},
|
||||
PeerEndpointAddr: {
|
||||
_alias: {
|
||||
localAddr: 'local_addr',
|
||||
sendBackAddr: 'send_back_addr'
|
||||
},
|
||||
localAddr: 'Text',
|
||||
sendBackAddr: 'Text'
|
||||
},
|
||||
PeerPing: {
|
||||
nanos: 'u64',
|
||||
secs: 'u64'
|
||||
},
|
||||
NetworkStatePeerset: {
|
||||
messageQueue: 'u64',
|
||||
// FIXME This is HashMap
|
||||
nodes: 'BTreeMap<Text, NetworkStatePeersetInfo>'
|
||||
},
|
||||
NetworkStatePeersetInfo: {
|
||||
connected: 'bool',
|
||||
reputation: 'u64'
|
||||
},
|
||||
PeerInfo: {
|
||||
peerId: 'Text',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { Enum, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
|
||||
import { BTreeMap, Enum, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
|
||||
import { Bytes, StorageKey, Text, bool, u32, u64, u8 } from '@polkadot/types/primitive';
|
||||
import { Balance, BlockNumber, DispatchClass, Hash, StorageData, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
|
||||
@@ -60,6 +60,53 @@ export interface KeyValueOption extends ITuple<[StorageKey, Option<StorageData>]
|
||||
/** @name NetworkState */
|
||||
export interface NetworkState extends Struct {
|
||||
readonly peerId: Text;
|
||||
readonly listenedAddresses: Vec<Text>;
|
||||
readonly externalAddresses: Vec<Text>;
|
||||
readonly connectedPeers: BTreeMap<Text, Peer>;
|
||||
readonly notConnectedPeers: BTreeMap<Text, NotConnectedPeer>;
|
||||
readonly averageDownloadPerSec: u64;
|
||||
readonly averageUploadPerSec: u64;
|
||||
readonly peerset: NetworkStatePeerset;
|
||||
}
|
||||
|
||||
/** @name NetworkStatePeerset */
|
||||
export interface NetworkStatePeerset extends Struct {
|
||||
readonly messageQueue: u64;
|
||||
readonly nodes: BTreeMap<Text, NetworkStatePeersetInfo>;
|
||||
}
|
||||
|
||||
/** @name NetworkStatePeersetInfo */
|
||||
export interface NetworkStatePeersetInfo extends Struct {
|
||||
readonly connected: bool;
|
||||
readonly reputation: u64;
|
||||
}
|
||||
|
||||
/** @name NotConnectedPeer */
|
||||
export interface NotConnectedPeer extends Struct {
|
||||
readonly knownAddresses: Vec<Text>;
|
||||
readonly latestPingTime: Option<PeerPing>;
|
||||
readonly versionString: Option<Text>;
|
||||
}
|
||||
|
||||
/** @name Peer */
|
||||
export interface Peer extends Struct {
|
||||
readonly enabled: bool;
|
||||
readonly endpoint: PeerEndpoint;
|
||||
readonly knownAddresses: Vec<Text>;
|
||||
readonly latestPingTime: PeerPing;
|
||||
readonly open: bool;
|
||||
readonly versionString: Text;
|
||||
}
|
||||
|
||||
/** @name PeerEndpoint */
|
||||
export interface PeerEndpoint extends Struct {
|
||||
readonly listening: PeerEndpointAddr;
|
||||
}
|
||||
|
||||
/** @name PeerEndpointAddr */
|
||||
export interface PeerEndpointAddr extends Struct {
|
||||
readonly localAddr: Text;
|
||||
readonly sendBackAddr: Text;
|
||||
}
|
||||
|
||||
/** @name PeerInfo */
|
||||
@@ -71,6 +118,12 @@ export interface PeerInfo extends Struct {
|
||||
readonly bestNumber: BlockNumber;
|
||||
}
|
||||
|
||||
/** @name PeerPing */
|
||||
export interface PeerPing extends Struct {
|
||||
readonly nanos: u64;
|
||||
readonly secs: u64;
|
||||
}
|
||||
|
||||
/** @name RpcMethods */
|
||||
export interface RpcMethods extends Struct {
|
||||
readonly version: u32;
|
||||
|
||||
Reference in New Issue
Block a user