Skip to content

Commit

Permalink
feat(balances): add JSON flag (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev authored Sep 26, 2023
1 parent 54ed4cb commit bb3884a
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 bb3884a

Please sign in to comment.