Skip to content

Commit

Permalink
feat(balances): add JSON flag
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Aug 28, 2023
1 parent 185d248 commit 8cf88b3
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tasks/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ const fetchZRC20Balance = async (address: string) => {
};

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const spinner = ora("Fetching balances...").start();
const spinner = ora("Fetching balances...");
if (!args.json) {
spinner.start();
}
const { ethers, config } = hre as any;
const pk = process.env.PRIVATE_KEY;
let address: string;
Expand All @@ -139,15 +142,21 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const balances = await Promise.all(balancePromises);
balances.push(await fetchBitcoinBalance(btc_address));
const filteredBalances = balances.filter((balance) => balance != null);
spinner.stop();
console.log(`
if (args.json) {
console.log(JSON.stringify(filteredBalances, null, 2));
} else {
spinner.stop();
console.log(`
EVM: ${address} ${btc_address ? `\nBitcoin: ${btc_address}` : ""}
`);
console.table(filteredBalances);
`);
console.table(filteredBalances);
}
};

export const balancesTask = task(
"balances",
`Fetch native and ZETA token balances`,
main
).addOptionalParam("address", `Fetch balances for a specific address`);
)
.addOptionalParam("address", `Fetch balances for a specific address`)
.addFlag("json", "Output balances as JSON");

0 comments on commit 8cf88b3

Please sign in to comment.