Skip to content

Commit 2ab16ac

Browse files
authored
Add a new output 'transfers' and make it default (#5644)
This adds a new output transfers which uses the same column as notes but excludes change notes.
1 parent 301aa74 commit 2ab16ac

File tree

1 file changed

+41
-10
lines changed
  • ironfish-cli/src/commands/wallet/transactions

1 file changed

+41
-10
lines changed

ironfish-cli/src/commands/wallet/transactions/index.ts

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ export class TransactionsCommand extends IronfishCommand {
5454
description: 'Number of block confirmations needed to confirm a transaction',
5555
}),
5656
notes: Flags.boolean({
57-
default: false,
5857
description: 'Include data from transaction output notes',
5958
}),
59+
format: Flags.string({
60+
description: 'output in a more machine friendly format',
61+
exclusive: ['notes'],
62+
options: ['notes', 'transactions', 'transfers'],
63+
helpGroup: 'OUTPUT',
64+
}),
6065
}
6166

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

77+
const output =
78+
flags.notes || flags.format === 'notes'
79+
? 'notes'
80+
: flags.format === 'transactions'
81+
? 'transactions'
82+
: flags.format === 'transfers'
83+
? 'transfers'
84+
: 'transfers'
85+
7286
const client = await this.connectRpc()
7387
await ui.checkWalletUnlocked(client)
7488

@@ -101,20 +115,20 @@ export class TransactionsCommand extends IronfishCommand {
101115
flags.limit,
102116
flags.offset,
103117
flags.confirmations,
104-
flags.notes,
118+
output === 'notes' || output === 'transfers',
105119
)
106120

107-
const columns = this.getColumns(flags.extended, flags.notes, format)
108-
109121
let hasTransactions = false
110122
let transactionRows: PartialRecursive<TransactionRow>[] = []
111123

112124
for await (const { account, transaction } of transactions) {
113125
if (transactionRows.length >= flags.limit) {
114126
break
115127
}
116-
if (flags.notes) {
128+
129+
if (output === 'notes' || output === 'transfers') {
117130
Assert.isNotUndefined(transaction.notes)
131+
118132
const assetLookup = await getAssetsByIDs(
119133
client,
120134
transaction.notes.map((n) => n.assetId) || [],
@@ -130,7 +144,13 @@ export class TransactionsCommand extends IronfishCommand {
130144
}
131145

132146
transactionRows = transactionRows.concat(
133-
this.getTransactionRowsByNote(assetLookup, accountsByAddress, transaction, format),
147+
this.getTransactionRowsByNote(
148+
assetLookup,
149+
accountsByAddress,
150+
transaction,
151+
format,
152+
output,
153+
),
134154
)
135155
} else {
136156
const assetLookup = await getAssetsByIDs(
@@ -146,6 +166,8 @@ export class TransactionsCommand extends IronfishCommand {
146166
hasTransactions = true
147167
}
148168

169+
const columns = this.getColumns(flags.extended, output, format)
170+
149171
ui.table(transactionRows, columns, {
150172
printLine: this.log.bind(this),
151173
...flags,
@@ -248,6 +270,7 @@ export class TransactionsCommand extends IronfishCommand {
248270
accountLookup: Map<string, string>,
249271
transaction: GetAccountTransactionsResponse,
250272
format: Format,
273+
output: 'notes' | 'transactions' | 'transfers',
251274
): PartialRecursive<TransactionRow>[] {
252275
Assert.isNotUndefined(transaction.notes)
253276
const transactionRows = []
@@ -272,7 +295,15 @@ export class TransactionsCommand extends IronfishCommand {
272295
const senderName = accountLookup.get(note.sender)
273296
const recipientName = accountLookup.get(note.owner)
274297

275-
const group = this.getRowGroup(index, noteCount, transactionRows.length)
298+
let group = this.getRowGroup(index, noteCount, transactionRows.length)
299+
300+
if (output === 'transfers') {
301+
if (note.sender === note.owner && !transaction.mints.length) {
302+
continue
303+
} else {
304+
group = ''
305+
}
306+
}
276307

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

314345
getColumns(
315346
extended: boolean,
316-
notes: boolean,
347+
output: 'notes' | 'transactions' | 'transfers',
317348
format: Format,
318349
): ui.TableColumns<PartialRecursive<TransactionRow>> {
319350
let columns: ui.TableColumns<PartialRecursive<TransactionRow>> = {
@@ -327,7 +358,7 @@ export class TransactionsCommand extends IronfishCommand {
327358
},
328359
type: {
329360
header: 'Type',
330-
minWidth: notes ? 18 : 8,
361+
minWidth: output === 'notes' || output === 'transfers' ? 18 : 8,
331362
get: (row) => row.type ?? '',
332363
},
333364
hash: {
@@ -386,7 +417,7 @@ export class TransactionsCommand extends IronfishCommand {
386417
},
387418
}
388419

389-
if (notes) {
420+
if (output === 'notes' || output === 'transfers') {
390421
columns = {
391422
...columns,
392423
senderName: {

0 commit comments

Comments
 (0)