Skip to content

Commit

Permalink
Add a new output 'transfers' and make it default
Browse files Browse the repository at this point in the history
This adds a new output transfers which uses the same column as notes but
excludes change notes.
  • Loading branch information
NullSoldier committed Nov 13, 2024
1 parent a243067 commit 9025369
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions ironfish-cli/src/commands/wallet/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ export class TransactionsCommand extends IronfishCommand {
description: 'Number of block confirmations needed to confirm a transaction',
}),
notes: Flags.boolean({
default: false,
description: 'Include data from transaction output notes',
}),
format: Flags.string({
description: 'output in a more machine friendly format',
exclusive: ['notes'],
options: ['notes', 'transactions', 'transfers'],
helpGroup: 'OUTPUT',
}),
}

async start(): Promise<void> {
Expand All @@ -69,6 +74,15 @@ export class TransactionsCommand extends IronfishCommand {
? Format.json
: Format.cli

const output =
flags.notes || flags.format === 'notes'
? 'notes'
: flags.format === 'transactions'
? 'transactions'
: flags.format === 'transfers'
? 'transfers'
: 'transfers'

const client = await this.connectRpc()
await ui.checkWalletUnlocked(client)

Expand Down Expand Up @@ -101,20 +115,20 @@ export class TransactionsCommand extends IronfishCommand {
flags.limit,
flags.offset,
flags.confirmations,
flags.notes,
output === 'notes' || output === 'transfers',
)

const columns = this.getColumns(flags.extended, flags.notes, format)

let hasTransactions = false
let transactionRows: PartialRecursive<TransactionRow>[] = []

for await (const { account, transaction } of transactions) {
if (transactionRows.length >= flags.limit) {
break
}
if (flags.notes) {

if (output === 'notes' || output === 'transfers') {
Assert.isNotUndefined(transaction.notes)

const assetLookup = await getAssetsByIDs(
client,
transaction.notes.map((n) => n.assetId) || [],
Expand All @@ -130,7 +144,13 @@ export class TransactionsCommand extends IronfishCommand {
}

transactionRows = transactionRows.concat(
this.getTransactionRowsByNote(assetLookup, accountsByAddress, transaction, format),
this.getTransactionRowsByNote(
assetLookup,
accountsByAddress,
transaction,
format,
output,
),
)
} else {
const assetLookup = await getAssetsByIDs(
Expand All @@ -146,6 +166,8 @@ export class TransactionsCommand extends IronfishCommand {
hasTransactions = true
}

const columns = this.getColumns(flags.extended, output, format)

ui.table(transactionRows, columns, {
printLine: this.log.bind(this),
...flags,
Expand Down Expand Up @@ -248,6 +270,7 @@ export class TransactionsCommand extends IronfishCommand {
accountLookup: Map<string, string>,
transaction: GetAccountTransactionsResponse,
format: Format,
output: 'notes' | 'transactions' | 'transfers',
): PartialRecursive<TransactionRow>[] {
Assert.isNotUndefined(transaction.notes)
const transactionRows = []
Expand All @@ -272,7 +295,15 @@ export class TransactionsCommand extends IronfishCommand {
const senderName = accountLookup.get(note.sender)
const recipientName = accountLookup.get(note.owner)

const group = this.getRowGroup(index, noteCount, transactionRows.length)
let group = this.getRowGroup(index, noteCount, transactionRows.length)

if (output === 'transfers') {
if (note.sender === note.owner && !transaction.mints.length) {
continue
} else {
group = ''
}
}

// include full transaction details in first row or non-cli-formatted output
if (transactionRows.length === 0 || format !== Format.cli) {
Expand Down Expand Up @@ -313,7 +344,7 @@ export class TransactionsCommand extends IronfishCommand {

getColumns(
extended: boolean,
notes: boolean,
output: 'notes' | 'transactions' | 'transfers',
format: Format,
): ui.TableColumns<PartialRecursive<TransactionRow>> {
let columns: ui.TableColumns<PartialRecursive<TransactionRow>> = {
Expand All @@ -327,7 +358,7 @@ export class TransactionsCommand extends IronfishCommand {
},
type: {
header: 'Type',
minWidth: notes ? 18 : 8,
minWidth: output === 'notes' || output === 'transfers' ? 18 : 8,
get: (row) => row.type ?? '',
},
hash: {
Expand Down Expand Up @@ -386,7 +417,7 @@ export class TransactionsCommand extends IronfishCommand {
},
}

if (notes) {
if (output === 'notes' || output === 'transfers') {
columns = {
...columns,
senderName: {
Expand Down

0 comments on commit 9025369

Please sign in to comment.