Skip to content

Commit 4596b89

Browse files
authored
- adds default limit for table output to 50 (#5611)
- prints message at end of table if limit is reached - updates commands to handle limit
1 parent 57ca7ee commit 4596b89

File tree

6 files changed

+150
-147
lines changed

6 files changed

+150
-147
lines changed

ironfish-cli/src/commands/mempool/transactions.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ export class TransactionsCommand extends IronfishCommand {
131131

132132
const transactions: GetMempoolTransactionResponse[] = []
133133
for await (const transaction of response.contentStream()) {
134+
if (transactions.length >= flags.limit) {
135+
break
136+
}
134137
transactions.push(transaction)
135138
}
136139

@@ -208,22 +211,16 @@ function renderTable(
208211

209212
let result = ''
210213

211-
const limit = flags.csv ? 0 : flags.show
212-
table(getRows(response, limit), columns, {
214+
table(getRows(response), columns, {
213215
printLine: (line) => (result += `${String(line)}\n`),
214216
...flags,
215217
})
216218

217-
if (limit > 0 && response.length > limit) {
218-
result += ` ... ${response.length - limit} more rows\n`
219-
}
220-
221219
return result
222220
}
223221

224-
function getRows(response: GetMempoolTransactionResponse[], limit: number): TransactionRow[] {
225-
const transactions = limit > 0 ? response.slice(0, limit) : response
226-
return transactions.map(({ serializedTransaction, position, expiresIn }) => {
222+
function getRows(response: GetMempoolTransactionResponse[]): TransactionRow[] {
223+
return response.map(({ serializedTransaction, position, expiresIn }) => {
227224
const transaction = new Transaction(Buffer.from(serializedTransaction, 'hex'))
228225

229226
return {

ironfish-cli/src/commands/peers/banned.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class BannedCommand extends IronfishCommand {
3333
if (!flags.follow) {
3434
await this.sdk.client.connect()
3535
const response = await this.sdk.client.peer.getBannedPeers()
36-
this.log(renderTable(response.content))
36+
this.log(renderTable(response.content, flags.limit))
3737
this.exit(0)
3838
}
3939

@@ -59,14 +59,14 @@ export class BannedCommand extends IronfishCommand {
5959

6060
for await (const value of response.contentStream()) {
6161
text.clearBaseLine(0)
62-
text.setContent(renderTable(value))
62+
text.setContent(renderTable(value, flags.limit))
6363
screen.render()
6464
}
6565
}
6666
}
6767
}
6868

69-
function renderTable(content: GetBannedPeersResponse): string {
69+
function renderTable(content: GetBannedPeersResponse, limit: number): string {
7070
const columns: TableColumns<BannedPeerResponse> = {
7171
identity: {
7272
minWidth: 45,
@@ -87,6 +87,7 @@ function renderTable(content: GetBannedPeersResponse): string {
8787
let result = ''
8888

8989
table(content.peers, columns, {
90+
limit,
9091
printLine: (line) => (result += `${String(line)}\n`),
9192
})
9293

ironfish-cli/src/commands/wallet/assets.ts

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -52,68 +52,68 @@ export class AssetsCommand extends IronfishCommand {
5252
const assetNameWidth = flags.extended
5353
? MAX_ASSET_NAME_COLUMN_WIDTH
5454
: MIN_ASSET_NAME_COLUMN_WIDTH
55-
let showHeader = !flags['no-header']
56-
55+
const assets = []
5756
for await (const asset of response.contentStream()) {
58-
table(
59-
[asset],
60-
{
61-
name: TableCols.fixedWidth({
62-
header: 'Name',
63-
width: assetNameWidth,
64-
get: (row) =>
65-
renderAssetWithVerificationStatus(
66-
BufferUtils.toHuman(Buffer.from(row.name, 'hex')),
67-
{
68-
verification: row.verification,
69-
outputType: flags.output,
70-
},
71-
),
72-
}),
73-
id: {
74-
header: 'ID',
75-
minWidth: ASSET_ID_LENGTH + 1,
76-
get: (row) => row.id,
77-
},
78-
metadata: TableCols.fixedWidth({
79-
header: 'Metadata',
80-
width: assetMetadataWidth,
81-
get: (row) => BufferUtils.toHuman(Buffer.from(row.metadata, 'hex')),
82-
}),
83-
createdTransactionHash: {
84-
header: 'Created Transaction Hash',
85-
get: (row) => row.createdTransactionHash,
86-
},
87-
supply: {
88-
header: 'Supply',
89-
minWidth: 16,
90-
get: (row) => row.supply ?? 'NULL',
91-
},
92-
creator: {
93-
header: 'Creator',
94-
minWidth: PUBLIC_ADDRESS_LENGTH + 1,
95-
get: (row) =>
96-
row.id === Asset.nativeId().toString('hex')
97-
? BufferUtils.toHuman(Buffer.from(row.creator, 'hex'))
98-
: row.creator,
99-
},
100-
owner: {
101-
header: 'Owner',
102-
minWidth: PUBLIC_ADDRESS_LENGTH + 1,
103-
get: (row) =>
104-
row.id === Asset.nativeId().toString('hex')
105-
? BufferUtils.toHuman(Buffer.from(row.owner, 'hex'))
106-
: row.owner,
107-
},
57+
assets.push(asset)
58+
if (assets.length >= flags.limit) {
59+
break
60+
}
61+
}
62+
table(
63+
assets,
64+
{
65+
name: TableCols.fixedWidth({
66+
header: 'Name',
67+
width: assetNameWidth,
68+
get: (row) =>
69+
renderAssetWithVerificationStatus(
70+
BufferUtils.toHuman(Buffer.from(row.name, 'hex')),
71+
{
72+
verification: row.verification,
73+
outputType: flags.output,
74+
},
75+
),
76+
}),
77+
id: {
78+
header: 'ID',
79+
minWidth: ASSET_ID_LENGTH + 1,
80+
get: (row) => row.id,
10881
},
109-
{
110-
printLine: this.log.bind(this),
111-
...flags,
112-
'no-header': !showHeader,
82+
metadata: TableCols.fixedWidth({
83+
header: 'Metadata',
84+
width: assetMetadataWidth,
85+
get: (row) => BufferUtils.toHuman(Buffer.from(row.metadata, 'hex')),
86+
}),
87+
createdTransactionHash: {
88+
header: 'Created Transaction Hash',
89+
get: (row) => row.createdTransactionHash,
11390
},
114-
)
115-
116-
showHeader = false
117-
}
91+
supply: {
92+
header: 'Supply',
93+
minWidth: 16,
94+
get: (row) => row.supply ?? 'NULL',
95+
},
96+
creator: {
97+
header: 'Creator',
98+
minWidth: PUBLIC_ADDRESS_LENGTH + 1,
99+
get: (row) =>
100+
row.id === Asset.nativeId().toString('hex')
101+
? BufferUtils.toHuman(Buffer.from(row.creator, 'hex'))
102+
: row.creator,
103+
},
104+
owner: {
105+
header: 'Owner',
106+
minWidth: PUBLIC_ADDRESS_LENGTH + 1,
107+
get: (row) =>
108+
row.id === Asset.nativeId().toString('hex')
109+
? BufferUtils.toHuman(Buffer.from(row.owner, 'hex'))
110+
: row.owner,
111+
},
112+
},
113+
{
114+
printLine: this.log.bind(this),
115+
...flags,
116+
},
117+
)
118118
}
119119
}
Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4-
import { CurrencyUtils, RpcAsset } from '@ironfish/sdk'
4+
import { CurrencyUtils, RpcAsset, RpcWalletNote } from '@ironfish/sdk'
55
import { Flags } from '@oclif/core'
66
import { IronfishCommand } from '../../../command'
77
import { RemoteFlags } from '../../../flags'
@@ -33,74 +33,74 @@ export class NotesCommand extends IronfishCommand {
3333
const account = await useAccount(client, flags.account)
3434

3535
const response = client.wallet.getAccountNotesStream({ account })
36-
37-
let showHeader = !flags['no-header']
38-
36+
const notes: RpcWalletNote[] = []
3937
for await (const note of response.contentStream()) {
38+
if (notes.length >= flags.limit) {
39+
break
40+
}
4041
if (!assetLookup.has(note.assetId)) {
4142
assetLookup.set(
4243
note.assetId,
4344
(await client.wallet.getAsset({ id: note.assetId, account })).content,
4445
)
4546
}
46-
47-
ui.table(
48-
[note],
49-
{
50-
memo: {
51-
header: 'Memo',
52-
// Maximum memo length is 32 bytes
53-
minWidth: 33,
54-
get: (row) => row.memo,
55-
},
56-
sender: {
57-
header: 'Sender',
58-
get: (row) => row.sender,
59-
},
60-
transactionHash: {
61-
header: 'From Transaction',
62-
get: (row) => row.transactionHash,
63-
},
64-
isSpent: {
65-
header: 'Spent',
66-
get: (row) => {
67-
if (row.spent === undefined) {
68-
return '-'
69-
} else {
70-
return row.spent ? `✔` : `x`
71-
}
72-
},
73-
},
74-
...TableCols.asset({ extended: flags.extended }),
75-
value: {
76-
header: 'Amount',
77-
get: (row) =>
78-
CurrencyUtils.render(
79-
row.value,
80-
false,
81-
row.assetId,
82-
assetLookup.get(row.assetId)?.verification,
83-
),
84-
minWidth: 16,
85-
},
86-
noteHash: {
87-
header: 'Note Hash',
88-
get: (row) => row.noteHash,
47+
notes.push(note)
48+
}
49+
ui.table(
50+
notes,
51+
{
52+
memo: {
53+
header: 'Memo',
54+
// Maximum memo length is 32 bytes
55+
minWidth: 33,
56+
get: (row) => row.memo,
57+
},
58+
sender: {
59+
header: 'Sender',
60+
get: (row) => row.sender,
61+
},
62+
transactionHash: {
63+
header: 'From Transaction',
64+
get: (row) => row.transactionHash,
65+
},
66+
isSpent: {
67+
header: 'Spent',
68+
get: (row) => {
69+
if (row.spent === undefined) {
70+
return '-'
71+
} else {
72+
return row.spent ? `✔` : `x`
73+
}
8974
},
90-
nullifier: {
91-
header: 'Nullifier',
92-
get: (row) => {
93-
if (row.nullifier === null) {
94-
return '-'
95-
} else {
96-
return row.nullifier
97-
}
98-
},
75+
},
76+
...TableCols.asset({ extended: flags.extended }),
77+
value: {
78+
header: 'Amount',
79+
get: (row) =>
80+
CurrencyUtils.render(
81+
row.value,
82+
false,
83+
row.assetId,
84+
assetLookup.get(row.assetId)?.verification,
85+
),
86+
minWidth: 16,
87+
},
88+
noteHash: {
89+
header: 'Note Hash',
90+
get: (row) => row.noteHash,
91+
},
92+
nullifier: {
93+
header: 'Nullifier',
94+
get: (row) => {
95+
if (row.nullifier === null) {
96+
return '-'
97+
} else {
98+
return row.nullifier
99+
}
99100
},
100101
},
101-
{ ...flags, 'no-header': !showHeader },
102-
)
103-
showHeader = false
104-
}
102+
},
103+
flags,
104+
)
105105
}
106106
}

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ export class TransactionsCommand extends IronfishCommand {
3838
char: 's',
3939
description: 'Block sequence to get transactions for',
4040
}),
41-
limit: Flags.integer({
42-
description: 'Number of latest transactions to get details for',
43-
}),
4441
offset: Flags.integer({
4542
description: 'Number of latest transactions to skip',
4643
}),
@@ -82,11 +79,13 @@ export class TransactionsCommand extends IronfishCommand {
8279

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

85-
let showHeader = !flags['no-header']
8682
let hasTransactions = false
8783

84+
let transactionRows: PartialRecursive<TransactionRow>[] = []
8885
for await (const transaction of response.contentStream()) {
89-
let transactionRows: PartialRecursive<TransactionRow>[]
86+
if (transactionRows.length >= flags.limit) {
87+
break
88+
}
9089
if (flags.notes) {
9190
Assert.isNotUndefined(transaction.notes)
9291
const assetLookup = await getAssetsByIDs(
@@ -113,17 +112,14 @@ export class TransactionsCommand extends IronfishCommand {
113112
)
114113
transactionRows = this.getTransactionRows(assetLookup, transaction, format)
115114
}
116-
117-
ui.table(transactionRows, columns, {
118-
printLine: this.log.bind(this),
119-
...flags,
120-
'no-header': !showHeader,
121-
})
122-
123-
showHeader = false
124115
hasTransactions = true
125116
}
126117

118+
ui.table(transactionRows, columns, {
119+
printLine: this.log.bind(this),
120+
...flags,
121+
})
122+
127123
if (!hasTransactions) {
128124
this.log('No transactions found')
129125
}

0 commit comments

Comments
 (0)