-
Notifications
You must be signed in to change notification settings - Fork 17
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 #60 from skip-mev/griko/spe-283-add-a-tx-history-a…
…nd-pending-tab-to-ibcfun [SPE-283] feat: add tx history interface
- Loading branch information
Showing
41 changed files
with
3,345 additions
and
1,399 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "chain-registry"] | ||
path = chain-registry | ||
url = https://github.com/cosmos/chain-registry.git |
Submodule chain-registry
added at
5a391c
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,3 @@ | ||
import * as os from "os"; | ||
|
||
export const concurrency = Math.max(1, (os.cpus() || { length: 1 }).length - 1); |
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,15 @@ | ||
import { Asset, AssetList, Chain } from "@graz-sh/types"; | ||
|
||
export interface Variables { | ||
assetlists: AssetList[]; | ||
chains: Chain[]; | ||
|
||
chainIds: string[]; | ||
chainNames: string[]; | ||
|
||
chainIdToName: Record<string, string>; | ||
chainNameToId: Record<string, string>; | ||
|
||
chainRecord: Record<string, Chain>; | ||
assetsRecord: Record<string, Asset[]>; | ||
} |
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,17 @@ | ||
import { globby } from "globby"; | ||
|
||
interface Args { | ||
registryPath: string; | ||
} | ||
|
||
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; | ||
} |
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,26 @@ | ||
import { AssetList } from "@graz-sh/types"; | ||
import { assetListSchema } from "@graz-sh/types/zod"; | ||
import * as fs from "fs/promises"; | ||
import * as path from "path"; | ||
|
||
interface Args { | ||
registryPath: string; | ||
chainPath: string; | ||
} | ||
|
||
export async function parseAssetListJson({ registryPath, chainPath }: Args) { | ||
const jsonPath = path.resolve(registryPath, chainPath, "assetlist.json"); | ||
|
||
let data: AssetList; | ||
try { | ||
const content = await fs.readFile(jsonPath, "utf-8"); | ||
data = await assetListSchema.parseAsync(JSON.parse(content)); | ||
} catch (error) { | ||
data = { | ||
chain_name: chainPath, | ||
assets: [], | ||
}; | ||
} | ||
|
||
return data; | ||
} |
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,18 @@ | ||
import { Chain } from "@graz-sh/types"; | ||
import { chainSchema } from "@graz-sh/types/zod"; | ||
import * as fs from "fs/promises"; | ||
import * as path from "path"; | ||
|
||
interface Args { | ||
registryPath: string; | ||
chainPath: string; | ||
} | ||
|
||
export async function parseChainJson({ registryPath, chainPath }: Args) { | ||
const jsonPath = path.resolve(registryPath, chainPath, "chain.json"); | ||
|
||
const content = await fs.readFile(jsonPath, "utf-8"); | ||
const data: Chain = await chainSchema.parseAsync(JSON.parse(content)); | ||
|
||
return data; | ||
} |
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,63 @@ | ||
import { Asset, AssetList, Chain } from "@graz-sh/types"; | ||
import pMap from "p-map"; | ||
|
||
import { concurrency } from "./_constants"; | ||
import { Variables } from "./_types"; | ||
import { parseAssetListJson } from "./parse-asset-list-json"; | ||
import { parseChainJson } from "./parse-chain-json"; | ||
|
||
interface Args { | ||
registryPath: string; | ||
chainPaths: string[]; | ||
} | ||
|
||
export async function parseChainPaths({ | ||
registryPath, | ||
chainPaths, | ||
}: Args): Promise<Variables> { | ||
const chains: Chain[] = []; | ||
const assetlists: AssetList[] = []; | ||
|
||
const chainIds: string[] = []; | ||
const chainNames: string[] = []; | ||
|
||
const chainIdToName: Record<string, string> = {}; | ||
const chainNameToId: Record<string, string> = {}; | ||
const chainRecord: Record<string, Chain> = {}; | ||
const assetsRecord: Record<string, Asset[]> = {}; | ||
|
||
async function loadChainPath(chainPath: string) { | ||
const [assetlist, chain] = await Promise.all([ | ||
parseAssetListJson({ registryPath, chainPath }), | ||
parseChainJson({ registryPath, chainPath }), | ||
]); | ||
|
||
chains.push(chain); | ||
assetlists.push(assetlist); | ||
|
||
chainIds.push(chain.chain_id); | ||
chainNames.push(chain.chain_name); | ||
|
||
chainIdToName[chain.chain_id] = chain.chain_name; | ||
chainIdToName[chain.chain_name] = chain.chain_name; | ||
|
||
chainNameToId[chain.chain_name] = chain.chain_id; | ||
chainNameToId[chain.chain_id] = chain.chain_id; | ||
|
||
chainRecord[chain.chain_id] = chain; | ||
assetsRecord[chain.chain_id] = assetlist.assets; | ||
} | ||
|
||
await pMap(chainPaths, loadChainPath, { concurrency }); | ||
|
||
return { | ||
chains, | ||
assetlists, | ||
chainIds, | ||
chainNames, | ||
chainIdToName, | ||
chainNameToId, | ||
chainRecord, | ||
assetsRecord, | ||
}; | ||
} |
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,31 @@ | ||
import * as fs from "fs/promises"; | ||
import pMap, { pMapSkip } from "p-map"; | ||
import * as path from "path"; | ||
|
||
import { concurrency } from "./_constants"; | ||
|
||
interface Args { | ||
registryPath: string; | ||
chainPaths: string[]; | ||
} | ||
|
||
export async function validateChainsPaths({ registryPath, chainPaths }: Args) { | ||
const filesToCheck = ["chain.json"]; | ||
|
||
const checkFiles = async (chainPath: string) => { | ||
try { | ||
await Promise.all( | ||
filesToCheck.map((file) => { | ||
return fs.lstat(path.resolve(registryPath, chainPath, file)); | ||
}), | ||
); | ||
return chainPath; | ||
} catch (error) { | ||
return pMapSkip; | ||
} | ||
}; | ||
|
||
const validChainPaths = await pMap(chainPaths, checkFiles, { concurrency }); | ||
|
||
return validChainPaths; | ||
} |
Oops, something went wrong.