Latest metadata for substrate 2.x (#1151)

* Latest metadata for substrate 2.x

* Save json...

* Latest types

* typo in name

* typo in name

* Export all types from the seperate modules
This commit is contained in:
Jaco Greeff
2019-07-21 10:35:27 +02:00
committed by GitHub
parent 80305f5a34
commit 3d7a460cd2
19 changed files with 340 additions and 114 deletions
@@ -38,13 +38,36 @@
"name": "AllExtrinsicsWeight",
"modifier": "Optional",
"type": {
"PlainType": "u32"
"PlainType": "Weight"
},
"fallback": "0x00",
"documentation": [
" Total weight for all extrinsics put together, for the current block."
]
},
{
"name": "AllExtrinsicsLen",
"modifier": "Optional",
"type": {
"PlainType": "u32"
},
"fallback": "0x00",
"documentation": [
" Total length (in bytes) for all extrinsics put together, for the current block."
]
},
{
"name": "NextWeightMultiplier",
"modifier": "Default",
"type": {
"PlainType": "WeightMultiplier"
},
"fallback": "0x0000000000000000",
"documentation": [
" The next weight multiplier. This should be updated at the end of each block based on the",
" saturation level (weight)."
]
},
{
"name": "BlockHash",
"modifier": "Default",
@@ -2224,15 +2247,6 @@
}
],
"events": [
{
"name": "_Phantom",
"args": [
"Phantom"
],
"documentation": [
" Dummy to manage the fact we have instancing."
]
},
{
"name": "Proposed",
"args": [
@@ -2445,15 +2459,6 @@
}
],
"events": [
{
"name": "_Phantom",
"args": [
"Phantom"
],
"documentation": [
" Dummy to manage the fact we have instancing."
]
},
{
"name": "Proposed",
"args": [
@@ -3142,6 +3147,17 @@
" The current authority set."
]
},
{
"name": "State",
"modifier": "Default",
"type": {
"PlainType": "StoredState"
},
"fallback": "0x00",
"documentation": [
" State of the current authority set."
]
},
{
"name": "PendingChange",
"modifier": "Optional",
@@ -3199,6 +3215,20 @@
"documentation": [
" New authority set has been applied."
]
},
{
"name": "Paused",
"args": [],
"documentation": [
" Current authority set has been paused."
]
},
{
"name": "Resumed",
"args": [],
"documentation": [
" Current authority set has been resumed."
]
}
],
"constants": []
@@ -3924,6 +3954,83 @@
}
],
"constants": []
},
{
"name": "im_online",
"prefix": "ImOnline",
"storage": [
{
"name": "GossipAt",
"modifier": "Default",
"type": {
"PlainType": "BlockNumber"
},
"fallback": "0x0000000000000000",
"documentation": []
},
{
"name": "LastNewEraStart",
"modifier": "Optional",
"type": {
"PlainType": "SessionIndex"
},
"fallback": "0x00",
"documentation": []
},
{
"name": "ReceivedHeartbeats",
"modifier": "Default",
"type": {
"DoubleMapType": {
"hasher": "Blake2_256",
"key1": "SessionIndex",
"key2": "AuthorityId",
"value": "Bytes",
"key2Hasher": "Blake2_256"
}
},
"fallback": "0x00",
"documentation": []
}
],
"calls": [
{
"name": "heartbeat",
"args": [
{
"name": "heartbeat",
"type": "Heartbeat"
},
{
"name": "_signature",
"type": "Bytes"
}
],
"documentation": []
}
],
"events": [
{
"name": "HeartbeatReceived",
"args": [
"BlockNumber",
"AuthorityId"
],
"documentation": [
" A new heartbeat was received at this `BlockNumber` from `AuthorityId`"
]
}
],
"constants": [
{
"name": "SessionsPerEra",
"type": "SessionIndex",
"value": "0x06000000",
"documentation": [
" Number of sessions per era."
]
}
]
}
]
}
File diff suppressed because one or more lines are too long
@@ -2,12 +2,12 @@
// 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 '../primitive/U64';
import I64 from './I64';
/**
* @name AuthorityWeight
* @name I64Fixed
* @description
* The weight of an authority
* A 64-bit signed integer (Fixed64 in Rust)
*/
export default class AuthorityWeight extends U64 {
export default class I64Fixed extends I64 {
}
+3 -1
View File
@@ -63,8 +63,10 @@ export default class Type extends Text {
Type._alias('Lookup::Source', 'Address'),
// alias Lookup::Target to AccountId (always the case)
Type._alias('Lookup::Target', 'AccountId'),
// alias for grandpa, as used in polkador
// alias for grandpa, as used in polkadot
Type._alias('grandpa::AuthorityId', 'AuthorityId'),
// specific for SessionIndex (cvould make this session::, but be conservative)
Type._alias('session::SessionIndex', 'SessionIndex'),
// HACK duplication between contracts & primitives, however contracts prefixed with exec
Type._alias('exec::StorageKey', 'ContractStorageKey'),
// flattens tuples with one value, `(AccountId)` -> `AccountId`
+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 U32 from './U32';
/**
* @name Weight
* @description
* Numeric range of a transaction weight.
*/
export default class Weight extends U32 {
}
@@ -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 Fixed64 from '../primitive/I64Fixed';
/**
* @name WeightMultiplier
* @description
* Representation of a weight multiplier. This represents how a fee value can be computed from a weighted transaction, extending [[Fixed64]]
*/
export default class WeightMultiplier extends Fixed64 {
}
+3
View File
@@ -30,6 +30,7 @@ export { default as I8, default as i8 } from './I8';
export { default as I16, default as i16 } from './I16';
export { default as I32, default as i32 } from './I32';
export { default as I64, default as i64 } from './I64';
export { default as Fixed64 } from './I64Fixed';
export { default as I128, default as i128 } from './I128';
export { default as I256, default as i256 } from './I256';
export { default as Method } from './Method';
@@ -49,3 +50,5 @@ export { default as U64, default as u64 } from './U64';
export { default as U128, default as u128 } from './U128';
export { default as U256, default as u256 } from './U256';
export { default as USize, default as usize } from './USize';
export { default as Weight } from './Weight';
export { default as WeightMultiplier } from './WeightMultiplier';
+25 -12
View File
@@ -6,25 +6,30 @@ import fs from 'fs';
import { isString } from '@polkadot/util';
import { getTypeDef, TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '../codec/createType';
import * as primitives from '../primitive';
import * as substrate from '../type';
import * as definitions from '../srml/definitions';
// these map all the codec and primitive types for import, see the TypeImports below. If
// we have an unseen type, it is `undefined`/`false`, if we need to import it, it is `true`
interface TypeExist {
[index: string]: boolean;
}
type TypeExist = Record<string, boolean>;
interface TypeImports {
codecTypes: TypeExist;
otherTypes: TypeExist;
ownTypes: string[];
primitiveTypes: TypeExist;
substrateTypes: TypeExist;
}
const HEADER = '/* eslint-disable @typescript-eslint/no-empty-interface */\n// Auto-generated, do not edit\n\n';
const FOOTER = '\n';
function setImports ({ codecTypes, otherTypes, ownTypes }: TypeImports, type: string | null, codecType: string | null): void {
if (type && !ownTypes.includes(type) && !otherTypes[type]) {
otherTypes[type] = true;
function setImports ({ codecTypes, ownTypes, primitiveTypes, substrateTypes }: TypeImports, type: string | null, codecType: string | null): void {
if (type && !ownTypes.includes(type)) {
if ((primitives as any)[type]) {
primitiveTypes[type] = true;
} else if ((substrate as any)[type]) {
substrateTypes[type] = true;
}
}
if (codecType) {
@@ -63,7 +68,7 @@ function tsPlain ({ name: plainName, type }: TypeDef, imports: TypeImports): str
return `export interface ${plainName} extends ${type} {}`;
}
function _tsStructGetterType (structName: string | undefined, { info, sub, type }: TypeDef): [string, string] {
function _tsStructGetterType (structName: string | undefined, { info, sub, type }: TypeDef, imports: TypeImports): [string, string] {
switch (info) {
case TypeDefInfo.Plain:
return [type, type];
@@ -71,6 +76,8 @@ function _tsStructGetterType (structName: string | undefined, { info, sub, type
case TypeDefInfo.Vector:
const _type = (sub as TypeDef).type;
setImports(imports, null, 'Vector');
return [_type, `Vector<${_type}>`];
default:
@@ -80,7 +87,7 @@ function _tsStructGetterType (structName: string | undefined, { info, sub, type
function tsStruct ({ name: structName, sub }: TypeDef, imports: TypeImports): string {
const keys = (sub as TypeDef[]).map((typedef): string => {
const [embedType, returnType] = _tsStructGetterType(structName, typedef);
const [embedType, returnType] = _tsStructGetterType(structName, typedef, imports);
setImports(imports, embedType, 'Struct');
@@ -130,17 +137,19 @@ function generateTsDef (srmlName: string, { types }: { types: Record<string, any
};
const codecTypes: TypeExist = {};
const otherTypes: TypeExist = {};
const ownTypes = Object.keys(types);
const primitiveTypes: TypeExist = {};
const substrateTypes: TypeExist = {};
const interfaces = Object.entries(types).map(([name, type]): [string, string] => {
const def = getTypeDef(isString(type) ? type.toString() : JSON.stringify(type), name);
return [name, generators[def.info](def, { codecTypes, otherTypes, ownTypes })];
return [name, generators[def.info](def, { codecTypes, ownTypes, primitiveTypes, substrateTypes })];
});
let header = HEADER;
const codecImports = Object.keys(codecTypes).filter((name): boolean => name !== 'Tuple').sort();
const primitiveImports = Object.keys(otherTypes).filter((type): boolean => otherTypes[type]).sort();
const primitiveImports = Object.keys(primitiveTypes).filter((type): boolean => primitiveTypes[type]).sort();
const substrateImports = Object.keys(substrateTypes).filter((type): boolean => substrateTypes[type]).sort();
const sortedDefs = interfaces.sort((a, b): number => a[0].localeCompare(b[0])).map(([, definition]): string => definition);
if (codecTypes['Tuple']) {
@@ -155,6 +164,10 @@ function generateTsDef (srmlName: string, { types }: { types: Record<string, any
header = header.concat(`import { ${primitiveImports.join(', ')} } from '../../primitive';\n`);
}
if (substrateImports.length) {
header = header.concat(`import { ${substrateImports.join(', ')} } from '../../type';\n`);
}
fs.writeFileSync(`packages/types/src/srml/${srmlName}/types.ts`, header.concat('\n').concat(sortedDefs.join('\n\n')).concat(FOOTER), { flag: 'w' });
}
+6
View File
@@ -2,4 +2,10 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// NOTE The order here is NOT alphabetical, rather it is setup so that lower
// layers can re-use types from higher layers as this is being injected. The
// injection order is critical.
export { default as grandpa } from './grandpa/definitions';
export { default as imOnline } from './imOnline/definitions';
export { default as parachains } from './parachains/definitions';
@@ -0,0 +1,39 @@
// 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.
export default {
types: {
AuthorityWeight: 'u64',
NextAuthority: '(SessionKey, u64)',
PendingPause: {
/// Block at which the intention to pause was scheduled.
scheduledAt: 'BlockNumber',
/// Number of blocks after which the change will be enacted.
delay: 'BlockNumber'
},
PendingResume: {
/// Block at which the intention to resume was scheduled.
scheduledAt: 'BlockNumber',
/// Number of blocks after which the change will be enacted.
delay: 'BlockNumber'
},
StoredPendingChange: {
scheduledAt: 'BlockNumber',
delay: 'BlockNumber',
nextAuthorities: 'Vec<NextAuthority>'
},
StoredState: {
_enum: {
/// The current authority set is live, and GRANDPA is enabled.
Live: 'Null',
/// There is a pending pause event which will be enacted at the given block height.
PendingPause: 'PendingPause',
/// The current GRANDPA authority set is paused.
Paused: 'Null',
/// There is a pending resume event which will be enacted at the given block height.
PendingResume: 'PendingResume'
}
}
}
};
+49
View File
@@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
// Auto-generated, do not edit
import { Codec } from '../../types';
import { Enum, Struct, Vector } from '../../codec';
import { u64 } from '../../primitive';
import { BlockNumber, SessionKey } from '../../type';
export interface AuthorityWeight extends u64 {}
type _NextAuthority = [SessionKey, u64];
export interface NextAuthority extends Codec, _NextAuthority {}
export interface PendingPause extends Struct {
readonly scheduledAt: BlockNumber;
readonly delay: BlockNumber;
}
export interface PendingResume extends Struct {
readonly scheduledAt: BlockNumber;
readonly delay: BlockNumber;
}
export interface StoredPendingChange extends Struct {
readonly scheduledAt: BlockNumber;
readonly delay: BlockNumber;
readonly nextAuthorities: Vector<NextAuthority>;
}
export interface StoredState extends Enum {
/**
* @description 0:: Live
*/
readonly isLive: boolean;
/**
* @description 1:: PendingPause(PendingPause)
*/
readonly isPendingPause: boolean;
readonly asPendingPause: PendingPause;
/**
* @description 2:: Paused
*/
readonly isPaused: boolean;
/**
* @description 3:: PendingResume(PendingResume)
*/
readonly isPendingResume: boolean;
readonly asPendingResume: PendingResume;
}
@@ -0,0 +1,22 @@
// 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.
export default {
types: {
OpaqueMultiaddr: 'Bytes',
OpaquePeerId: 'Bytes',
OpaqueNetworkState: {
/// PeerId of the local node.
peerId: 'OpaquePeerId',
/// List of addresses the node knows it can be reached as.
externalAddresses: 'Vec<OpaqueMultiaddr>'
},
Heartbeat: {
blockNumber: 'BlockNumber',
networkState: 'OpaqueNetworkState',
sessionIndex: 'SessionIndex',
authorityId: 'AuthorityId'
}
}
};
+22
View File
@@ -0,0 +1,22 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
// Auto-generated, do not edit
import { Struct, Vector } from '../../codec';
import { Bytes } from '../../primitive';
import { AuthorityId, BlockNumber, SessionIndex } from '../../type';
export interface Heartbeat extends Struct {
readonly blockNumber: BlockNumber;
readonly networkState: OpaqueNetworkState;
readonly sessionIndex: SessionIndex;
readonly authorityId: AuthorityId;
}
export interface OpaqueMultiaddr extends Bytes {}
export interface OpaqueNetworkState extends Struct {
readonly peerId: OpaquePeerId;
readonly externalAddresses: Vector<OpaqueMultiaddr>;
}
export interface OpaquePeerId extends Bytes {}
@@ -6,8 +6,7 @@ export default {
types: {
AuctionIndex: 'u32',
CollatorSignature: 'Signature',
// Until we are able to import the SessionKey from grandpa, define as AccountId
AvailabilityVote: '(AccountId, CollatorSignature)', // '(SessionKey, CollatorSignature)',
AvailabilityVote: '(SessionKey, CollatorSignature)',
ValidityAttestation: {
_enum: {
// This Null is not in the original, however indexes start at 1, so add a
+2 -1
View File
@@ -4,6 +4,7 @@
import { Codec } from '../../types';
import { Enum, Struct, Vector } from '../../codec';
import { AccountId, BalanceOf, Bytes, Hash, Signature, u32, u64 } from '../../primitive';
import { SessionKey } from '../../type';
export interface AttestedCandidate extends Struct {
readonly candidate: CandidateReceipt;
@@ -13,7 +14,7 @@ export interface AttestedCandidate extends Struct {
export interface AuctionIndex extends u32 {}
type _AvailabilityVote = [AccountId, CollatorSignature];
type _AvailabilityVote = [SessionKey, CollatorSignature];
export interface AvailabilityVote extends Codec, _AvailabilityVote {}
type _BalanceUpload = [AccountId, u64];
+7
View File
@@ -0,0 +1,7 @@
// 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.
export * from './grandpa/types';
export * from './imOnline/types';
export * from './parachains/types';
@@ -1,72 +0,0 @@
// 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 { AnyNumber, AnyU8a } from '../types';
import Struct from '../codec/Struct';
import Tuple from '../codec/Tuple';
import Vector from '../codec/Vector';
import U64 from '../primitive/U64';
import BlockNumber from './BlockNumber';
import SessionKey from './SessionKey';
export interface NextAuthorityValue {
index?: AnyNumber;
sessionKey?: AnyU8a;
}
export interface StoredPendingChangeValue {
scheduledAt: AnyNumber;
delay: AnyNumber;
nextAuthorities?: (Uint8Array | NextAuthorityValue)[];
}
/**
* @name NextAuthority
* @description
* The next authority available as [[SessionKey]]
*/
export class NextAuthority extends Tuple {
public constructor (value?: Uint8Array | NextAuthorityValue) {
super({
SessionKey,
U64
}, value);
}
public get index (): U64 {
return this[1] as U64;
}
public get sessionKey (): SessionKey {
return this[0] as SessionKey;
}
}
/**
* @name StoredPendingChange
* @description
* Stored pending change for a Grandpa events
*/
export default class StoredPendingChange extends Struct {
public constructor (value?: Uint8Array | StoredPendingChangeValue) {
super({
scheduledAt: BlockNumber,
delay: BlockNumber,
nextAuthorities: Vector.with(NextAuthority)
}, value);
}
public get delay (): BlockNumber {
return this.get('delay') as BlockNumber;
}
public get nextAuthorities (): Vector<NextAuthority> {
return this.get('nextAuthorities') as Vector<NextAuthority>;
}
public get scheduledAt (): BlockNumber {
return this.get('scheduledAt') as BlockNumber;
}
}
-2
View File
@@ -12,7 +12,6 @@ export { default as Amount } from './Amount';
export { default as ApprovalFlag } from './ApprovalFlag';
export { default as AssetOf } from './AssetOf';
export { default as AuthorityId } from './AuthorityId';
export { default as AuthorityWeight } from './AuthorityWeight';
export { default as BalanceLock } from './BalanceLock';
// NOTE Bft items are only used in internal structures
// export * from './Bft;
@@ -62,7 +61,6 @@ export { default as SessionKeys } from './SessionKeys';
export { default as SetIndex } from './SetIndex';
export { default as SignaturePayload, SignaturePayloadRaw } from './SignaturePayload';
export { default as StakingLedger } from './StakingLedger';
export { default as StoredPendingChange } from './StoredPendingChange';
export { default as TreasuryProposal } from './TreasuryProposal';
export { default as UncleEntryItem } from './UncleEntryItem';
export { default as UnlockChunk } from './UnlockChunk';