Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(balances): add JSON flag #44

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Loading