-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import Entropy from "@entropyxyz/sdk" | ||
import { EntropyBase } from "../common/entropy-base" | ||
import * as BalanceUtils from "./utils" | ||
import Entropy from "@entropyxyz/sdk"; | ||
import { Command } from "commander"; | ||
import { cliWrite, endpointOption, passwordOption } from "src/common/utils-cli"; | ||
import { EntropyBalance } from "./main"; | ||
|
||
const FLOW_CONTEXT = 'ENTROPY-BALANCE' | ||
export class BalanceCommand extends EntropyBase { | ||
constructor (entropy: Entropy, endpoint: string) { | ||
super(entropy, endpoint, FLOW_CONTEXT) | ||
} | ||
export async function entropyBalanceCommand (entropy: Entropy, rootCommand: Command) { | ||
const programCommand = rootCommand.command('balance') | ||
.description('Commands to retrieive account balances on the Entropy Network') | ||
entropyAccountBalance(entropy, programCommand) | ||
} | ||
|
||
public async getBalance (address: string) { | ||
const balance = await BalanceUtils.getBalance(this.entropy, address) | ||
|
||
this.logger.log(`Current balance of ${address}: ${balance}`, `${BalanceCommand.name}`) | ||
|
||
return `${balance.toLocaleString('en-US')} BITS` | ||
} | ||
async function entropyAccountBalance (entropy: Entropy, programCommand: Command) { | ||
programCommand | ||
.argument('address', 'Account address whose balance you want to query') | ||
.addOption(passwordOption()) | ||
.addOption(endpointOption()) | ||
.action(async (address, opts) => { | ||
const balanceCommand = new EntropyBalance(entropy, opts.endpoint) | ||
const balance = await balanceCommand.getBalance(address) | ||
cliWrite(balance) | ||
process.exit(0) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { print } from "src/common/utils" | ||
import { EntropyBalance } from "./main" | ||
|
||
export async function entropyBalance (entropy, endpoint, storedConfig) { | ||
try { | ||
const entropyBalance = new EntropyBalance(entropy, endpoint) | ||
const balanceString = await entropyBalance.getBalance(storedConfig.selectedAccount) | ||
print(`Address ${storedConfig.selectedAccount} has a balance of: ${balanceString}`) | ||
} catch (error) { | ||
console.error('There was an error retrieving balance', error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Entropy from "@entropyxyz/sdk" | ||
import { EntropyBase } from "../common/entropy-base" | ||
import * as BalanceUtils from "./utils" | ||
|
||
const FLOW_CONTEXT = 'ENTROPY-BALANCE' | ||
export class EntropyBalance extends EntropyBase { | ||
constructor (entropy: Entropy, endpoint: string) { | ||
super(entropy, endpoint, FLOW_CONTEXT) | ||
} | ||
|
||
public async getBalance (address: string) { | ||
const balance = await BalanceUtils.getBalance(this.entropy, address) | ||
|
||
this.logger.log(`Current balance of ${address}: ${balance}`, EntropyBalance.name) | ||
|
||
return `${balance.toLocaleString('en-US')} BITS` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters