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

Revert "optionally organizes wallet:transactions output by note" #3734

Merged
merged 1 commit into from
Apr 4, 2023
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
83 changes: 5 additions & 78 deletions ironfish-cli/src/commands/wallet/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ export class TransactionsCommand extends IronfishCommand {
confirmations: Flags.integer({
description: 'Number of block confirmations needed to confirm a transaction',
}),
notes: Flags.boolean({
default: false,
description: 'Include data from transaction output notes',
}),
}

static args = [
Expand Down Expand Up @@ -73,17 +69,14 @@ export class TransactionsCommand extends IronfishCommand {
limit: flags.limit,
offset: flags.offset,
confirmations: flags.confirmations,
notes: flags.notes,
})

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

let showHeader = !flags['no-header']

for await (const transaction of response.contentStream()) {
const transactionRows = flags.notes
? this.getTransactionRowsByNote(transaction, format)
: this.getTransactionRows(transaction, format)
const transactionRows = this.getTransactionRows(transaction, format)

CliUx.ux.table(transactionRows, columns, {
printLine: this.log.bind(this),
Expand Down Expand Up @@ -151,63 +144,11 @@ export class TransactionsCommand extends IronfishCommand {
return transactionRows
}

getTransactionRowsByNote(
transaction: GetAccountTransactionsResponse,
format: Format,
): PartialRecursive<TransactionRow>[] {
Assert.isNotUndefined(transaction.notes)
const transactionRows = []

const nativeAssetId = Asset.nativeId().toString('hex')

const notes = transaction.notes.sort((n) => (n.assetId === nativeAssetId ? -1 : 1))

const noteCount = transaction.notes.length

const feePaid = transaction.type === TransactionType.SEND ? BigInt(transaction.fee) : 0n

for (const [index, note] of notes.entries()) {
const amount = BigInt(note.value)
const assetId = note.assetId
const assetName = note.assetName
const sender = note.sender
const recipient = note.owner

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

// include full transaction details in first row or non-cli-formatted output
if (transactionRows.length === 0 || format !== Format.cli) {
transactionRows.push({
...transaction,
group,
assetId,
assetName,
amount,
feePaid,
sender,
recipient,
})
} else {
transactionRows.push({
group,
assetId,
assetName,
amount,
sender,
recipient,
})
}
}

return transactionRows
}

getColumns(
extended: boolean,
notes: boolean,
format: Format,
): CliUx.Table.table.Columns<PartialRecursive<TransactionRow>> {
let columns: CliUx.Table.table.Columns<PartialRecursive<TransactionRow>> = {
const columns: CliUx.Table.table.Columns<PartialRecursive<TransactionRow>> = {
timestamp: TableCols.timestamp({
streaming: true,
}),
Expand Down Expand Up @@ -256,7 +197,7 @@ export class TransactionsCommand extends IronfishCommand {
},
...TableCols.asset({ extended, format }),
amount: {
header: 'Amount',
header: 'Net Amount',
get: (row) => {
Assert.isNotUndefined(row.amount)
return CurrencyUtils.renderIron(row.amount)
Expand All @@ -265,20 +206,8 @@ export class TransactionsCommand extends IronfishCommand {
},
}

if (notes) {
columns = {
...columns,
sender: {
header: 'Sender Address',
},
recipient: {
header: 'Recipient Address',
},
}
}

if (format === Format.cli) {
columns = {
return {
group: {
header: '',
minWidth: 3,
Expand Down Expand Up @@ -321,6 +250,4 @@ type TransactionRow = {
burnsCount: number
expiration: number
submittedSequence: number
sender: string
recipient: string
}