Skip to content

Commit 43bf1ad

Browse files
authored
Merge pull request #874 from lxcmyf/feature/dev_491
feat(prompt): optimize prompt information
2 parents e95398d + 141ec79 commit 43bf1ad

File tree

8 files changed

+52
-15
lines changed

8 files changed

+52
-15
lines changed

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.apache.commons.lang3.StringUtils.isEmpty;
2323
import static org.tron.common.utils.ByteArray.toHexString;
2424
import static org.tron.common.utils.DomainValidator.isDomainOrIP;
25+
import static org.tron.core.manager.TxHistoryManager.DASH;
2526
import static org.tron.keystore.StringUtils.byte2String;
2627
import static org.tron.ledger.console.ConsoleColor.ANSI_BLUE;
2728
import static org.tron.ledger.console.ConsoleColor.ANSI_BOLD;
@@ -42,6 +43,7 @@
4243
import java.io.Console;
4344
import java.io.IOException;
4445
import java.io.InputStream;
46+
import java.math.BigInteger;
4547
import java.nio.ByteBuffer;
4648
import java.nio.CharBuffer;
4749
import java.nio.charset.Charset;
@@ -57,6 +59,7 @@
5759
import java.util.regex.Pattern;
5860
import java.util.stream.Collectors;
5961
import java.util.stream.IntStream;
62+
import org.bouncycastle.util.encoders.Hex;
6063
import org.jetbrains.annotations.Nullable;
6164
import org.tron.api.GrpcAPI.BlockExtention;
6265
import org.tron.api.GrpcAPI.BlockList;
@@ -128,6 +131,8 @@ public class Utils {
128131

129132
public static final int MIN_LENGTH = 2;
130133
public static final int MAX_LENGTH = 14;
134+
public static final String VERSION = " v4.9.1";
135+
public static final String TRANSFER_METHOD_ID = "a9059cbb";
131136

132137
private static SecureRandom random = new SecureRandom();
133138

@@ -605,6 +610,7 @@ public static Tx getTx(Chain.Transaction transaction) {
605610
tx.setType(contract.getType().name());
606611
tx.setFrom(encode58Check(triggerSmartContract.getOwnerAddress().toByteArray()));
607612
tx.setTo(encode58Check(triggerSmartContract.getContractAddress().toByteArray()));
613+
setTransferParams(tx, triggerSmartContract);
608614
break;
609615
case UpdateSettingContract:
610616
UpdateSettingContract updateSettingContract =
@@ -778,6 +784,35 @@ public static Tx getTx(Chain.Transaction transaction) {
778784
return tx;
779785
}
780786

787+
private static void setTransferParams(Tx tx, TriggerSmartContract triggerSmartContract) {
788+
try {
789+
byte[] data = triggerSmartContract.getData().toByteArray();
790+
byte[] methodId = Arrays.copyOfRange(data, 0, 4);
791+
if (TRANSFER_METHOD_ID.equals(Hex.toHexString(methodId))) {
792+
byte[] toBytes = Arrays.copyOfRange(data, 4, 36);
793+
byte[] addressBytes = Arrays.copyOfRange(toBytes, 12, 32);
794+
byte[] tronAddressBytes = new byte[21];
795+
tronAddressBytes[0] = 0x41;
796+
System.arraycopy(addressBytes, 0, tronAddressBytes, 1, 20);
797+
String to = encode58Check(tronAddressBytes);
798+
byte[] amountBytes = Arrays.copyOfRange(data, 36, 68);
799+
tx.setTo(to);
800+
tx.setAmount(parseAmountToLongStr(amountBytes));
801+
}
802+
} catch (Exception e) {
803+
System.out.println(e.getMessage());
804+
}
805+
}
806+
807+
public static String parseAmountToLongStr(byte[] amountBytes) {
808+
BigInteger amount = new BigInteger(1, amountBytes);
809+
if (amount.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
810+
System.out.println("Amount exceeds long capacity: " + amount);
811+
return DASH;
812+
}
813+
return String.valueOf(amount.longValue());
814+
}
815+
781816
public static JSONObject printTransactionToJSON(Protocol.Transaction transaction, boolean selfType) {
782817
JSONObject jsonTransaction =
783818
JSON.parseObject(JsonFormat.printToString(transaction, selfType));
@@ -1175,7 +1210,7 @@ public static void printBanner() {
11751210
try (InputStream inputStream = Client.class.getResourceAsStream("/banner.txt")) {
11761211
if (inputStream != null) {
11771212
String banner = new String(readAllBytes(inputStream), StandardCharsets.UTF_8);
1178-
System.out.println(blueBoldHighlight(banner));
1213+
System.out.println(blueBoldHighlight(banner) + blueBoldHighlight(VERSION));
11791214
} else {
11801215
System.out.println("No banner.txt found!");
11811216
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public List<BackupRecord> loadAllRecords() {
120120

121121
public List<BackupRecord> getRecordsByTimeRange(LocalDateTime start, LocalDateTime end) {
122122
return loadAllRecords().stream()
123-
.filter(br -> br.getTimestamp().isBefore(end))
124-
.filter(br -> br.getTimestamp().isAfter(start))
123+
.filter(br -> !br.getTimestamp().isBefore(start))
124+
.filter(br -> !br.getTimestamp().isAfter(end))
125125
.sorted(Comparator.comparing(BackupRecord::getTimestamp).reversed())
126126
.collect(Collectors.toList());
127127
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ public List<Tx> getUserTransactionsByTimeRange(NetType network, LocalDateTime st
144144
.filter(Optional::isPresent)
145145
.map(Optional::get)
146146
.filter(tx -> tx.isRelatedTo(currentUserAddress))
147-
.filter(tx -> tx.getTimestamp().isBefore(end))
148-
.filter(tx -> tx.getTimestamp().isAfter(start))
147+
.filter(tx -> !tx.getTimestamp().isBefore(start))
148+
.filter(tx -> !tx.getTimestamp().isAfter(end))
149149
.sorted(Comparator.comparing(Tx::getTimestamp).reversed())
150150
.skip((page - 1L) * PAGE_SIZE)
151151
.limit(PAGE_SIZE)
@@ -197,8 +197,8 @@ public int getUserTotalPagesByTimeRange(NetType network, LocalDateTime start, Lo
197197
.filter(Optional::isPresent)
198198
.map(Optional::get)
199199
.filter(tx -> tx.isRelatedTo(currentUserAddress))
200-
.filter(tx -> tx.getTimestamp().isBefore(end))
201-
.filter(tx -> tx.getTimestamp().isAfter(start))
200+
.filter(tx -> !tx.getTimestamp().isBefore(start))
201+
.filter(tx -> !tx.getTimestamp().isAfter(end))
202202
.count();
203203

204204
return (int) Math.ceil((double) count / PAGE_SIZE);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void startInteractiveViewer(NetType netType) {
4242

4343
private void printWelcome() {
4444
System.out.println("====================================");
45-
System.out.println(" COMPLETE TRANSACTION VIEWER");
45+
System.out.println(" TRANSACTION VIEWER");
4646
System.out.println("====================================");
4747
}
4848

@@ -168,10 +168,10 @@ private void printTransactionPage(List<Tx> transactions, int currentPage, int to
168168

169169
private void printHelp() {
170170
System.out.println("\n=== HELP ===");
171-
System.out.println("1. View all transactions - Shows complete transaction history");
171+
System.out.println("1. View all transactions - Shows transaction history");
172172
System.out.println("2. Filter by time range - Filters transactions between two timestamps");
173173
System.out.println("3. Help - Shows this help message");
174-
System.out.println("4. Exit - Quits the application");
174+
System.out.println("4. Exit - Quits the current view");
175175
System.out.println("\nWhile browsing pages:");
176176
System.out.println("n - Next page");
177177
System.out.println("p - Previous page");

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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.VERSION;
78
import static org.tron.common.utils.Utils.blueBoldHighlight;
89
import static org.tron.common.utils.Utils.failedHighlight;
910
import static org.tron.common.utils.Utils.getLong;
@@ -3371,12 +3372,13 @@ public static String[] getCmd(String cmdLine) {
33713372

33723373
private void run() {
33733374
if (version) {
3374-
System.out.println("Version 4.9.1");
3375+
System.out.println("Version" + VERSION);
33753376
System.exit(0);
33763377
}
3377-
System.out.println(" ");
3378+
System.out.println();
33783379
System.out.println("Welcome to Tron " + blueBoldHighlight("Wallet-Cli"));
33793380
printBanner();
3381+
System.out.println();
33803382
System.out.println("Please type one of the following commands to proceed.");
33813383
System.out.println(greenBoldHighlight("Login") + ", " + greenBoldHighlight("LoginAll")
33823384
+ ", " + greenBoldHighlight("RegisterWallet")

src/main/resources/banner.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
__ ____ _| | | ___| |_ ___| (_)
33
\ \ /\ / / _` | | |/ _ \ __|____ / __| | |
44
\ V V / (_| | | | __/ ||_____| (__| | |
5-
\_/\_/ \__,_|_|_|\___|\__| \___|_|_|
5+
\_/\_/ \__,_|_|_|\___|\__| \___|_|_|

src/main/resources/config.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ net {
44

55
fullnode = {
66
ip.list = [
7-
"127.0.0.1:50051"
7+
88
]
99
}
1010

src/main/resources/help_summary.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
| ExportWalletMnemonic | Export wallet mnemonic words |
141141
| BackupWallet | Backup the current wallet as private key |
142142
| BackupWallet2Base64 | Backup wallet in base64 format |
143-
| ViewBackupRecords | View transaction history |
143+
| ViewBackupRecords | View backup records |
144144
| ClearWalletKeystore | Delete the keystore file and mnemonic words file |
145145
| ResetWallet | Delete all keystore files and mnemonic words files |
146146
| CurrentNetwork | Display current network |

0 commit comments

Comments
 (0)