Skip to content

Commit

Permalink
add initia registry to codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki committed Mar 28, 2024
1 parent 03fc289 commit 5521012
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "chain-registry"]
path = chain-registry
url = https://github.com/cosmos/chain-registry.git
[submodule "initia-registry"]
path = initia-registry
url = https://github.com/initia-labs/initia-registry
1 change: 1 addition & 0 deletions initia-registry
Submodule initia-registry added at 188125
12 changes: 11 additions & 1 deletion src/ast/get-chains-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ interface Args {
export async function getChainsPaths({ registryPath }: Args) {
const mainnetGlobs = ["*", "!_*", "!testnets"];
const testnetGlobs = ["testnets/*", "!testnets/_*"];

const paths = await globby([...mainnetGlobs, ...testnetGlobs], {
cwd: registryPath,
onlyDirectories: true,
});

return paths;
}

export async function getInitiaChainsPaths({ registryPath }: Args) {
const devnetGlobs = ["devnets/*", "!devnets/_*"];

const initiaPaths = await globby([...devnetGlobs], {
cwd: registryPath,
onlyDirectories: true,
});

return initiaPaths;
}
18 changes: 13 additions & 5 deletions src/ast/parse-chain-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ import { parseChainJson } from "./parse-chain-json";
interface Args {
registryPath: string;
chainPaths: string[];
initiaRegistryPath: string;
initiaChainPaths: string[];
}

export async function parseChainPaths({ registryPath, chainPaths }: Args): Promise<Variables> {
export async function parseChainPaths({
registryPath,
chainPaths,
initiaChainPaths,
initiaRegistryPath,
}: Args): Promise<Variables> {
const chains: Chain[] = [];
const assetlists: AssetList[] = [];

Expand All @@ -27,10 +34,10 @@ export async function parseChainPaths({ registryPath, chainPaths }: Args): Promi
const explorersRecord: Record<string, Explorer[]> = {};
const chainInfosRecord: Record<string, ChainInfo> = {};

async function loadChainPath(chainPath: string) {
async function loadChainPath(_registryPath: string, chainPath: string) {
const [assetlist, chain] = await Promise.all([
parseAssetListJson({ registryPath, chainPath }),
parseChainJson({ registryPath, chainPath }),
parseAssetListJson({ registryPath: _registryPath, chainPath }),
parseChainJson({ registryPath: _registryPath, chainPath }),
]);

chains.push(chain);
Expand All @@ -54,7 +61,8 @@ export async function parseChainPaths({ registryPath, chainPaths }: Args): Promi
});
}

await pMap(chainPaths, loadChainPath, { concurrency });
await pMap(chainPaths, (i) => loadChainPath(registryPath, i), { concurrency });
await pMap(initiaChainPaths, (i) => loadChainPath(initiaRegistryPath, i), { concurrency });

return {
chains,
Expand Down
14 changes: 13 additions & 1 deletion src/scripts/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import * as path from "path";

import { getChainsPaths } from "@/ast/get-chains-paths";
import { getChainsPaths, getInitiaChainsPaths } from "@/ast/get-chains-paths";
import { parseChainPaths } from "@/ast/parse-chain-paths";
import { validateChainsPaths } from "@/ast/validate-chains-paths";
import { writeEntrypoints } from "@/ast/write-entrypoints";

async function codegen() {
const registryPath = path.resolve("chain-registry");
const initiaRegistryPath = path.resolve("initia-registry");

const chainPaths = await getChainsPaths({
registryPath,
});

const initiaChainPaths = await getInitiaChainsPaths({
registryPath: initiaRegistryPath,
});

const validChainPaths = await validateChainsPaths({
registryPath,
chainPaths,
});

const initiaValidChainPaths = await validateChainsPaths({
registryPath: initiaRegistryPath,
chainPaths: initiaChainPaths,
});

const variables = await parseChainPaths({
registryPath,
chainPaths: validChainPaths,
initiaChainPaths: initiaValidChainPaths,
initiaRegistryPath,
});

await writeEntrypoints({
Expand Down

0 comments on commit 5521012

Please sign in to comment.