-
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.
Merge branch 'naynay/file-restructure' of github.com:entropyxyz/cli i…
…nto mixmix/deploy_cli
- Loading branch information
Showing
22 changed files
with
276 additions
and
223 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
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 { BaseCommand } from "../common/base-command" | ||
import * as BalanceUtils from "./utils" | ||
|
||
const FLOW_CONTEXT = 'ENTROPY-BALANCE' | ||
export class BalanceCommand extends BaseCommand { | ||
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}`, `${BalanceCommand.name}`) | ||
|
||
return `${balance.toLocaleString('en-US')} BITS` | ||
} | ||
} |
File renamed without changes.
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,24 @@ | ||
import Entropy from "@entropyxyz/sdk"; | ||
import { BalanceInfo } from "./types"; | ||
|
||
const hexToBigInt = (hexString: string) => BigInt(hexString) | ||
|
||
export async function getBalance (entropy: Entropy, address: string): Promise<number> { | ||
const accountInfo = (await entropy.substrate.query.system.account(address)) as any | ||
return parseInt(hexToBigInt(accountInfo.data.free).toString()) | ||
} | ||
|
||
export async function getBalances (entropy: Entropy, addresses: string[]): Promise<BalanceInfo> { | ||
const balanceInfo: BalanceInfo = {} | ||
await Promise.all(addresses.map(async address => { | ||
try { | ||
const balance = await getBalance(entropy, address) | ||
|
||
balanceInfo[address] = { balance } | ||
} catch (error) { | ||
balanceInfo[address] = { error: error.message } | ||
} | ||
})) | ||
|
||
return balanceInfo | ||
} |
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
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 Entropy from "@entropyxyz/sdk"; | ||
import { EntropyLogger } from "./logger"; | ||
|
||
export abstract class BaseCommand { | ||
protected logger: EntropyLogger | ||
protected entropy: Entropy | ||
|
||
constructor (entropy: Entropy, endpoint: string, flowContext: string) { | ||
this.logger = new EntropyLogger(flowContext, endpoint) | ||
this.entropy = entropy | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.