generated from PolymeshAssociation/typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from PolymathNetwork/feat/MSDK-79-use-original…
…-polkadot Use native polkadot typegen
- Loading branch information
Showing
48 changed files
with
10,211 additions
and
1,626 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,29 @@ | ||
/* eslint-disable */ | ||
const https = require('https'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const rimraf = require('rimraf'); | ||
const util = require('util'); | ||
|
||
const dirName = path.resolve('src', 'polkadot', 'polymesh'); | ||
rimraf.sync(dirName); | ||
fs.mkdirSync(dirName); | ||
|
||
https.get('https://pme.polymath.network/code/polymesh_schema.json', res => { | ||
const chunks = []; | ||
res.on('data', chunk => { | ||
chunks.push(chunk); | ||
}); | ||
|
||
res.on('end', () => { | ||
const schema = Buffer.concat(chunks).toString(); | ||
const content = JSON.parse(`{ "types": ${schema} }`); | ||
fs.writeFileSync( | ||
path.resolve(dirName, 'definitions.ts'), | ||
`/* eslint-disable @typescript-eslint/camelcase */\nexport default ${util.inspect(content, { | ||
compact: false, | ||
depth: null, | ||
})}` | ||
); | ||
}); | ||
}); |
This file contains 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,54 @@ | ||
/* eslint-disable */ | ||
const Metadata = require('@polkadot/metadata/Metadata').default; | ||
const { w3cwebsocket } = require('websocket'); | ||
const { TypeRegistry } = require('@polkadot/types/create'); | ||
const { stringCamelCase, stringLowerFirst, stringUpperFirst } = require('@polkadot/util'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const websocket = new w3cwebsocket('wss://pme.polymath.network'); | ||
websocket.onopen = () => { | ||
websocket.send('{"id":"1","jsonrpc":"2.0","method":"state_getMetadata","params":[]}'); | ||
}; | ||
websocket.onmessage = message => { | ||
let namespaces = ''; | ||
let txTag = 'export type TxTag ='; | ||
let txTags = 'export const TxTags = {\n'; | ||
|
||
const registry = new TypeRegistry(); | ||
|
||
const metadata = new Metadata(registry, JSON.parse(message.data).result); | ||
const modules = metadata.asLatest.modules; | ||
|
||
modules.forEach(({ name, calls }, index) => { | ||
const allCalls = calls.unwrapOr(null); | ||
const moduleName = name.toString(); | ||
|
||
if (allCalls && allCalls.length) { | ||
const moduleNameCamelCase = stringCamelCase(moduleName); | ||
const moduleNamePascal = stringUpperFirst(moduleNameCamelCase); | ||
txTag = txTag.concat(`\n | ${moduleNamePascal}Tx`); | ||
txTags = txTags.concat(` ${stringLowerFirst(moduleName)}: ${moduleNamePascal}Tx,\n`); | ||
|
||
namespaces = namespaces.concat(`export enum ${moduleNamePascal}Tx {\n`); | ||
allCalls.forEach(({ name }) => { | ||
const nameCamelCase = stringCamelCase(name.toString()); | ||
const namePascal = stringUpperFirst(nameCamelCase); | ||
namespaces = namespaces.concat( | ||
` ${namePascal} = '${moduleNameCamelCase}.${nameCamelCase}',\n` | ||
); | ||
}); | ||
namespaces = namespaces.concat('}\n\n'); | ||
} | ||
}); | ||
|
||
txTag = txTag.concat(';'); | ||
txTags = txTags.concat('};'); | ||
|
||
fs.appendFileSync( | ||
path.resolve('src', 'polkadot', 'types.ts'), | ||
'\n'.concat(namespaces).concat(`${txTag}\n\n${txTags}\n`) | ||
); | ||
|
||
websocket.close(); | ||
}; |
This file contains 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.