Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new output 'transfers' and make it default #5644

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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