-
Notifications
You must be signed in to change notification settings - Fork 377
Latest metadata for substrate 2.x #1151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
21513e3
Latest metadata for substrate 2.x
jacogr 9680b3d
Save json...
jacogr fd3ac47
Latest types
jacogr 94fd10d
typo in name
jacogr e7bd8e8
typo in name
jacogr 7661942
Export all types from the seperate modules
jacogr 4a80d88
Merge branch 'jg-metadata-bump' of github.com:polkadot-js/api into jg…
jacogr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make is slightly more clever - it can now import from |
||
| 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,14 +68,16 @@ 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]; | ||
|
|
||
| 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' }); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to create some issues down the line as soon as Babe comes online. Babe also has weights, defined as
u64, but the above isu32