Skip to content

Commit d809153

Browse files
authored
Merge pull request #876 from lxcmyf/feature/dev_491
feat(display): optimize information display
2 parents 7a1069c + c4e8dc2 commit d809153

File tree

7 files changed

+120
-72
lines changed

7 files changed

+120
-72
lines changed

src/main/java/org/tron/common/utils/Utils.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ public static Tx getTx(Chain.Transaction transaction) {
610610
tx.setType(contract.getType().name());
611611
tx.setFrom(encode58Check(triggerSmartContract.getOwnerAddress().toByteArray()));
612612
tx.setTo(encode58Check(triggerSmartContract.getContractAddress().toByteArray()));
613-
setTransferParams(tx, triggerSmartContract);
613+
// setTransferParams(tx, triggerSmartContract);
614614
break;
615615
case UpdateSettingContract:
616616
UpdateSettingContract updateSettingContract =
@@ -1340,16 +1340,16 @@ public static void printWalletInfo(List<WalletFile> walletFileList, int index) {
13401340

13411341
System.out.println(formatLine(
13421342
String.valueOf(index + 1),
1343-
walletName,
13441343
wf.getAddress(),
1345-
4, 15, 42));
1344+
walletName,
1345+
4, 42, 76));
13461346
}
13471347

13481348
public static void searchWallets(List<WalletFile> walletFileList, String searchTerm) {
1349-
String headerFormat = "%-4s %-15s %-42s";
1349+
String headerFormat = "%-4s %-42s %-76s";
13501350
boolean found = false;
13511351

1352-
System.out.println(greenBoldHighlight(String.format(headerFormat, "No.", "Name", "Address")));
1352+
System.out.println(greenBoldHighlight(String.format(headerFormat, "No.", "Address", "Name")));
13531353

13541354
for (int i = 0; i < walletFileList.size(); i++) {
13551355
WalletFile wf = walletFileList.get(i);
@@ -1368,7 +1368,7 @@ public static void searchWallets(List<WalletFile> walletFileList, String searchT
13681368
}
13691369

13701370
public static void listWallets(List<WalletFile> walletFileList) {
1371-
System.out.println("\n" + greenBoldHighlight(formatLine("No.", "Name", "Address", 4, 15, 42)));
1371+
System.out.println("\n" + greenBoldHighlight(formatLine("No.", "Address", "Name", 4, 42, 76)));
13721372

13731373
IntStream.range(0, walletFileList.size())
13741374
.mapToObj(i -> {
@@ -1377,22 +1377,22 @@ public static void listWallets(List<WalletFile> walletFileList) {
13771377
String.valueOf(i + 1),
13781378
wf.getName(),
13791379
wf.getAddress(),
1380-
4, 15, 42);
1380+
4, 42, 76);
13811381
})
13821382
.forEach(System.out::println);
13831383
}
13841384

1385-
public static String formatLine(String no, String name, String address,
1386-
int noWidth, int nameWidth, int addrWidth) {
1385+
public static String formatLine(String no, String address, String name,
1386+
int noWidth, int addrWidth, int nameWidth) {
13871387
String displayName = truncateToWidth(name, nameWidth);
13881388

13891389
if (containsChinese(displayName)) {
13901390
displayName += " ";
13911391
}
13921392

13931393
return padRight(no, noWidth) + " "
1394-
+ padRight(displayName, nameWidth) + " "
1395-
+ padRight(address, addrWidth);
1394+
+ padRight(address, addrWidth) + " "
1395+
+ padRight(displayName, nameWidth);
13961396
}
13971397

13981398
public static int getDisplayWidth(String str) {
@@ -1481,7 +1481,7 @@ public static void nameWallet(WalletFile walletFile, boolean isLedger) {
14811481
walletFile.setName(walletName);
14821482
}
14831483

1484-
private static boolean isValidWalletName(String name) {
1484+
public static boolean isValidWalletName(String name) {
14851485
if (org.apache.commons.lang3.StringUtils.isEmpty(name)) {
14861486
return false;
14871487
}

src/main/java/org/tron/core/dao/Tx.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ public class Tx {
1717
private LocalDateTime timestamp;
1818
private String status;
1919
private String note;
20+
private String fullNodeEndpoint;
2021

2122
public Tx() {
2223
}
2324

24-
public Tx(String id, String type, String from, String to, String amount, LocalDateTime timestamp, String status, String note) {
25+
public Tx(String id, String type, String from, String to, String amount, LocalDateTime timestamp, String note, String fullNodeEndpoint) {
2526
this.id = Objects.requireNonNull(id);
2627
this.type = Objects.requireNonNull(type);
2728
this.from = Objects.requireNonNull(from);
2829
this.to = Objects.requireNonNull(to);
2930
this.amount = amount;
3031
this.timestamp = timestamp;
31-
this.status = Objects.requireNonNull(status);
3232
this.note = note;
33+
this.fullNodeEndpoint = fullNodeEndpoint;
3334
}
3435

3536
public boolean isRelatedTo(String address) {
@@ -38,14 +39,15 @@ public boolean isRelatedTo(String address) {
3839

3940
@Override
4041
public String toString() {
41-
return String.format("Tx[id=%s, type=%s, from=%s, to=%s, amount=%d, timestamp=%s, status=%s]",
42+
return String.format("Tx[id=%s, type=%s, from=%s, to=%s, amount=%s, timestamp=%s, note=%s, fullNodeEndpoint=%s]",
4243
id,
4344
type,
4445
from,
4546
to,
4647
amount,
4748
timestamp.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
48-
status);
49+
note,
50+
fullNodeEndpoint);
4951
}
5052

5153
private String abbreviate(String address) {

src/main/java/org/tron/core/manager/TxHistoryManager.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.tron.core.manager;
22

3+
import static org.tron.common.enums.NetType.CUSTOM;
4+
35
import com.typesafe.config.Config;
46
import java.io.IOException;
57
import java.nio.file.Files;
@@ -110,7 +112,7 @@ private List<String> readNonEmptyRecords(Path filePath) throws IOException {
110112
.collect(Collectors.toList());
111113
}
112114

113-
public List<Tx> getUserTransactions(NetType network, int page) {
115+
public List<Tx> getUserTransactions(NetType network, String fullnodeEndpoint, int page) {
114116
Path filePath = getNetworkFilePath(network);
115117
if (!Files.exists(filePath)) {
116118
return Collections.emptyList();
@@ -122,6 +124,10 @@ public List<Tx> getUserTransactions(NetType network, int page) {
122124
.filter(Optional::isPresent)
123125
.map(Optional::get)
124126
.filter(tx -> tx.isRelatedTo(currentUserAddress))
127+
.filter(tx -> network != CUSTOM ||
128+
(fullnodeEndpoint != null &&
129+
!fullnodeEndpoint.trim().isEmpty() &&
130+
fullnodeEndpoint.equals(tx.getFullNodeEndpoint())))
125131
.sorted(Comparator.comparing(Tx::getTimestamp).reversed())
126132
.skip((page - 1L) * PAGE_SIZE)
127133
.limit(PAGE_SIZE)
@@ -132,7 +138,7 @@ public List<Tx> getUserTransactions(NetType network, int page) {
132138
}
133139
}
134140

135-
public List<Tx> getUserTransactionsByTimeRange(NetType network, LocalDateTime start, LocalDateTime end, int page) {
141+
public List<Tx> getUserTransactionsByTimeRange(NetType network, String fullnodeEndpoint, LocalDateTime start, LocalDateTime end, int page) {
136142
Path filePath = getNetworkFilePath(network);
137143
if (!Files.exists(filePath)) {
138144
return Collections.emptyList();
@@ -146,6 +152,10 @@ public List<Tx> getUserTransactionsByTimeRange(NetType network, LocalDateTime st
146152
.filter(tx -> tx.isRelatedTo(currentUserAddress))
147153
.filter(tx -> !tx.getTimestamp().isBefore(start))
148154
.filter(tx -> !tx.getTimestamp().isAfter(end))
155+
.filter(tx -> network != CUSTOM ||
156+
(fullnodeEndpoint != null &&
157+
!fullnodeEndpoint.trim().isEmpty() &&
158+
fullnodeEndpoint.equals(tx.getFullNodeEndpoint())))
149159
.sorted(Comparator.comparing(Tx::getTimestamp).reversed())
150160
.skip((page - 1L) * PAGE_SIZE)
151161
.limit(PAGE_SIZE)
@@ -164,7 +174,7 @@ private void ensureBaseDirectoryExists() {
164174
}
165175
}
166176

167-
public int getUserTotalPages(NetType network) {
177+
public int getUserTotalPages(NetType network, String fullnodeEndpoint) {
168178
Path filePath = getNetworkFilePath(network);
169179
if (!Files.exists(filePath)) {
170180
return 0;
@@ -176,6 +186,10 @@ public int getUserTotalPages(NetType network) {
176186
.filter(Optional::isPresent)
177187
.map(Optional::get)
178188
.filter(tx -> tx.isRelatedTo(currentUserAddress))
189+
.filter(tx -> network != CUSTOM ||
190+
(fullnodeEndpoint != null &&
191+
!fullnodeEndpoint.trim().isEmpty() &&
192+
fullnodeEndpoint.equals(tx.getFullNodeEndpoint())))
179193
.count();
180194

181195
return (int) Math.ceil((double) count / PAGE_SIZE);
@@ -185,7 +199,7 @@ public int getUserTotalPages(NetType network) {
185199
}
186200
}
187201

188-
public int getUserTotalPagesByTimeRange(NetType network, LocalDateTime start, LocalDateTime end) {
202+
public int getUserTotalPagesByTimeRange(NetType network, String fullnodeEndpoint, LocalDateTime start, LocalDateTime end) {
189203
Path filePath = getNetworkFilePath(network);
190204
if (!Files.exists(filePath)) {
191205
return 0;
@@ -199,6 +213,10 @@ public int getUserTotalPagesByTimeRange(NetType network, LocalDateTime start, Lo
199213
.filter(tx -> tx.isRelatedTo(currentUserAddress))
200214
.filter(tx -> !tx.getTimestamp().isBefore(start))
201215
.filter(tx -> !tx.getTimestamp().isAfter(end))
216+
.filter(tx -> network != CUSTOM ||
217+
(fullnodeEndpoint != null &&
218+
!fullnodeEndpoint.trim().isEmpty() &&
219+
fullnodeEndpoint.equals(tx.getFullNodeEndpoint())))
202220
.count();
203221

204222
return (int) Math.ceil((double) count / PAGE_SIZE);
@@ -216,8 +234,9 @@ private String txToLine(Tx tx) {
216234
StringUtils.isEmpty(tx.getTo()) ? DASH : tx.getTo(),
217235
StringUtils.isEmpty(tx.getAmount()) ? DASH : tx.getAmount(),
218236
tx.getTimestamp().format(TIMESTAMP_FORMAT),
219-
tx.getStatus(),
220-
StringUtils.isEmpty(tx.getNote()) ? DASH : tx.getNote()
237+
// tx.getStatus(),
238+
StringUtils.isEmpty(tx.getNote()) ? DASH : tx.getNote(),
239+
StringUtils.isEmpty(tx.getFullNodeEndpoint()) ? DASH : tx.getFullNodeEndpoint()
221240
);
222241
}
223242

@@ -233,8 +252,8 @@ private Optional<Tx> lineToTx(String line) {
233252
parts[3], // to
234253
parts[4], // amount
235254
LocalDateTime.parse(parts[5], TIMESTAMP_FORMAT), // timestamp
236-
parts[6], // status
237-
parts[7] // note
255+
parts[6], // note
256+
parts[7] // fullNodeEndpoint
238257
));
239258
} catch (Exception e) {
240259
System.err.println("Failed to parse transaction line: " + line);

src/main/java/org/tron/core/viewer/TxHistoryViewer.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,24 @@ public class TxHistoryViewer {
1717
private final Scanner scanner;
1818
private static final DateTimeFormatter DATE_FORMAT =
1919
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
20+
private static final DateTimeFormatter DATE_FORMAT_WITHOUT_SECOND =
21+
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
2022

2123
public TxHistoryViewer(TxHistoryManager historyManager) {
2224
this.historyManager = historyManager;
2325
this.scanner = new Scanner(System.in);
2426
}
2527

26-
public void startInteractiveViewer(NetType netType) {
28+
public void startInteractiveViewer(NetType netType, String fullnodeEndpoint) {
2729
printWelcome();
2830

2931
while (true) {
3032
printMainMenu();
3133
String command = scanner.nextLine().trim().toLowerCase();
3234

3335
switch (command) {
34-
case "1": showTransactionList(netType); break;
35-
case "2": showTransactionsByTimeRange(netType); break;
36+
case "1": showTransactionList(netType, fullnodeEndpoint); break;
37+
case "2": showTransactionsByTimeRange(netType, fullnodeEndpoint); break;
3638
case "3": printHelp(); break;
3739
case "4": return;
3840
default: System.out.println("Invalid command");
@@ -55,17 +57,17 @@ private void printMainMenu() {
5557
System.out.print("Select option: ");
5658
}
5759

58-
private void showTransactionList(NetType netType) {
60+
private void showTransactionList(NetType netType, String fullnodeEndpoint) {
5961
int currentPage = 1;
60-
int totalPages = historyManager.getUserTotalPages(netType);
62+
int totalPages = historyManager.getUserTotalPages(netType, fullnodeEndpoint);
6163

6264
if (totalPages == 0) {
6365
System.out.println("\nNo transactions found");
6466
return;
6567
}
6668

6769
while (true) {
68-
List<Tx> transactions = historyManager.getUserTransactions(netType, currentPage);
70+
List<Tx> transactions = historyManager.getUserTransactions(netType, fullnodeEndpoint, currentPage);
6971
printTransactionPage(transactions, currentPage, totalPages);
7072

7173
System.out.print("\n[" + greenBoldHighlight("n") + "]Next [" + greenBoldHighlight("p") + "]Previous [" + greenBoldHighlight("q") + "]Back: ");
@@ -83,7 +85,7 @@ private void showTransactionList(NetType netType) {
8385
}
8486
}
8587

86-
private void showTransactionsByTimeRange(NetType netType) {
88+
private void showTransactionsByTimeRange(NetType netType, String fullnodeEndpoint) {
8789
try {
8890
System.out.println("\n=== TIME RANGE FILTER ===");
8991
System.out.println("Format: yyyy-MM-dd HH:mm:ss (e.g. 2023-10-01 14:30:33)");
@@ -93,7 +95,7 @@ private void showTransactionsByTimeRange(NetType netType) {
9395
LocalDateTime end = getLocalDateTime("End time: ");
9496

9597
int currentPage = 1;
96-
int totalPages = historyManager.getUserTotalPagesByTimeRange(netType, start, end);
98+
int totalPages = historyManager.getUserTotalPagesByTimeRange(netType, fullnodeEndpoint, start, end);
9799

98100
if (totalPages == 0) {
99101
System.out.println("\nNo transactions found in this time range");
@@ -102,7 +104,7 @@ private void showTransactionsByTimeRange(NetType netType) {
102104

103105
while (true) {
104106
List<Tx> transactions =
105-
historyManager.getUserTransactionsByTimeRange(netType, start, end, currentPage);
107+
historyManager.getUserTransactionsByTimeRange(netType, fullnodeEndpoint, start, end, currentPage);
106108
printTransactionPage(transactions, currentPage, totalPages);
107109

108110
System.out.print("\n[" + greenBoldHighlight("n") + "]Next [" + greenBoldHighlight("p") + "]Previous [" + greenBoldHighlight("q") + "]Back: ");
@@ -140,27 +142,27 @@ private LocalDateTime getLocalDateTime(String s) {
140142
private void printTransactionPage(List<Tx> transactions, int currentPage, int totalPages) {
141143
// Print table header
142144
System.out.printf("\n=== TRANSACTIONS (Page %d of %d) ===\n", currentPage, totalPages);
143-
System.out.println("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
144-
System.out.printf("%-78s %-45s %-48s %-48s %-33s %-21s %-30s " +
145+
System.out.println("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
146+
System.out.printf("%-78s %-45s %-48s %-48s %-33s %-30s " +
145147
// "%-100s" +
146148
"\n",
147-
greenBoldHighlight("ID"), greenBoldHighlight("TYPE"), greenBoldHighlight("OWNER ADDRESS"), greenBoldHighlight("ACTIVE/TO/CONTRACT ADDRESS"), greenBoldHighlight("AMOUNT"), greenBoldHighlight("STATUS"), greenBoldHighlight("TIME")
149+
greenBoldHighlight("ID"), greenBoldHighlight("TYPE"), greenBoldHighlight("OWNER ADDRESS"), greenBoldHighlight("ACTIVE/TO/CONTRACT ADDRESS"), greenBoldHighlight("AMOUNT"), greenBoldHighlight("TIME")
148150
// , greenBoldHighlight("NOTE")
149151
);
150-
System.out.println("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
152+
System.out.println("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
151153

152154
// Print all transaction fields
153155
for (Tx tx : transactions) {
154-
System.out.printf("%-65s %-32s %-35s %-35s %-20s %-8s %-17s" +
156+
System.out.printf("%-65s %-32s %-35s %-35s %-20s %-17s" +
155157
// " %-100s" +
156158
"\n",
157159
tx.getId(),
158160
tx.getType(),
159161
tx.getFrom(),
160162
tx.getTo(),
161163
tx.getAmount(),
162-
tx.getStatus(),
163-
tx.getTimestamp().format(DATE_FORMAT)
164+
// tx.getStatus(),
165+
tx.getTimestamp().format(DATE_FORMAT_WITHOUT_SECOND)
164166
// , tx.getNote() != null ? tx.getNote() : ""
165167
);
166168
}

src/main/java/org/tron/walletcli/Client.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
import static org.tron.common.enums.NetType.CUSTOM;
55
import static org.tron.common.utils.CommandHelpUtil.getCommandHelp;
66
import static org.tron.common.utils.Utils.EMPTY_STR;
7+
import static org.tron.common.utils.Utils.MAX_LENGTH;
8+
import static org.tron.common.utils.Utils.MIN_LENGTH;
79
import static org.tron.common.utils.Utils.VERSION;
810
import static org.tron.common.utils.Utils.blueBoldHighlight;
911
import static org.tron.common.utils.Utils.failedHighlight;
1012
import static org.tron.common.utils.Utils.getLong;
1113
import static org.tron.common.utils.Utils.greenBoldHighlight;
1214
import static org.tron.common.utils.Utils.isValid;
15+
import static org.tron.common.utils.Utils.isValidWalletName;
1316
import static org.tron.common.utils.Utils.printBanner;
1417
import static org.tron.common.utils.Utils.printHelp;
1518
import static org.tron.common.utils.Utils.printStackTrace;
@@ -3971,6 +3974,11 @@ private void modifyWalletName(String[] parameters) throws IOException {
39713974
return;
39723975
}
39733976
String newName = parameters[0];
3977+
if(!isValidWalletName(newName)) {
3978+
System.out.println("The wallet name "
3979+
+ String.format("must be between %d and %d characters", MIN_LENGTH, MAX_LENGTH));
3980+
return;
3981+
}
39743982
boolean success = walletApiWrapper.modifyWalletName(newName);
39753983
if (success) {
39763984
System.out.println("Modify Wallet Name " + successfulHighlight() + " !!");

0 commit comments

Comments
 (0)