From bb3884a8b3b8a9c63a344463ed054ad557c8e585 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Tue, 26 Sep 2023 20:05:33 +0400 Subject: [PATCH] feat(balances): add JSON flag (#44) --- tasks/balances.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tasks/balances.ts b/tasks/balances.ts index 2a14e6b3..4c492207 100644 --- a/tasks/balances.ts +++ b/tasks/balances.ts @@ -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; @@ -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");