|
22 | 22 | import static org.apache.commons.lang3.StringUtils.isEmpty; |
23 | 23 | import static org.tron.common.utils.ByteArray.toHexString; |
24 | 24 | import static org.tron.common.utils.DomainValidator.isDomainOrIP; |
| 25 | +import static org.tron.core.manager.TxHistoryManager.DASH; |
25 | 26 | import static org.tron.keystore.StringUtils.byte2String; |
26 | 27 | import static org.tron.ledger.console.ConsoleColor.ANSI_BLUE; |
27 | 28 | import static org.tron.ledger.console.ConsoleColor.ANSI_BOLD; |
|
42 | 43 | import java.io.Console; |
43 | 44 | import java.io.IOException; |
44 | 45 | import java.io.InputStream; |
| 46 | +import java.math.BigInteger; |
45 | 47 | import java.nio.ByteBuffer; |
46 | 48 | import java.nio.CharBuffer; |
47 | 49 | import java.nio.charset.Charset; |
|
57 | 59 | import java.util.regex.Pattern; |
58 | 60 | import java.util.stream.Collectors; |
59 | 61 | import java.util.stream.IntStream; |
| 62 | +import org.bouncycastle.util.encoders.Hex; |
60 | 63 | import org.jetbrains.annotations.Nullable; |
61 | 64 | import org.tron.api.GrpcAPI.BlockExtention; |
62 | 65 | import org.tron.api.GrpcAPI.BlockList; |
@@ -128,6 +131,8 @@ public class Utils { |
128 | 131 |
|
129 | 132 | public static final int MIN_LENGTH = 2; |
130 | 133 | 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"; |
131 | 136 |
|
132 | 137 | private static SecureRandom random = new SecureRandom(); |
133 | 138 |
|
@@ -605,6 +610,7 @@ public static Tx getTx(Chain.Transaction transaction) { |
605 | 610 | tx.setType(contract.getType().name()); |
606 | 611 | tx.setFrom(encode58Check(triggerSmartContract.getOwnerAddress().toByteArray())); |
607 | 612 | tx.setTo(encode58Check(triggerSmartContract.getContractAddress().toByteArray())); |
| 613 | + setTransferParams(tx, triggerSmartContract); |
608 | 614 | break; |
609 | 615 | case UpdateSettingContract: |
610 | 616 | UpdateSettingContract updateSettingContract = |
@@ -778,6 +784,35 @@ public static Tx getTx(Chain.Transaction transaction) { |
778 | 784 | return tx; |
779 | 785 | } |
780 | 786 |
|
| 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 | + |
781 | 816 | public static JSONObject printTransactionToJSON(Protocol.Transaction transaction, boolean selfType) { |
782 | 817 | JSONObject jsonTransaction = |
783 | 818 | JSON.parseObject(JsonFormat.printToString(transaction, selfType)); |
@@ -1175,7 +1210,7 @@ public static void printBanner() { |
1175 | 1210 | try (InputStream inputStream = Client.class.getResourceAsStream("/banner.txt")) { |
1176 | 1211 | if (inputStream != null) { |
1177 | 1212 | String banner = new String(readAllBytes(inputStream), StandardCharsets.UTF_8); |
1178 | | - System.out.println(blueBoldHighlight(banner)); |
| 1213 | + System.out.println(blueBoldHighlight(banner) + blueBoldHighlight(VERSION)); |
1179 | 1214 | } else { |
1180 | 1215 | System.out.println("No banner.txt found!"); |
1181 | 1216 | } |
|
0 commit comments