-
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.
[NayNay] File Restructure: Signing Restructure (#218)
* [NayNay] File Restructure: Signing Restructure - created new file structure for signing flow - updated tui/cli with new changes * some cleanup; fixed sign tests * removed inquirer input from commands file, added file inoput back to signing * added raw sign back in * wip: raw sign stuff * wip: finished off last changes for raw sign but need to test * wip: porting to newly defined structure * updated signing to new structure, and added utils-cli from mix pr * updated file structure for balance * updated file structure for transfer * pr review updates * updated to sign not signing * signing-restructure tweeeeks (#220) * tweeeeks * more tweeks * fix tests * rename test * fix maskPayload * test fix * change sign command to just return sig * stdout cleanup for balance and sign * tweeks * fix transfer to allow decimal transfers --------- Co-authored-by: mix irving <mix@protozoa.nz>
- Loading branch information
Showing
31 changed files
with
682 additions
and
487 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,19 @@ | ||
import Entropy from "@entropyxyz/sdk" | ||
import { BaseCommand } from "../common/base-command" | ||
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 BaseCommand { | ||
constructor (entropy: Entropy, endpoint: string) { | ||
super(entropy, endpoint, FLOW_CONTEXT) | ||
} | ||
export async function entropyBalanceCommand (entropy: Entropy, rootCommand: Command) { | ||
rootCommand.command('balance') | ||
.description('Command to retrieive the balance of an account on the Entropy Network') | ||
.argument('address', 'Account address whose balance you want to query') | ||
.addOption(passwordOption()) | ||
.addOption(endpointOption()) | ||
.action(async (address, opts) => { | ||
const BalanceService = new EntropyBalance(entropy, opts.endpoint) | ||
const balance = await BalanceService.getBalance(address) | ||
cliWrite(`${balance.toLocaleString('en-US')} BITS`) | ||
process.exit(0) | ||
}) | ||
|
||
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` | ||
} | ||
} | ||
} |
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 BalanceService = new EntropyBalance(entropy, endpoint) | ||
const balance = await BalanceService.getBalance(storedConfig.selectedAccount) | ||
print(`Address ${storedConfig.selectedAccount} has a balance of: ${balance.toLocaleString('en-US')} BITS`) | ||
} 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,34 @@ | ||
import Entropy from "@entropyxyz/sdk" | ||
import { EntropyBase } from "../common/entropy-base" | ||
import * as BalanceUtils from "./utils" | ||
import { BalanceInfo } from "./types" | ||
|
||
const FLOW_CONTEXT = 'ENTROPY-BALANCE' | ||
export class EntropyBalance extends EntropyBase { | ||
constructor (entropy: Entropy, endpoint: string) { | ||
super(entropy, endpoint, FLOW_CONTEXT) | ||
} | ||
|
||
async getBalance (address: string): Promise<number> { | ||
const accountInfo = (await this.entropy.substrate.query.system.account(address)) as any | ||
const balance = parseInt(BalanceUtils.hexToBigInt(accountInfo.data.free).toString()) | ||
|
||
this.logger.log(`Current balance of ${address}: ${balance}`, EntropyBalance.name) | ||
return balance | ||
} | ||
|
||
async getBalances (addresses: string[]): Promise<BalanceInfo> { | ||
const balanceInfo: BalanceInfo = {} | ||
await Promise.all(addresses.map(async address => { | ||
try { | ||
const balance = await this.getBalance(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1 @@ | ||
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 | ||
} | ||
export const hexToBigInt = (hexString: string) => BigInt(hexString) |
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
Oops, something went wrong.