Skip to content

Commit 040c8de

Browse files
authored
Merge pull request #912 from tronprotocol/release_v4.9.3
Release v4.9.3
2 parents 86deadb + d89a4f2 commit 040c8de

23 files changed

Lines changed: 2878 additions & 423 deletions

README.md

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ grpc = {
6767
}
6868
}
6969
70+
# Set the maximum number of transactions and backup records that can be retained
71+
maxRecords = 1000
72+
73+
# To use the tronlink multi-sign feature, please first apply for an secretId and secretKey.
74+
# For details, please refer to
75+
# https://docs.google.com/forms/d/e/1FAIpQLSc5EB1X8JN7LA4SAVAG99VziXEY6Kv6JxmlBry9rUBlwI-GaQ/viewform
76+
# If you prefer not to apply, a speed-limited secretId and secretKey will be provided for use:
77+
# secretId = "TEST", secretKey = "TESTTESTTEST", channel = "test".
78+
tronlink = {
79+
mainnet = {
80+
secretId = ""
81+
secretKey = ""
82+
channel = ""
83+
}
84+
testnet = {
85+
secretId = ""
86+
secretKey = ""
87+
channel = ""
88+
}
89+
}
7090
```
7191

7292
### Run a web wallet
@@ -139,7 +159,8 @@ For more information on a specific command, just type the command in the termina
139159
| [UpdateAccountPermission](#How-to-use-the-multi-signature-feature-of-wallet-cli) | [UpdateAsset](#Update-parameters-of-trc10-token) | [UpdateBrokerage](#Brokerage) |
140160
| [UpdateEnergyLimit](#Update-smart-contract-parameters) | [UpdateSetting](#Update-smart-contract-parameters) | [UpdateWitness](#update-witness) |
141161
| [ViewBackupRecords](#View-backup-records) | [ViewTransactionHistory](#View-transaction-history) | [VoteWitness](#How-to-vote) |
142-
| [WithdrawBalance](#withdraw-balance) | [WithdrawExpireUnfreeze](#withdraw-expire-unfreeze) | |
162+
| [WithdrawBalance](#withdraw-balance) | [WithdrawExpireUnfreeze](#withdraw-expire-unfreeze) | [TronlinkMultiSign](#tronlink-multi-sign) |
163+
| [EncodingConverter](#encoding-converter) | [GetPrivateKeyByMnemonic](#How-to-get-privateKey-through-mnemonic) | |
143164

144165

145166
Type any one of the listed commands, to display how-to tips.
@@ -1803,7 +1824,6 @@ wallet> loginall
18031824
Please input your password.
18041825
password:
18051826
Use user defined config file in current dir
1806-
WalletApi getRpcVsersion: 2
18071827
[========================================] 100%
18081828
The 1th keystore file name is TJEEKTmaVTYSpJAxahtyuofnDSpe2seajB.json
18091829
The 2th keystore file name is TX1L9xonuUo1AHsjUZ3QzH8wCRmKm56Xew.json
@@ -2621,4 +2641,52 @@ After sign transaction hex string is 0ad4010a0208c72208c02252c2ae3b92e1409fb0b9d
26212641
TxId is 9c8d4b84e9a71ccaad86b0a96f790067d3fc7ea85c26b425e5d748b81d31a8b8
26222642
Transfer 1 to TR311sD6KasRnofj5RnFiFBA2rH8RH2kYk broadcast successful.
26232643
Please check the given transaction id to get the result on blockchain using getTransactionInfoById command.
2644+
```
2645+
### tronlink multi sign
2646+
> TronlinkMultiSign
2647+
2648+
Create multi sign transactions and view the multi sign transaction list through the tronlink service.
2649+
2650+
Example:
2651+
```console
2652+
wallet> tronlinkmultisign
2653+
2654+
=== Multi-Sign Manager ===
2655+
1. Multi-sign transaction list
2656+
2. Create multi-sign transaction
2657+
0. Exit
2658+
Please enter the number to operate:
2659+
```
2660+
2661+
### encoding converter
2662+
> EncodingConverter
2663+
2664+
A Useful Encoding Converter.
2665+
2666+
Example:
2667+
```console
2668+
wallet> EncodingConverter
2669+
2670+
==============================
2671+
Encoding Converter (CLI)
2672+
==============================
2673+
1) TRON - EVM Address
2674+
2) Base64 Encode / Decode
2675+
3) Base58Check Encode / Decode
2676+
4) Public Key -> Address
2677+
5) Private Key -> Public Key & Address
2678+
0) Exit
2679+
>
2680+
```
2681+
2682+
### How to get privateKey through mnemonic
2683+
> GetPrivateKeyByMnemonic
2684+
2685+
Get the private key through mnemonics.
2686+
2687+
Example:
2688+
```console
2689+
wallet> GetPrivateKeyByMnemonic
2690+
2691+
Please enter 12 or 24 words (separated by spaces) [Attempt 1/3]:
26242692
```

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ dependencies {
101101
exclude group: "com.google.guava", module: "guava"
102102
}
103103
implementation 'javax.annotation:javax.annotation-api:1.3.2'
104+
implementation 'org.java-websocket:Java-WebSocket:1.5.3'
104105
}
105106

106107
protobuf {

src/main/java/org/tron/common/enums/NetType.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ public enum NetType {
2020
"TFFAMQLZybALaLb4uxHA9RBE7pxhUAjF3U",
2121
"https://open.gasfree.io",
2222
"/tron"),
23-
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
24-
),
23+
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
24+
"https://api.walletadapter.org"),
2525
NILE("https://nile.trongrid.io",
2626
new Grpc(FULLNODE_NILE, FULLNODE_NILE_SOLIDITY),
2727
new GasFree(
2828
3448148188L,
2929
"THQGuFzL87ZqhxkgqYEryRAd7gqFqL5rdc",
3030
"https://open-test.gasfree.io",
3131
"/nile"),
32-
"TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf"
33-
),
32+
"TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf",
33+
"https://apinile.walletadapter.org"),
3434
SHASTA(
3535
"https://api.shasta.trongrid.io",
3636
new Grpc(TRONGRID_SHASTA, TRONGRID_SHASTA_SOLIDITY),
@@ -39,20 +39,22 @@ public enum NetType {
3939
"TSwCtDum13k1PodgNgTWx5be7k1c6eWaNP",
4040
"https://open-test.gasfree.io",
4141
"/shasta"),
42-
"TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs"
43-
),
44-
CUSTOM(null, null, null, null);
42+
"TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs",
43+
"https://apishasta.walletadapter.org"),
44+
CUSTOM(null, null, null, null, null);
4545

4646
private final String http;
4747
private final Grpc grpc;
4848
private final GasFree gasFree;
4949
private final String usdtAddress;
50+
private final String tronlinkUrl;
5051

51-
NetType(String http, Grpc grpc, GasFree gasFree, String usdtAddress) {
52+
NetType(String http, Grpc grpc, GasFree gasFree, String usdtAddress, String tronlinkUrl) {
5253
this.http = http;
5354
this.grpc = grpc;
5455
this.gasFree = gasFree;
5556
this.usdtAddress = usdtAddress;
57+
this.tronlinkUrl = tronlinkUrl;
5658
}
5759

5860
@Setter

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.ArrayList;
2828
import java.util.Arrays;
2929
import java.util.List;
30+
import org.apache.commons.lang3.ArrayUtils;
3031
import org.apache.commons.lang3.StringUtils;
3132
import org.bouncycastle.util.encoders.Hex;
3233

@@ -439,6 +440,24 @@ public static List<Integer> hexStringToIntegerList(String hexString) {
439440
return result;
440441
}
441442

443+
public static List<Integer> bytesToIntegerList(byte[] bytes) {
444+
List<Integer> result = new ArrayList<>();
445+
if (ArrayUtils.isEmpty(bytes)) {
446+
return result;
447+
}
448+
for (int byteIndex = 0; byteIndex < bytes.length; byteIndex++) {
449+
byte currentByte = bytes[byteIndex];
450+
451+
for (int bitIndex = 0; bitIndex < 8; bitIndex++) {
452+
if ((currentByte & (1 << bitIndex)) != 0) {
453+
int value = byteIndex * 8 + bitIndex;
454+
result.add(value);
455+
}
456+
}
457+
}
458+
return result;
459+
}
460+
442461
public static String integerListToHexString(List<Integer> currentOps) {
443462
byte[] operations = new byte[32];
444463
currentOps.forEach(e -> operations[e / 8] |= (1 << e % 8));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private static String responseBodyToString(Response response) throws IOException
7575
}).orElse(EMPTY);
7676
}
7777
if (response.code() == 502) {
78-
throw new IOException("Unexpected HTTP code " + response.code() + ": Bad Gateway.");
78+
throw new IOException("Unexpected HTTP code " + response.code() + ": Bad Gateway. Please try again later.");
7979
}
8080
throw new IOException(
8181
"Unexpected HTTP code " + response.code() + ": " + msg + "\nAPI authentication failed, "
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package org.tron.common.utils;
2+
3+
import static org.tron.common.utils.Utils.greenBoldHighlight;
4+
import static org.tron.common.utils.Utils.yellowBoldHighlight;
5+
6+
import com.alibaba.fastjson.JSON;
7+
import com.alibaba.fastjson.JSONArray;
8+
import com.alibaba.fastjson.JSONObject;
9+
import java.net.URI;
10+
import java.util.Map;
11+
import org.java_websocket.client.WebSocketClient;
12+
import org.java_websocket.handshake.ServerHandshake;
13+
import org.jline.reader.LineReader;
14+
15+
public class MultiTxWebSocketClient extends WebSocketClient {
16+
17+
private final LineReader lineReader;
18+
private final String subscribeJson;
19+
20+
public MultiTxWebSocketClient(URI serverUri, Map<String, String> headers,
21+
LineReader lineReader,
22+
String address) {
23+
super(serverUri, headers);
24+
this.lineReader = lineReader;
25+
this.subscribeJson = String.format(
26+
"{\"address\":\"%s\",\"version\":\"v1\"}", address
27+
);
28+
}
29+
30+
@Override
31+
public void onOpen(ServerHandshake handshake) {
32+
send(subscribeJson);
33+
34+
// lineReader.printAbove(
35+
// greenBoldHighlight("🔗 WebSocket connected, subscribed address")
36+
// );
37+
}
38+
39+
public static boolean isJsonArray(String str) {
40+
if (str == null) return false;
41+
42+
str = str.trim();
43+
if (!str.startsWith("[") || !str.endsWith("]")) {
44+
return false;
45+
}
46+
47+
try {
48+
JSON.parseArray(str);
49+
return true;
50+
} catch (Exception e) {
51+
return false;
52+
}
53+
}
54+
55+
@Override
56+
public void onMessage(String message) {
57+
if (!isJsonArray(message)) {
58+
return;
59+
}
60+
JSONArray jsonArray = JSON.parseArray(message);
61+
long count = jsonArray.stream()
62+
.map(o -> (JSONObject) o)
63+
.filter(obj -> obj.getIntValue("is_sign") == 0
64+
&& obj.getIntValue("state") == 0)
65+
.count();
66+
if (count > 0) {
67+
lineReader.printAbove(
68+
yellowBoldHighlight("🔔 New message: ") + "You have " + count + " transaction(s) to be signed, please view it through the " + greenBoldHighlight("TronlinkMultiSign") + " command."
69+
);
70+
}
71+
}
72+
73+
@Override
74+
public void onClose(int code, String reason, boolean remote) {
75+
// lineReader.printAbove(
76+
// redBoldHighlight("❌ WebSocket closed: " + reason)
77+
// );
78+
}
79+
80+
@Override
81+
public void onError(Exception ex) {
82+
// lineReader.printAbove(
83+
// redBoldHighlight("❌ WebSocket error: " + ex.getMessage())
84+
// );
85+
}
86+
}
87+
88+

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Arrays;
2222
import java.util.List;
2323
import java.util.Scanner;
24+
import org.bouncycastle.util.encoders.Hex;
2425
import org.tron.common.crypto.ECKey;
2526
import org.tron.common.crypto.ECKey.ECDSASignature;
2627
import org.tron.common.crypto.Sha256Sm3Hash;
@@ -69,6 +70,11 @@ public static Sha256Hash getTransactionId(Chain.Transaction transaction) {
6970
return Sha256Hash.of(true, transaction.getRawData().toByteArray());
7071
}
7172

73+
public static Sha256Hash getTransactionId(String rawDataHex) {
74+
byte[] raw = Hex.decode(rawDataHex);
75+
return Sha256Hash.of(true, raw);
76+
}
77+
7278
public static byte[] getOwner(Transaction.Contract contract) {
7379
ByteString owner;
7480
try {
@@ -364,9 +370,9 @@ public static Chain.Transaction setTimestamp(Chain.Transaction transaction) {
364370
return builder.build();
365371
}
366372

367-
public static Chain.Transaction setExpirationTime(Chain.Transaction transaction) {
373+
public static Chain.Transaction setExpirationTime(Chain.Transaction transaction, boolean multi) {
368374
if (transaction.getSignatureCount() == 0) {
369-
long expirationTime = System.currentTimeMillis() + 6 * 60 * 60 * 1000;
375+
long expirationTime = System.currentTimeMillis() + (multi ? 24L * 3600 * 1000 : 6 * 60 * 60 * 1000);
370376
Chain.Transaction.Builder builder = transaction.toBuilder();
371377
Chain.Transaction.raw.Builder rowBuilder =
372378
transaction.getRawData().toBuilder();

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static org.apache.commons.lang3.StringUtils.EMPTY;
2222
import static org.apache.commons.lang3.StringUtils.isEmpty;
23+
import static org.apache.commons.lang3.StringUtils.isNoneBlank;
2324
import static org.tron.common.utils.ByteArray.toHexString;
2425
import static org.tron.common.utils.DomainValidator.isDomainOrIP;
2526
import static org.tron.core.manager.TxHistoryManager.DASH;
@@ -59,6 +60,7 @@
5960
import java.util.regex.Pattern;
6061
import java.util.stream.Collectors;
6162
import java.util.stream.IntStream;
63+
import org.apache.commons.lang3.tuple.Triple;
6264
import org.bouncycastle.util.encoders.Hex;
6365
import org.jetbrains.annotations.Nullable;
6466
import org.tron.api.GrpcAPI.BlockExtention;
@@ -132,7 +134,7 @@ public class Utils {
132134

133135
public static final int MIN_LENGTH = 2;
134136
public static final int MAX_LENGTH = 14;
135-
public static final String VERSION = " v4.9.2";
137+
public static final String VERSION = " v4.9.3";
136138
public static final String TRANSFER_METHOD_ID = "a9059cbb";
137139

138140
private static SecureRandom random = new SecureRandom();
@@ -612,7 +614,7 @@ public static Tx getTx(Chain.Transaction transaction) {
612614
tx.setFrom(encode58Check(triggerSmartContract.getOwnerAddress().toByteArray()));
613615
tx.setTo(encode58Check(triggerSmartContract.getContractAddress().toByteArray()));
614616
NetType netType = WalletApi.getCurrentNetwork();
615-
if (netType.getUsdtAddress().equals(encode58Check(triggerSmartContract.getContractAddress().toByteArray()))) {
617+
if (org.apache.commons.lang3.StringUtils.equals(netType.getUsdtAddress(), encode58Check(triggerSmartContract.getContractAddress().toByteArray()))) {
616618
setTransferParams(tx, triggerSmartContract);
617619
tx.setType(contract.getType().name() + "(transferUSDT)");
618620
}
@@ -1504,4 +1506,17 @@ private static boolean containsChinese(String str) {
15041506
);
15051507
}
15061508

1509+
public static String intToBooleanString(int value) {
1510+
return value == 1 ? "true" : "false";
1511+
}
1512+
1513+
public static boolean allNotBlank(Triple<String, String, String> triple) {
1514+
return triple != null
1515+
&& isNoneBlank(
1516+
triple.getLeft(),
1517+
triple.getMiddle(),
1518+
triple.getRight()
1519+
);
1520+
}
1521+
15071522
}

0 commit comments

Comments
 (0)