Skip to content

Commit

Permalink
Merge pull request #2294 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER
  • Loading branch information
NullSoldier authored Oct 5, 2022
2 parents 0efb836 + b1e53b2 commit 6769ec1
Show file tree
Hide file tree
Showing 212 changed files with 12,097 additions and 6,248 deletions.
5 changes: 3 additions & 2 deletions ironfish-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ironfish",
"version": "0.1.47",
"version": "0.1.48",
"description": "CLI for running and interacting with an Iron Fish node",
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
"main": "build/src/index.js",
Expand Down Expand Up @@ -56,13 +56,14 @@
"dependencies": {
"@aws-sdk/client-s3": "3.127.0",
"@ironfish/rust-nodejs": "0.1.14",
"@ironfish/sdk": "0.0.24",
"@ironfish/sdk": "0.0.25",
"@oclif/core": "1.16.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
"@types/tar": "6.1.1",
"axios": "0.21.4",
"blessed": "0.1.81",
"blru": "0.1.6",
"json-colorizer": "2.2.2",
"segfault-handler": "1.3.0",
"supports-hyperlinks": "2.2.0",
Expand Down
10 changes: 10 additions & 0 deletions ironfish-cli/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
createRootLogger,
DatabaseVersionError,
ErrorUtils,
InternalOptions,
IronfishSdk,
Logger,
RpcConnectionError,
Expand All @@ -17,6 +18,7 @@ import {
DatabaseFlag,
DatabaseFlagKey,
DataDirFlagKey,
RpcAuthFlagKey,
RpcTcpHostFlagKey,
RpcTcpPortFlagKey,
RpcTcpSecureFlag,
Expand Down Expand Up @@ -46,6 +48,7 @@ export type FLAGS =
| typeof RpcTcpSecureFlagKey
| typeof RpcTcpTlsFlagKey
| typeof VerboseFlagKey
| typeof RpcAuthFlagKey

export abstract class IronfishCommand extends Command {
// Yes, this is disabling the type system but any code
Expand Down Expand Up @@ -109,6 +112,7 @@ export abstract class IronfishCommand extends Command {
const configFlag = getFlag(flags, ConfigFlagKey)

const configOverrides: Partial<ConfigOptions> = {}
const internalOverrides: Partial<InternalOptions> = {}

const databaseNameFlag = getFlag(flags, DatabaseFlagKey)
if (typeof databaseNameFlag === 'string' && databaseNameFlag !== DatabaseFlag.default) {
Expand Down Expand Up @@ -153,9 +157,15 @@ export abstract class IronfishCommand extends Command {
configOverrides.logLevel = '*:verbose'
}

const rpcAuthFlag = getFlag(flags, RpcAuthFlagKey)
if (typeof rpcAuthFlag === 'string') {
internalOverrides.rpcAuthToken = rpcAuthFlag
}

this.sdk = await IronfishSdk.init({
pkg: IronfishCliPKG,
configOverrides: configOverrides,
internalOverrides: internalOverrides,
configName: typeof configFlag === 'string' ? configFlag : undefined,
dataDir: typeof dataDirFlag === 'string' ? dataDirFlag : undefined,
logger: this.logger,
Expand Down
80 changes: 70 additions & 10 deletions ironfish-cli/src/commands/accounts/balance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { displayIronAmountWithCurrency, oreToIron } from '@ironfish/sdk'
import { CurrencyUtils, GetBalanceResponse } from '@ironfish/sdk'
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'

Expand All @@ -14,6 +15,22 @@ export class BalanceCommand extends IronfishCommand {

static flags = {
...RemoteFlags,
explain: Flags.boolean({
default: false,
description: 'Explain your balance',
}),
all: Flags.boolean({
default: false,
description: 'Also show pending and unconfirmed balance',
}),
confirmations: Flags.integer({
required: false,
description: 'Minimum number of blocks confirmations for a note',
}),
ore: Flags.boolean({
default: false,
description: 'Show amounts in ore',
}),
}

static args = [
Expand All @@ -26,26 +43,69 @@ export class BalanceCommand extends IronfishCommand {
]

async start(): Promise<void> {
const { args } = await this.parse(BalanceCommand)
const { flags, args } = await this.parse(BalanceCommand)
const account = args.account as string | undefined

const client = await this.sdk.connectRpc()

const response = await client.getAccountBalance({
account: account,
account,
minimumBlockConfirmations: flags.confirmations,
})

const { account: accountResponse, confirmed, unconfirmed } = response.content
if (flags.explain) {
this.explainBalance(response.content, flags.ore)
return
}

if (flags.all) {
this.log(`Account: ${response.content.account}`)
this.log(
`Balance: ${CurrencyUtils.render(response.content.confirmed, true, flags.ore)}`,
)
this.log(
`Unconfirmed: ${CurrencyUtils.render(response.content.unconfirmed, true, flags.ore)}`,
)
this.log(
`Pending: ${CurrencyUtils.render(response.content.pending, true, flags.ore)}`,
)
return
}

this.log(`Account: ${response.content.account}`)
this.log(`Balance: ${CurrencyUtils.render(response.content.confirmed, true, flags.ore)}`)
}

explainBalance(response: GetBalanceResponse, ore: boolean): void {
const unconfirmed = CurrencyUtils.decode(response.unconfirmed)
const pending = CurrencyUtils.decode(response.pending)
const confirmed = CurrencyUtils.decode(response.confirmed)

const pendingDelta = pending - unconfirmed
const unconfirmedDelta = unconfirmed - confirmed

this.log(`Account: ${response.account}`)
this.log('')

this.log(`Your balance is made of notes on the chain that are safe to spend`)
this.log(`Balance: ${CurrencyUtils.render(confirmed, true, ore)}`)
this.log('')

this.log(`Account - ${String(accountResponse)}\n`)
this.log(
`The balance is: ${displayIronAmountWithCurrency(oreToIron(Number(unconfirmed)), true)}`,
`${response.unconfirmedCount} notes worth ${CurrencyUtils.render(
unconfirmedDelta,
ore,
)} are on the chain within ${response.minimumBlockConfirmations.toString()} blocks of the head`,
)
this.log(`Unconfirmed: ${CurrencyUtils.render(unconfirmed, ore)}`)
this.log('')

this.log(
`Amount available to spend: ${displayIronAmountWithCurrency(
oreToIron(Number(confirmed)),
true,
)}`,
`${response.pendingCount} notes worth ${CurrencyUtils.render(
pendingDelta,
ore,
)} are waiting for miners to add them to the chain`,
)
this.log(`Pending: ${CurrencyUtils.render(pending, ore)}`)
}
}
4 changes: 2 additions & 2 deletions ironfish-cli/src/commands/accounts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CreateCommand extends IronfishCommand {

static args = [
{
name: 'name',
name: 'account',
parse: (input: string): Promise<string> => Promise.resolve(input.trim()),
required: false,
description: 'Name of the account',
Expand All @@ -24,7 +24,7 @@ export class CreateCommand extends IronfishCommand {

async start(): Promise<void> {
const { args } = await this.parse(CreateCommand)
let name = args.name as string
let name = args.account as string

if (!name) {
name = (await CliUx.ux.prompt('Enter the name of the account', {
Expand Down
15 changes: 7 additions & 8 deletions ironfish-cli/src/commands/accounts/import.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { AccountsValue, JSONUtils, PromiseUtils } from '@ironfish/sdk'
import { AccountValue, JSONUtils, PromiseUtils } from '@ironfish/sdk'
import { CliUx, Flags } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'
Expand Down Expand Up @@ -33,7 +33,7 @@ export class ImportCommand extends IronfishCommand {

const client = await this.sdk.connectRpc()

let account: AccountsValue | null = null
let account: Omit<AccountValue, 'id'> | null = null
if (importPath) {
account = await this.importFile(importPath)
} else if (process.stdin.isTTY) {
Expand Down Expand Up @@ -62,13 +62,13 @@ export class ImportCommand extends IronfishCommand {
}
}

async importFile(path: string): Promise<AccountsValue> {
async importFile(path: string): Promise<AccountValue> {
const resolved = this.sdk.fileSystem.resolve(path)
const data = await this.sdk.fileSystem.readFile(resolved)
return JSONUtils.parse<AccountsValue>(data)
return JSONUtils.parse<AccountValue>(data)
}

async importPipe(): Promise<AccountsValue> {
async importPipe(): Promise<AccountValue> {
let data = ''

const onData = (dataIn: string): void => {
Expand All @@ -84,10 +84,10 @@ export class ImportCommand extends IronfishCommand {

process.stdin.off('data', onData)

return JSONUtils.parse<AccountsValue>(data)
return JSONUtils.parse<AccountValue>(data)
}

async importTTY(): Promise<AccountsValue> {
async importTTY(): Promise<Omit<AccountValue, 'id'>> {
const accountName = (await CliUx.ux.prompt('Enter the account name', {
required: true,
})) as string
Expand All @@ -114,7 +114,6 @@ export class ImportCommand extends IronfishCommand {
incomingViewKey: incomingViewKey,
outgoingViewKey: outgoingViewKey,
publicAddress: publicAddress,
rescan: null,
}
}
}
59 changes: 34 additions & 25 deletions ironfish-cli/src/commands/accounts/notes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { oreToIron } from '@ironfish/sdk'
import { CurrencyUtils } from '@ironfish/sdk'
import { CliUx } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'
Expand All @@ -28,29 +28,38 @@ export class NotesCommand extends IronfishCommand {

const client = await this.sdk.connectRpc()

const response = await client.getAccountNotes({ account })

const { account: accountResponse, notes } = response.content

this.log(`\n ${accountResponse} - Account notes\n`)

CliUx.ux.table(notes, {
isSpender: {
header: 'Spender',
get: (row) => (row.spender ? `✔` : `x`),
},
amount: {
header: 'Amount ($IRON)',
get: (row) => oreToIron(row.amount),
},
memo: {
header: 'Memo',
},
noteTxHash: {
header: 'From Transaction',
},
})

this.log(`\n`)
const response = client.getAccountNotesStream({ account })

let showHeader = true

for await (const note of response.contentStream()) {
CliUx.ux.table(
[note],
{
amount: {
header: 'Amount ($IRON)',
get: (row) => CurrencyUtils.renderIron(row.amount),
},
memo: {
header: 'Memo',
},
transactionHash: {
header: 'From Transaction',
},
isSpent: {
header: 'Spent',
get: (row) => {
if (row.spent === undefined) {
return '-'
} else {
return row.spent ? `✔` : `x`
}
},
},
},
{ 'no-header': !showHeader },
)
showHeader = false
}
}
}
5 changes: 3 additions & 2 deletions ironfish-cli/src/commands/accounts/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class RemoveCommand extends IronfishCommand {

static args = [
{
name: 'name',
name: 'account',
parse: (input: string): Promise<string> => Promise.resolve(input.trim()),
required: true,
description: 'Name of the account',
},
Expand All @@ -27,7 +28,7 @@ export class RemoveCommand extends IronfishCommand {
async start(): Promise<void> {
const { args, flags } = await this.parse(RemoveCommand)
const confirm = flags.confirm
const name = (args.name as string).trim()
const name = args.account as string

const client = await this.sdk.connectRpc()

Expand Down
Loading

0 comments on commit 6769ec1

Please sign in to comment.