Skip to content

Commit

Permalink
add readme and method to export json (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelamouche authored Sep 22, 2021
1 parent 662241f commit 83b3540
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions moonbeam-types-bundle/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# ignore files generated by typescript
dist/
**.json
30 changes: 30 additions & 0 deletions moonbeam-types-bundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Moonbeam Types Bundle

Exports npm package `moonbeam-types-bundle`, formated as per polkadot-js specification to use
with the app or the api.

## Exports

```
export const typesBundle = {
spec: {
moonbeam: moonbeamDefinitions,
moonbeamDefinitions,
moonbase: moonbeamDefinitions,
moonriver: moonbeamDefinitions,
},
} as OverrideBundleType;
```

`typesBundle` is of type OverrideBundleType to associate runtime names with correct definitions

`moonbeamDefinitions` is of types OverrideBundleDefinition and returns a different set of type for
each runtime version.

## Print Types

To print and save types JSON for a specific version run:
`ts-node generateJSON.ts <verison number>`

To print and save the latest:
`ts-node generateJSON.ts latest`
31 changes: 31 additions & 0 deletions moonbeam-types-bundle/generateJSON.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { RegistryTypes } from "@polkadot/types/types";
import fs from "fs";
import { moonbeamDefinitions } from ".";

async function generateJSON() {
const version = process.argv[2] || "latest";
let types: RegistryTypes;
if (!moonbeamDefinitions.types) {
throw new Error("missing types definitions");
} else if (version === "latest") {
types = moonbeamDefinitions.types[moonbeamDefinitions.types.length - 1].types;
} else if (Number(version)) {
let i = 0;
while (
i < moonbeamDefinitions.types.length &&
moonbeamDefinitions.types[i].minmax[1] &&
Number(moonbeamDefinitions.types[i].minmax[1]) < Number(version)
) {
i += 1;
}
types = moonbeamDefinitions.types[i].types;
} else {
throw new Error("parameter must be number or `latest`");
}
console.log(JSON.stringify(types));
fs.appendFile("moonbeam-types-" + version + ".json", JSON.stringify(types), function (err) {
if (err) throw err;
console.log("Saved for version : " + version);
});
}
generateJSON();
2 changes: 1 addition & 1 deletion moonbeam-types-bundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export const moonbeamDefinitions = {
types: TYPES_155_199,
},
{
minmax: [199, 400],
minmax: [200, 399],
types: TYPES_200_399,
},
{
Expand Down

0 comments on commit 83b3540

Please sign in to comment.