diff --git a/packages/api/test/e2e/rpc-core/state.spec.ts b/packages/api/test/e2e/rpc-core/state.spec.ts index be7821ed66..9c8c2b57b5 100644 --- a/packages/api/test/e2e/rpc-core/state.spec.ts +++ b/packages/api/test/e2e/rpc-core/state.spec.ts @@ -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 { Balance, Hash, StorageData } from '@polkadot/types/interfaces'; +import { Balance, Hash, Moment, StorageData } from '@polkadot/types/interfaces'; import fs from 'fs'; import path from 'path'; @@ -13,10 +13,10 @@ import storage from '@polkadot/api-metadata/storage/static'; import { Abi } from '@polkadot/api-contract'; import testingPairs from '@polkadot/keyring/testingPairs'; import { KeyringPair } from '@polkadot/keyring/types'; -import WsProvider from '@polkadot/rpc-provider/ws'; -import { Bytes, Metadata, Moment, StorageKey } from '@polkadot/types'; - import Rpc from '@polkadot/rpc-core'; +import WsProvider from '@polkadot/rpc-provider/ws'; +import { Bytes, Metadata, StorageKey } from '@polkadot/types'; + import flipperAbi from '../../../../api-contract/test/contracts/flipper.json'; const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; diff --git a/packages/types/src/Metadata/util/validateTypes.ts b/packages/types/src/Metadata/util/validateTypes.ts index b091fbde4b..06cc44dd87 100644 --- a/packages/types/src/Metadata/util/validateTypes.ts +++ b/packages/types/src/Metadata/util/validateTypes.ts @@ -2,9 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '../../codec/types'; + import { isUndefined } from '@polkadot/util'; -import { getTypeDef, TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '../../codec/createType'; +import { getTypeDef } from '../../codec/createType'; import flattenUniq from './flattenUniq'; import { getTypeRegistry } from '../../codec'; diff --git a/packages/types/src/codec/Compact.spec.ts b/packages/types/src/codec/Compact.spec.ts index c053f8d459..9859df2ad5 100644 --- a/packages/types/src/codec/Compact.spec.ts +++ b/packages/types/src/codec/Compact.spec.ts @@ -7,7 +7,7 @@ import '../injector'; import BN from 'bn.js'; import createType, { ClassOf } from '../codec/createType'; -import Moment from '../primitive/Moment'; +import Moment from './Date'; import U32 from '../primitive/U32'; import Compact from './Compact'; import UInt from './UInt'; diff --git a/packages/types/src/codec/Compact.ts b/packages/types/src/codec/Compact.ts index 1f9578226e..6a58aa67fa 100644 --- a/packages/types/src/codec/Compact.ts +++ b/packages/types/src/codec/Compact.ts @@ -8,14 +8,14 @@ import BN from 'bn.js'; import { bnToBn, compactAddLength, compactFromU8a, compactStripLength, compactToU8a, hexToBn, isBn, isHex, isNumber, isString } from '@polkadot/util'; import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults'; -import Moment from '../primitive/Moment'; import { UIntBitLength } from './AbstractInt'; +import CodecDate from './Date'; import UInt from './UInt'; import Base from './Base'; // List of codec types that are compact-encodable -export const COMPACT_ENCODABLE = [UInt, Moment]; -export type CompactEncodable = UInt | Moment; // FIXME is there a way to do it not-manually from the array? +export const COMPACT_ENCODABLE = [UInt, CodecDate]; +export type CompactEncodable = UInt | CodecDate; // FIXME is there a way to do it not-manually from the array? /** * @name Compact diff --git a/packages/types/src/primitive/Moment.spec.ts b/packages/types/src/codec/Date.spec.ts similarity index 70% rename from packages/types/src/primitive/Moment.spec.ts rename to packages/types/src/codec/Date.spec.ts index b7844df4b6..d618416aaf 100644 --- a/packages/types/src/primitive/Moment.spec.ts +++ b/packages/types/src/codec/Date.spec.ts @@ -5,18 +5,18 @@ import BN from 'bn.js'; import { CodecTo } from '../types'; -import Moment from './Moment'; -import U64 from './U64'; +import CodecDate from './Date'; +import U64 from '../primitive/U64'; -describe('Moment', (): void => { +describe('Date', (): void => { describe('decode', (): void => { - const testDecode = (type: string, input: Date | Moment | U64 | number, expected: string | number, toJSON: boolean = false): void => + const testDecode = (type: string, input: Date | CodecDate | U64 | number, expected: string | number, toJSON: boolean = false): void => it(`can decode from ${type}`, (): void => { - expect(new Moment(input)[toJSON ? 'toJSON' : 'toISOString']()).toBe(expected); + expect(new CodecDate(input)[toJSON ? 'toJSON' : 'toISOString']()).toBe(expected); }); testDecode('Date', new Date(1537968546280), '2018-09-26T13:29:06.280Z'); - testDecode('Moment', new Moment(1234), 1234, true); + testDecode('CodecDate', new CodecDate(1234), 1234, true); testDecode('number', 1234, 1234, true); testDecode('U64', new U64(69), 69, true); }); @@ -24,7 +24,7 @@ describe('Moment', (): void => { describe('encode', (): void => { const testEncode = (to: 'toBn' | 'toISOString' | 'toNumber' | CodecTo, expected: BN | number | string | Uint8Array): void => it(`can encode ${to}`, (): void => { - expect(new Moment(421)[to]()).toEqual(expected); + expect(new CodecDate(421)[to]()).toEqual(expected); }); testEncode('toBn', new BN(421)); @@ -36,7 +36,7 @@ describe('Moment', (): void => { it(`can encode toString`, (): void => { expect( - new Moment(421) + new CodecDate(421) .toString() .startsWith('Thu Jan 01 1970') // The time depends on the timezone this test is run in ).toBe(true); @@ -44,24 +44,24 @@ describe('Moment', (): void => { it('encodes default BE hex', (): void => { expect( - new Moment(3).toHex() + new CodecDate(3).toHex() ).toEqual('0x0000000000000003'); }); it('encodes options LE hex', (): void => { expect( - new Moment(3).toHex(true) + new CodecDate(3).toHex(true) ).toEqual('0x0300000000000000'); }); }); describe('utils', (): void => { it('compares values', (): void => { - expect(new Moment(123).eq(123)).toBe(true); + expect(new CodecDate(123).eq(123)).toBe(true); }); it('compares values (non-match)', (): void => { - expect(new Moment(123).eq(456)).toBe(false); + expect(new CodecDate(123).eq(456)).toBe(false); }); }); }); diff --git a/packages/types/src/primitive/Moment.ts b/packages/types/src/codec/Date.ts similarity index 89% rename from packages/types/src/primitive/Moment.ts rename to packages/types/src/codec/Date.ts index 1efdbd8723..330b06c9f4 100644 --- a/packages/types/src/primitive/Moment.ts +++ b/packages/types/src/codec/Date.ts @@ -8,13 +8,13 @@ import BN from 'bn.js'; import { bnToBn, bnToHex, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util'; import { blake2AsU8a } from '@polkadot/util-crypto'; -import createType from '../codec/createType'; -import { UIntBitLength } from '../codec/AbstractInt'; +import createType from './createType'; +import { UIntBitLength } from './AbstractInt'; const BITLENGTH: UIntBitLength = 64; /** - * @name Moment + * @name Date * @description * A wrapper around seconds/timestamps. Internally the representation only has * second precicion (aligning with Rust), so any numbers passed an/out are always @@ -23,18 +23,18 @@ const BITLENGTH: UIntBitLength = 64; * and has all the methods available that are applicable to any `Date` * @noInheritDoc */ -export default class Moment extends Date implements Codec { +export default class CodecDate extends Date implements Codec { protected raw: Date; // FIXME Remove this once we convert all types out of Base - public constructor (value: Moment | Date | AnyNumber = 0) { + public constructor (value: CodecDate | Date | AnyNumber = 0) { super( - Moment.decodeMoment(value) + CodecDate.decodeDate(value) ); this.raw = this; } - public static decodeMoment (value: Moment | Date | AnyNumber): Date { + public static decodeDate (value: CodecDate | Date | AnyNumber): Date { if (value instanceof Date) { return value; } else if (isU8a(value)) { @@ -73,7 +73,7 @@ export default class Moment extends Date implements Codec { * @description Compares the value of the input to see if there is a match */ public eq (other?: any): boolean { - return Moment.decodeMoment(other).getTime() === this.getTime(); + return CodecDate.decodeDate(other).getTime() === this.getTime(); } /** diff --git a/packages/types/src/codec/createType.spec.ts b/packages/types/src/codec/createType.spec.ts index 2377528b0b..39f24e20f1 100644 --- a/packages/types/src/codec/createType.spec.ts +++ b/packages/types/src/codec/createType.spec.ts @@ -5,8 +5,9 @@ import '../injector'; import { Codec, Constructor } from '../types'; +import { TypeDef, TypeDefInfo } from './types'; -import createType, { TypeDef, TypeDefInfo, createClass, createTypeUnsafe, getTypeClass, getTypeDef, typeSplit, ClassOf } from './createType'; +import createType, { createClass, createTypeUnsafe, getTypeClass, getTypeDef, typeSplit, ClassOf } from './createType'; import CodecSet from './Set'; describe('typeSplit', (): void => { @@ -220,6 +221,13 @@ describe('createClass', (): void => { expect(a).toBe(b); }); + + it('should return equivalents for Bytes & Vec', (): void => { + const a = createClass('Vec'); + const b = createClass('Bytes'); + + expect(a).toBe(b); + }); }); describe('createType', (): void => { diff --git a/packages/types/src/codec/createType.ts b/packages/types/src/codec/createType.ts index 82a1fe6844..1e8734c7ed 100644 --- a/packages/types/src/codec/createType.ts +++ b/packages/types/src/codec/createType.ts @@ -2,11 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { TypeDef, TypeDefInfo, TypeDefExtVecFixed } from './types'; + import memoizee from 'memoizee'; import { assert } from '@polkadot/util'; import { InterfaceRegistry } from '../interfaceRegistry'; import { Codec, Constructor } from '../types'; +import Bytes from '../primitive/Bytes'; import Null from '../primitive/Null'; import Compact from './Compact'; import Enum from './Enum'; @@ -24,36 +27,6 @@ import getRegistry from './typeRegistry'; // Type which says: if `K` is in the InterfaceRegistry, then return InterfaceRegistry[K], else fallback to T type FromReg = K extends keyof InterfaceRegistry ? InterfaceRegistry[K] : T -export enum TypeDefInfo { - Compact, - DoubleMap, - Enum, - Linkage, - Option, - Plain, - Set, - Struct, - Tuple, - Vec, - VecFixed, - // anything not full supported (keep this as the last entry) - Null -} - -export interface TypeDefExtVecFixed { - length: number; - type: string; -} - -export interface TypeDef { - info: TypeDefInfo; - index?: number; - ext?: TypeDefExtVecFixed; // add additional here as required - name?: string; - type: string; - sub?: TypeDef | TypeDef[]; -} - // safely split a string on ', ' while taking care of any nested occurences export function typeSplit (type: string): string[] { let cDepth = 0; // compact/doublemap/linkedmap/option/vector depth @@ -292,8 +265,13 @@ export function getTypeClass (value: TypeDef, Fallback? case TypeDefInfo.Vec: assert(value.sub && !Array.isArray(value.sub), 'Expected subtype for Vec'); - return Vec.with( - getTypeClass(value.sub as TypeDef) + + const vsub = value.sub as TypeDef; + + return ( + vsub.type === 'u8' + ? Bytes + : Vec.with(getTypeClass(vsub)) ) as unknown as Constructor; case TypeDefInfo.VecFixed: diff --git a/packages/types/src/codec/index.ts b/packages/types/src/codec/index.ts index aee904dd80..a0e7da736d 100644 --- a/packages/types/src/codec/index.ts +++ b/packages/types/src/codec/index.ts @@ -9,19 +9,20 @@ // These are the base codec types, generally used for construction export { default as Compact } from './Compact'; +// export { default as Date } from './Date'; export { default as Enum } from './Enum'; export { default as EnumType } from './EnumType'; export { default as Option } from './Option'; export { default as Set } from './Set'; export { default as Struct } from './Struct'; -export { default as StructAny } from './StructAny'; +// export { default as StructAny } from './StructAny'; export { default as Tuple } from './Tuple'; -export { default as Vec, default as Vector } from './Vec'; +export { default as Vec } from './Vec'; // Convenience base classes, used as "anything of this type" bases export { default as U8a } from './U8a'; export { default as UInt } from './UInt'; // Type management helper functions -export { default as createType, createClass, getTypeClass, getTypeDef, ClassOf, TypeDef, TypeDefInfo } from './createType'; +export { default as createType, createClass, getTypeClass, getTypeDef, ClassOf } from './createType'; export { default as getTypeRegistry } from './typeRegistry'; diff --git a/packages/types/src/codec/types.ts b/packages/types/src/codec/types.ts new file mode 100644 index 0000000000..d22c07b845 --- /dev/null +++ b/packages/types/src/codec/types.ts @@ -0,0 +1,33 @@ +// 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 enum TypeDefInfo { + Compact, + DoubleMap, + Enum, + Linkage, + Option, + Plain, + Set, + Struct, + Tuple, + Vec, + VecFixed, + // anything not fully supported (keep this as the last entry) + Null +} + +export interface TypeDefExtVecFixed { + length: number; + type: string; +} + +export interface TypeDef { + info: TypeDefInfo; + index?: number; + ext?: TypeDefExtVecFixed; // add additional here as required + name?: string; + type: string; + sub?: TypeDef | TypeDef[]; +} diff --git a/packages/types/src/index.spec.ts b/packages/types/src/index.spec.ts index 7d69efb460..988edba9a0 100644 --- a/packages/types/src/index.spec.ts +++ b/packages/types/src/index.spec.ts @@ -6,42 +6,60 @@ import './injector'; import extrinsics from '@polkadot/api-metadata/extrinsics/static'; -import { Codec, Constructor } from './types'; -import * as Classes from './index.types'; +import { createTypeUnsafe } from './codec/createType'; +import GenericMethod from './primitive/Generic/Method'; +import { Codec } from './types'; +import * as exported from './index.types'; +import * as definitions from './interfaces/definitions'; -const Types = Classes as Record; -const UNCONSTRUCTABLE = ['genericorigin', 'usize']; +// NOTE This is not a shortcut to implementing types incorrectly. This is here +// specifically for the types that _should_ throw in the constrtuctor, i.e +// `usize` is not allowed (runtime incompat) and `origin` is not passed through +// to any calls. All other types _must_ pass and allow for empty defaults +const UNCONSTRUCTABLE = ['genericorigin', 'origin', 'usize']; -describe('types', (): void => { - describe('default creation', (): void => { - Object.keys(Types).forEach((name): void => { - it(`creates an empty ${name}`, (): void => { - const constructFn = (): Codec => - new Types[name](); +function testTypes (type: string, typeNames: string[]): void { + describe(type, (): void => { + describe(`${type}:: default creation`, (): void => { + typeNames.forEach((name): void => { + it(`creates an empty ${name}`, (): void => { + const constructFn = (): Codec => + createTypeUnsafe(name); - if (UNCONSTRUCTABLE.includes(name.toLowerCase())) { - expect(constructFn).toThrow(); - } else { - expect(constructFn).not.toThrow(); - } + if (UNCONSTRUCTABLE.includes(name.toLowerCase())) { + expect(constructFn).toThrow(); + } else { + expect(constructFn).not.toThrow(); + } + }); + }); + }); + + describe(`${type}:: default creation (empty bytes)`, (): void => { + GenericMethod.injectMethods(extrinsics); + + typeNames.forEach((name): void => { + it(`creates an empty ${name} (from empty bytes)`, (): void => { + const constructFn = (): Codec => + createTypeUnsafe(name, [createTypeUnsafe('Bytes')]); + + if (UNCONSTRUCTABLE.includes(name.toLowerCase())) { + expect(constructFn).toThrow(); + } else { + expect(constructFn).not.toThrow(); + } + }); }); }); }); +} - describe('default creation (empty bytes)', (): void => { - (Types.GenericMethod as any).injectMethods(extrinsics); +describe('type creation', (): void => { + testTypes('exported', Object.keys(exported)); - Object.keys(Types).forEach((name): void => { - it(`creates an empty ${name} (from empty bytes)`, (): void => { - const constructFn = (): Codec => - new Types[name](new Types.Bytes()); - - if (UNCONSTRUCTABLE.includes(name.toLowerCase())) { - expect(constructFn).toThrow(); - } else { - expect(constructFn).not.toThrow(); - } - }); - }); - }); + Object + .entries(definitions) + .forEach(([name, { types }]): void => + testTypes(`${name} (injected)`, Object.keys(types)) + ); }); diff --git a/packages/types/src/interfaceRegistry.ts b/packages/types/src/interfaceRegistry.ts index d853bd1b11..c2aaa7f6ab 100644 --- a/packages/types/src/interfaceRegistry.ts +++ b/packages/types/src/interfaceRegistry.ts @@ -1,8 +1,8 @@ // Auto-generated via `yarn build:interfaces`, do not edit import { Compact, Option, Vec } from './codec'; -import { Bytes, Data, Fixed64, H160, H256, H512, Moment, Null, StorageHasher, StorageKey, Text, Type, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from './primitive'; -import { AccountId, AccountIdOf, AccountIndex, Address, Balance, BalanceOf, Block, BlockNumber, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Method, MortalEra, Origin, Perbill, Permill, Phantom, PreRuntime, Seal, SealV0, Signature, SignedBlock, Sr25519Signature, StorageData, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime'; +import { Bytes, Data, Fixed64, H160, H256, H512, Null, StorageHasher, StorageKey, Text, Type, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from './primitive'; +import { AccountId, AccountIdOf, AccountIndex, Address, Balance, BalanceOf, Block, BlockNumber, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Method, Moment, MortalEra, Origin, Perbill, Permill, Phantom, PreRuntime, Seal, SealV0, Signature, SignedBlock, Sr25519Signature, StorageData, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime'; import { AuthorityId } from './interfaces/consensus'; import { Keys, SessionIndex } from './interfaces/session'; import { AuthorityWeight, NextAuthority, PendingPause, PendingResume, StoredPendingChange, StoredState } from './interfaces/grandpa'; @@ -61,10 +61,6 @@ export interface InterfaceRegistry { i256: i256; 'Option': Option; 'Vec': Vec; - Moment: Moment; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vec; Null: Null; 'Option': Option; 'Vec': Vec; @@ -132,6 +128,51 @@ export interface InterfaceRegistry { 'Compact': Compact; 'Option': Option; 'Vec': Vec; + Hash: Hash; + 'Option': Option; + 'Vec': Vec; + Index: Index; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; + KeyTypeId: KeyTypeId; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; + LockIdentifier: LockIdentifier; + 'Option': Option; + 'Vec': Vec; + Moment: Moment; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; + Perbill: Perbill; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; + Permill: Permill; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; + Phantom: Phantom; + 'Option': Option; + 'Vec': Vec; + ValidatorId: ValidatorId; + 'Option': Option; + 'Vec': Vec; + Weight: Weight; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; + WeightMultiplier: WeightMultiplier; + 'Option': Option; + 'Vec': Vec; + StorageData: StorageData; + 'Option': Option; + 'Vec': Vec; + KeyValue: KeyValue; + 'Option': Option; + 'Vec': Vec; Signature: Signature; 'Option': Option; 'Vec': Vec; @@ -141,6 +182,27 @@ export interface InterfaceRegistry { Sr25519Signature: Sr25519Signature; 'Option': Option; 'Vec': Vec; + Method: Method; + 'Option': Option; + 'Vec': Vec; + Origin: Origin; + 'Option': Option; + 'Vec': Vec; + ImmortalEra: ImmortalEra; + 'Option': Option; + 'Vec': Vec; + MortalEra: MortalEra; + 'Option': Option; + 'Vec': Vec; + ExtrinsicEra: ExtrinsicEra; + 'Option': Option; + 'Vec': Vec; + ExtrinsicPayload: ExtrinsicPayload; + 'Option': Option; + 'Vec': Vec; + Extrinsic: Extrinsic; + 'Option': Option; + 'Vec': Vec; ConsensusEngineId: ConsensusEngineId; 'Compact': Compact; 'Option': Option; @@ -163,9 +225,6 @@ export interface InterfaceRegistry { Digest: Digest; 'Option': Option; 'Vec': Vec; - Hash: Hash; - 'Option': Option; - 'Vec': Vec; Header: Header; 'Option
': Option
; 'Vec
': Vec
; @@ -178,65 +237,6 @@ export interface InterfaceRegistry { SignedBlock: SignedBlock; 'Option': Option; 'Vec': Vec; - KeyTypeId: KeyTypeId; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vec; - LockIdentifier: LockIdentifier; - 'Option': Option; - 'Vec': Vec; - Index: Index; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vec; - Perbill: Perbill; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vec; - Permill: Permill; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vec; - Phantom: Phantom; - 'Option': Option; - 'Vec': Vec; - StorageData: StorageData; - 'Option': Option; - 'Vec': Vec; - KeyValue: KeyValue; - 'Option': Option; - 'Vec': Vec; - ValidatorId: ValidatorId; - 'Option': Option; - 'Vec': Vec; - Weight: Weight; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vec; - WeightMultiplier: WeightMultiplier; - 'Option': Option; - 'Vec': Vec; - Method: Method; - 'Option': Option; - 'Vec': Vec; - Origin: Origin; - 'Option': Option; - 'Vec': Vec; - ImmortalEra: ImmortalEra; - 'Option': Option; - 'Vec': Vec; - MortalEra: MortalEra; - 'Option': Option; - 'Vec': Vec; - ExtrinsicEra: ExtrinsicEra; - 'Option': Option; - 'Vec': Vec; - ExtrinsicPayload: ExtrinsicPayload; - 'Option': Option; - 'Vec': Vec; - Extrinsic: Extrinsic; - 'Option': Option; - 'Vec': Vec; AuthorityId: AuthorityId; 'Option': Option; 'Vec': Vec; @@ -501,7 +501,6 @@ export interface InterfaceRegistry { 'Option': Option; 'Vec': Vec; MomentOf: MomentOf; - 'Compact': Compact; 'Option': Option; 'Vec': Vec; RewardDestination: RewardDestination; diff --git a/packages/types/src/interfaces/runtime/definitions.ts b/packages/types/src/interfaces/runtime/definitions.ts index 4878393897..ddad50ccda 100644 --- a/packages/types/src/interfaces/runtime/definitions.ts +++ b/packages/types/src/interfaces/runtime/definitions.ts @@ -11,12 +11,37 @@ export default { Balance: 'u128', BalanceOf: 'Balance', BlockNumber: 'u64', + Hash: 'H256', + Index: 'u64', + KeyTypeId: 'u32', + LockIdentifier: '[u8; 8]', + Moment: 'u64', + Perbill: 'u32', + Permill: 'u32', + Phantom: 'Null', + ValidatorId: 'AccountId', + Weight: 'u32', + WeightMultiplier: 'Fixed64', - // block - // :: signature + // storage helpers + StorageData: 'Bytes', + KeyValue: '(StorageKey, StorageData)', + + // signatures (used in block & extrinsics) Signature: 'H512', Ed25519Signature: 'Signature', Sr25519Signature: 'Signature', + + // extrinsic definition + Method: 'GenericMethod', + Origin: 'GenericOrigin', + ImmortalEra: 'GenericImmortalEra', + MortalEra: 'GenericMortalEra', + ExtrinsicEra: 'GenericExtrinsicEra', + ExtrinsicPayload: 'GenericExtrinsicPayload', + Extrinsic: 'GenericExtrinsic', + + // block definition // :: digest ConsensusEngineId: 'GenericConsensusEngineId', PreRuntime: '(ConsensusEngineId, Bytes)', @@ -25,7 +50,6 @@ export default { Consensus: '(ConsensusEngineId, Bytes)', DigestItem: 'GenericDigestItem', Digest: 'GenericDigest', - Hash: 'H256', // :: parts Header: { parentHash: 'Hash', @@ -40,27 +64,6 @@ export default { SignedBlock: { block: 'Block', justification: 'Justification' - }, - - KeyTypeId: 'u32', - LockIdentifier: '[u8; 8]', - Index: 'u64', - Perbill: 'u32', - Permill: 'u32', - Phantom: 'Null', - StorageData: 'Bytes', - KeyValue: '(StorageKey, StorageData)', - ValidatorId: 'AccountId', - Weight: 'u32', - WeightMultiplier: 'Fixed64', - - // extrinsics - Method: 'GenericMethod', - Origin: 'GenericOrigin', - ImmortalEra: 'GenericImmortalEra', - MortalEra: 'GenericMortalEra', - ExtrinsicEra: 'GenericExtrinsicEra', - ExtrinsicPayload: 'GenericExtrinsicPayload', - Extrinsic: 'GenericExtrinsic' + } } }; diff --git a/packages/types/src/interfaces/runtime/types.ts b/packages/types/src/interfaces/runtime/types.ts index 2bc21fa0a5..883e2837ac 100644 --- a/packages/types/src/interfaces/runtime/types.ts +++ b/packages/types/src/interfaces/runtime/types.ts @@ -90,6 +90,9 @@ export type LockIdentifier = Vec; /** GenericMethod */ export type Method = GenericMethod; +/** u64 */ +export type Moment = u64; + /** GenericMortalEra */ export type MortalEra = GenericMortalEra; diff --git a/packages/types/src/interfaces/staking/types.ts b/packages/types/src/interfaces/staking/types.ts index 26f193a3fe..f1511a7268 100644 --- a/packages/types/src/interfaces/staking/types.ts +++ b/packages/types/src/interfaces/staking/types.ts @@ -1,8 +1,8 @@ // Auto-generated via `yarn build:interfaces`, do not edit import { Compact, Enum, Struct, Vec } from '../../codec'; -import { Moment, u32 } from '../../primitive'; -import { AccountId, Balance, BlockNumber } from '../runtime'; +import { u32 } from '../../primitive'; +import { AccountId, Balance, BlockNumber, Moment } from '../runtime'; /** u32 */ export type EraIndex = u32; diff --git a/packages/types/src/primitive/Generic/Event.ts b/packages/types/src/primitive/Generic/Event.ts index 8446031cf9..d1dd984522 100644 --- a/packages/types/src/primitive/Generic/Event.ts +++ b/packages/types/src/primitive/Generic/Event.ts @@ -2,12 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { TypeDef } from '../../codec/types'; import { EventId } from '../../interfaces/system'; import { Constructor, Codec } from '../../types'; import { assert, isUndefined, stringCamelCase, u8aToHex } from '@polkadot/util'; -import { ClassOf, TypeDef, getTypeClass, getTypeDef } from '../../codec/createType'; +import { ClassOf, getTypeClass, getTypeDef } from '../../codec/createType'; import Struct from '../../codec/Struct'; import Tuple from '../../codec/Tuple'; import Metadata from '../../Metadata'; diff --git a/packages/types/src/primitive/index.ts b/packages/types/src/primitive/index.ts index 362b19d167..0fe1265909 100644 --- a/packages/types/src/primitive/index.ts +++ b/packages/types/src/primitive/index.ts @@ -25,7 +25,6 @@ export { default as i64 } from './I64'; export { default as Fixed64 } from './I64Fixed'; export { default as i128 } from './I128'; export { default as i256 } from './I256'; -export { default as Moment } from './Moment'; export { default as Null } from './Null'; export { default as StorageHasher } from './StorageHasher'; export { default as StorageKey } from './StorageKey'; diff --git a/packages/types/src/scripts/interfacesTs.ts b/packages/types/src/scripts/interfacesTs.ts index 1737ba3fca..9dbc2c5ba3 100644 --- a/packages/types/src/scripts/interfacesTs.ts +++ b/packages/types/src/scripts/interfacesTs.ts @@ -2,10 +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 { TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '../codec/types'; + import fs from 'fs'; import { isString, stringCamelCase, stringUpperFirst } from '@polkadot/util'; -import { getTypeDef, TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '../codec/createType'; +import { getTypeDef } from '../codec/createType'; import * as codecClasses from '../codec'; import { COMPACT_ENCODABLE } from '../codec/Compact'; import * as primitiveClasses from '../primitive'; diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts index 5d8d9aea49..5ebf1ff5f2 100644 --- a/packages/types/src/types.ts +++ b/packages/types/src/types.ts @@ -12,6 +12,8 @@ import { FunctionMetadata } from './Metadata/v7/Calls'; import Method from './primitive/Generic/Method'; import Address from './primitive/Generic/Address'; +export * from './codec/types'; + // eslint-disable-next-line @typescript-eslint/interface-name-prefix export interface IKeyringPair { address: string;