Skip to content

Commit

Permalink
Colorize Storage list
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalin committed Nov 22, 2024
1 parent 059c731 commit 1936f4f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/tools/list-storages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import yargs from "yargs";
import chalk from "chalk";

import { getApiFor, NETWORK_YARGS_OPTIONS } from "../utils/networks.ts";
import { xxhashAsHex } from "@polkadot/util-crypto";

const argv = yargs(process.argv.slice(2))
.usage("Usage: $0")
Expand All @@ -9,15 +11,26 @@ const argv = yargs(process.argv.slice(2))
...NETWORK_YARGS_OPTIONS,
}).argv;

const capitalize = (s) => {
return String(s[0]).toUpperCase() + String(s).slice(1);
}
const main = async () => {
const api = await getApiFor(argv);

for (const section of Object.keys(api.query)) {
console.log(`${section}`);
const palletName = section == "evm" ? "EVM" : capitalize(section);
const sectionKey = xxhashAsHex(palletName, 128);
console.log(`${chalk.yellow(palletName)}`);
for (const method of Object.keys(api.query[section])) {
console.log(
` ${`${section}.${method}`.padStart(50, " ")}: ${api.query[section][method].keyPrefix()}`,
);
if (api.query[section][method].keyPrefix().includes(sectionKey.slice(2))) {
console.log(
` ${`${section}.${method}`.padStart(50, " ")}: ${chalk.yellow(sectionKey)}${api.query[section][method].keyPrefix().slice(34)}`,
);
} else {
console.log(
` ${`${section}.${method}`.padStart(50, " ")}: ${api.query[section][method].keyPrefix()}`,
);
}
}
}
await api.disconnect();
Expand Down

0 comments on commit 1936f4f

Please sign in to comment.