Metadata update for latest master (#901)
* Latest metadata, add EventIndex type * Add parsed metadata * Create empty DoubleMap type
This commit is contained in:
@@ -6,18 +6,15 @@ import { AnyNumber } from '../../types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import Enum from '../../codec/Enum';
|
||||
import EnumType from '../../codec/EnumType';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Bool from '../../primitive/Bool';
|
||||
import Bytes from '../../primitive/Bytes';
|
||||
import StorageHasher from '../../primitive/StorageHasher';
|
||||
import Text from '../../primitive/Text';
|
||||
import Type from '../../primitive/Type';
|
||||
import {
|
||||
PlainType,
|
||||
StorageFunctionModifier
|
||||
} from '../v3/Storage';
|
||||
import { PlainType, StorageFunctionModifier } from '../v3/Storage';
|
||||
|
||||
// Re-export classes that haven't changed between V3 and V4
|
||||
export {
|
||||
@@ -25,52 +22,6 @@ export {
|
||||
StorageFunctionModifier
|
||||
};
|
||||
|
||||
export class StorageHasher extends Enum {
|
||||
constructor (value?: any) {
|
||||
super(['Blake2_128', 'Blake2_256', 'Twox128', 'Twox256', 'Twox128Concat'], value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Is the enum Blake2_128?
|
||||
*/
|
||||
get isBlake2128 (): boolean {
|
||||
return this.toNumber() === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Is the enum Blake2_256?
|
||||
*/
|
||||
get isBlake2256 (): boolean {
|
||||
return this.toNumber() === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Is the enum Twox128?
|
||||
*/
|
||||
get isTwox128 (): boolean {
|
||||
return this.toNumber() === 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Is the enum Twox256?
|
||||
*/
|
||||
get isTwox256 (): boolean {
|
||||
return this.toNumber() === 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Is the enum isTwox128Concat?
|
||||
*/
|
||||
get isTwox128Concat (): boolean {
|
||||
return this.toNumber() === 4;
|
||||
}
|
||||
|
||||
toJSON (): any {
|
||||
// This looks prettier in the generated JSON
|
||||
return this.toString();
|
||||
}
|
||||
}
|
||||
|
||||
export class MapType extends Struct {
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
@@ -219,7 +170,7 @@ export class StorageFunctionType extends EnumType<PlainType | MapType | DoubleMa
|
||||
*/
|
||||
toString (): string {
|
||||
if (this.isDoubleMap) {
|
||||
return this.asDoubleMap.toString();
|
||||
return `DoubleMap<${this.asDoubleMap.toString()}>`;
|
||||
}
|
||||
|
||||
if (this.isMap) {
|
||||
|
||||
@@ -78,14 +78,15 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "RandomSeed",
|
||||
"name": "RandomMaterial",
|
||||
"modifier": "Default",
|
||||
"type": {
|
||||
"PlainType": "Hash"
|
||||
"PlainType": "(i8,Vec<Hash>)"
|
||||
},
|
||||
"fallback": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"fallback": "0x0000",
|
||||
"documentation": [
|
||||
" Random seed of the current block."
|
||||
" Series of block headers from the last 81 blocks that acts as random seed material. This is arranged as a",
|
||||
" ring buffer with the `i8` prefix being the index into the `Vec` of the oldest hash."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -142,6 +143,46 @@
|
||||
"documentation": [
|
||||
" Events deposited for the current block."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "EventCount",
|
||||
"modifier": "Default",
|
||||
"type": {
|
||||
"PlainType": "EventIndex"
|
||||
},
|
||||
"fallback": "0x00000000",
|
||||
"documentation": [
|
||||
" The number of events in the `Events<T>` list."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "EventTopics",
|
||||
"modifier": "Default",
|
||||
"type": {
|
||||
"DoubleMapType": {
|
||||
"hasher": "Blake2_256",
|
||||
"key1": "Null",
|
||||
"key2": "Hash",
|
||||
"value": "Vec<(BlockNumber,EventIndex)>",
|
||||
"key2Hasher": "blake2_256"
|
||||
}
|
||||
},
|
||||
"fallback": "0x00",
|
||||
"documentation": [
|
||||
" Mapping between a topic (represented by T::Hash) and a vector of indexes",
|
||||
" of events in the `<Events<T>>` list.",
|
||||
"",
|
||||
" The first key serves no purpose. This field is declared as double_map just",
|
||||
" for convenience of using `remove_prefix`.",
|
||||
"",
|
||||
" All topic vectors have deterministic storage locations depending on the topic. This",
|
||||
" allows light-clients to leverage the changes trie storage tracking mechanism and",
|
||||
" in case of changes fetch the list of events of interest.",
|
||||
"",
|
||||
" The value has the type `(T::BlockNumber, EventIndex)` because if we used only just",
|
||||
" the `EventIndex` then in case if the topic has the same contents on the next block",
|
||||
" no notification will be triggered thus the event might be lost."
|
||||
]
|
||||
}
|
||||
],
|
||||
"calls": null,
|
||||
@@ -1462,7 +1503,7 @@
|
||||
},
|
||||
"fallback": "0x00000000",
|
||||
"documentation": [
|
||||
" The next free referendum index, aka the number of referendums started so far."
|
||||
" The next free referendum index, aka the number of referenda started so far."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,7 +7,7 @@ import { Constructor, Codec } from '../types';
|
||||
|
||||
type TypeWithValues = [Constructor, Array<any>];
|
||||
|
||||
export class Linkage<T extends Codec> extends Struct {
|
||||
export default class Linkage<T extends Codec> extends Struct {
|
||||
constructor (Type: Constructor, value?: any) {
|
||||
super({
|
||||
previous: Option.with(Type),
|
||||
|
||||
@@ -5,16 +5,17 @@
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { Codec, Constructor } from '../types';
|
||||
import Null from '../primitive/Null';
|
||||
import Text from '../primitive/Text';
|
||||
import EnumType from './EnumType';
|
||||
import Compact from './Compact';
|
||||
import EnumType from './EnumType';
|
||||
import Linkage from './Linkage';
|
||||
import Option from './Option';
|
||||
import Struct from './Struct';
|
||||
import Tuple from './Tuple';
|
||||
import UInt from './UInt';
|
||||
import Vector from './Vector';
|
||||
import getRegistry from './typeRegistry';
|
||||
import { Linkage } from './Linkage';
|
||||
|
||||
export enum TypeDefInfo {
|
||||
Compact,
|
||||
@@ -24,7 +25,9 @@ export enum TypeDefInfo {
|
||||
Struct,
|
||||
Tuple,
|
||||
Vector,
|
||||
Linkage
|
||||
Linkage,
|
||||
// anything not full supported (keep this as the last entry)
|
||||
Null
|
||||
}
|
||||
|
||||
export type TypeDef = {
|
||||
@@ -116,8 +119,16 @@ export function getTypeDef (_type: Text | string, name?: string): TypeDef {
|
||||
|
||||
// not as pretty, but remain compatible with oo7 for both struct and Array types
|
||||
value.sub = Array.isArray(details)
|
||||
? details.map((name) => ({ info: TypeDefInfo.Plain, name, type: 'Null' }))
|
||||
: Object.keys(details).map((name) => ({ info: TypeDefInfo.Plain, name, type: details[name] || 'Null' }));
|
||||
? details.map((name) => ({
|
||||
info: TypeDefInfo.Plain,
|
||||
name,
|
||||
type: 'Null'
|
||||
}))
|
||||
: Object.keys(details).map((name) => ({
|
||||
info: TypeDefInfo.Plain,
|
||||
name,
|
||||
type: details[name] || 'Null'
|
||||
}));
|
||||
value.info = TypeDefInfo.Enum;
|
||||
} else {
|
||||
value.info = TypeDefInfo.Struct;
|
||||
@@ -135,6 +146,9 @@ export function getTypeDef (_type: Text | string, name?: string): TypeDef {
|
||||
} else if (startingWith(type, 'Linkage<', '>')) {
|
||||
value.info = TypeDefInfo.Linkage;
|
||||
value.sub = getTypeDef(subType);
|
||||
} else if (startingWith(type, 'DoubleMap<', '>')) {
|
||||
// FIXME As a first step, only allow parsing of DoubleMap, don't actually init
|
||||
value.info = TypeDefInfo.Null;
|
||||
}
|
||||
|
||||
return value;
|
||||
@@ -195,9 +209,12 @@ export function getTypeClass (value: TypeDef): Constructor {
|
||||
);
|
||||
case TypeDefInfo.Linkage:
|
||||
assert(value.sub && !Array.isArray(value.sub), 'Expected subtype for Linkage');
|
||||
|
||||
return Linkage.withKey(
|
||||
getTypeClass(value.sub as TypeDef)
|
||||
);
|
||||
case TypeDefInfo.Null:
|
||||
return Null;
|
||||
}
|
||||
|
||||
throw new Error(`Unable to determine type from '${value.type}'`);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// 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 Enum from '../codec/Enum';
|
||||
|
||||
export default class StorageHasher extends Enum {
|
||||
constructor (value?: any) {
|
||||
super(['Blake2_128', 'Blake2_256', 'Twox128', 'Twox256', 'Twox128Concat'], value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Is the enum Blake2_128?
|
||||
*/
|
||||
get isBlake2128 (): boolean {
|
||||
return this.toNumber() === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Is the enum Blake2_256?
|
||||
*/
|
||||
get isBlake2256 (): boolean {
|
||||
return this.toNumber() === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Is the enum Twox128?
|
||||
*/
|
||||
get isTwox128 (): boolean {
|
||||
return this.toNumber() === 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Is the enum Twox256?
|
||||
*/
|
||||
get isTwox256 (): boolean {
|
||||
return this.toNumber() === 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Is the enum isTwox128Concat?
|
||||
*/
|
||||
get isTwox128Concat (): boolean {
|
||||
return this.toNumber() === 4;
|
||||
}
|
||||
|
||||
toJSON (): any {
|
||||
// This looks prettier in the generated JSON
|
||||
return this.toString();
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ export { default as Method } from './Method';
|
||||
export { default as Moment, MomentOf } from './Moment';
|
||||
export { default as Null } from './Null';
|
||||
export { default as StorageData } from './StorageData';
|
||||
export { default as StorageHasher } from './StorageHasher';
|
||||
export { default as StorageKey } from './StorageKey';
|
||||
export { default as Text } from './Text';
|
||||
export { default as Type } from './Type';
|
||||
|
||||
@@ -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 '../primitive/U32';
|
||||
|
||||
/**
|
||||
* @name EventIndex
|
||||
* @description
|
||||
* The Substrate EventIndex representation as a [[U32]].
|
||||
*/
|
||||
export default class EventIndex extends U32 {
|
||||
}
|
||||
@@ -26,6 +26,7 @@ export { default as CodeHash } from './CodeHash';
|
||||
export { default as ContractInfo } from './ContractInfo';
|
||||
export { default as Digest, DigestItem } from './Digest';
|
||||
export { default as Event } from './Event';
|
||||
export { default as EventIndex } from './EventIndex';
|
||||
export { default as EventRecord } from './EventRecord';
|
||||
export { default as Exposure } from './Exposure';
|
||||
export { default as Extrinsic } from './Extrinsic';
|
||||
|
||||
Reference in New Issue
Block a user