Skip to content

Commit ab2c86e

Browse files
authored
Merge pull request #859 from tronprotocol/release_v4.9.0
Release v4.9.0
2 parents b2f3b98 + e54eb47 commit ab2c86e

32 files changed

+3270
-9339
lines changed

README.md

Lines changed: 258 additions & 1057 deletions
Large diffs are not rendered by default.

build.gradle

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
maven {
5+
url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
6+
}
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
// classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0'
12+
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18'
13+
classpath "com.github.node-gradle:gradle-node-plugin:7.1.0"
14+
}
15+
}
16+
17+
plugins {
18+
id 'com.github.johnrengelman.shadow' version '7.1.2'
19+
}
20+
121
group 'Tron'
222
version '1.0-SNAPSHOT'
323

@@ -38,23 +58,6 @@ sourceSets {
3858
}
3959
}
4060

41-
buildscript {
42-
repositories {
43-
mavenLocal()
44-
maven {
45-
url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
46-
}
47-
mavenCentral()
48-
}
49-
50-
dependencies {
51-
classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
52-
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.12'
53-
classpath "gradle.plugin.com.liferay:gradle-plugins-node:7.0.2"
54-
}
55-
}
56-
57-
5861
dependencies {
5962
implementation group: 'junit', name: 'junit', version: '4.13.2'
6063
implementation group: 'com.beust', name: 'jcommander', version: '1.82'
@@ -97,7 +100,7 @@ dependencies {
97100
implementation("io.github.tronprotocol:trident:0.10.0") {
98101
exclude group: "com.google.guava", module: "guava"
99102
}
100-
103+
implementation 'javax.annotation:javax.annotation-api:1.3.2'
101104
}
102105

103106
protobuf {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
package org.tron.common.enums;
22

3+
import static org.tron.trident.core.Constant.FULLNODE_NILE;
4+
import static org.tron.trident.core.Constant.FULLNODE_NILE_SOLIDITY;
5+
import static org.tron.trident.core.Constant.TRONGRID_MAIN_NET;
6+
import static org.tron.trident.core.Constant.TRONGRID_MAIN_NET_SOLIDITY;
7+
import static org.tron.trident.core.Constant.TRONGRID_SHASTA;
8+
import static org.tron.trident.core.Constant.TRONGRID_SHASTA_SOLIDITY;
9+
310
import lombok.Getter;
411
import lombok.Setter;
512

613
@Getter
714
public enum NetType {
815
MAIN(
916
"https://api.trongrid.io",
10-
new Grpc("grpc.trongrid.io:50051", "grpc.trongrid.io:50052"),
17+
new Grpc(TRONGRID_MAIN_NET, TRONGRID_MAIN_NET_SOLIDITY),
1118
new GasFree(
1219
728126428L,
1320
"TFFAMQLZybALaLb4uxHA9RBE7pxhUAjF3U",
1421
"https://open.gasfree.io",
1522
"/tron")
1623
),
1724
NILE("https://nile.trongrid.io",
18-
new Grpc("grpc.nile.trongrid.io:50051", "grpc.nile.trongrid.io:50061"),
25+
new Grpc(FULLNODE_NILE, FULLNODE_NILE_SOLIDITY),
1926
new GasFree(
2027
3448148188L,
2128
"THQGuFzL87ZqhxkgqYEryRAd7gqFqL5rdc",
@@ -24,7 +31,7 @@ public enum NetType {
2431
),
2532
SHASTA(
2633
"https://api.shasta.trongrid.io",
27-
new Grpc("grpc.shasta.trongrid.io:50051", "grpc.shasta.trongrid.io:50052"),
34+
new Grpc(TRONGRID_SHASTA, TRONGRID_SHASTA_SOLIDITY),
2835
new GasFree(
2936
2494104990L,
3037
"TSwCtDum13k1PodgNgTWx5be7k1c6eWaNP",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,9 @@ public static String parseMethod(String methodSign, String input, boolean isHex)
347347
if (isHex) {
348348
return Hex.toHexString(selector) + input;
349349
}
350-
byte[] encodedParms = encodeInput(methodSign, input);
350+
byte[] encodedParams = encodeInput(methodSign, input);
351351

352-
return Hex.toHexString(selector) + Hex.toHexString(encodedParms);
352+
return Hex.toHexString(selector) + Hex.toHexString(encodedParams);
353353
}
354354

355355
public static byte[] encodeInput(String methodSign, String input) {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.tron.common.utils;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.io.InputStreamReader;
7+
import java.util.ArrayList;
8+
import java.util.HashMap;
9+
import java.util.List;
10+
import java.util.Map;
11+
12+
public class CommandHelpUtil {
13+
private static final Map<String, CommandHelp> commandHelps = new HashMap<>();
14+
15+
static {
16+
try {
17+
loadCommandExamples();
18+
} catch (IOException e) {
19+
System.out.println(e.getMessage());
20+
}
21+
}
22+
23+
private static class CommandHelp {
24+
String syntax;
25+
String summary;
26+
List<String> examples = new ArrayList<>();
27+
28+
@Override
29+
public String toString() {
30+
StringBuilder sb = new StringBuilder();
31+
sb.append("Syntax:\n").append(syntax);
32+
if (summary != null && !summary.isEmpty()) {
33+
sb.append("\nSummary:\n").append(summary);
34+
}
35+
sb.append("\nUsage examples:");
36+
for (String example : examples) {
37+
sb.append("\n").append(example);
38+
}
39+
return sb + "\n";
40+
}
41+
}
42+
43+
public static void loadCommandExamples() throws IOException {
44+
InputStream inputStream = CommandHelpUtil.class.getResourceAsStream("/commands.txt");
45+
if (inputStream == null) {
46+
System.err.println("Cannot find commands.txt file");
47+
return;
48+
}
49+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
50+
String line;
51+
CommandHelp currentHelp = null;
52+
String currentSection = null;
53+
54+
while ((line = reader.readLine()) != null) {
55+
if (line.startsWith("Syntax:")) {
56+
currentHelp = new CommandHelp();
57+
currentSection = "syntax";
58+
} else if (line.startsWith("Summary:")) {
59+
currentSection = "summary";
60+
} else if (line.startsWith("Usage example:")) {
61+
currentSection = "example";
62+
} else if (line.startsWith("wallet> ") && currentHelp != null) {
63+
currentHelp.examples.add(line);
64+
if (currentHelp.examples.size() == 1) {
65+
String command = line.substring("wallet> ".length()).split("\\s+")[0];
66+
commandHelps.put(command.toLowerCase(), currentHelp);
67+
}
68+
} else if (currentHelp != null && currentSection != null) {
69+
switch (currentSection) {
70+
case "syntax":
71+
currentHelp.syntax = (currentHelp.syntax == null ? "" : currentHelp.syntax + "\n") + line;
72+
break;
73+
case "summary":
74+
currentHelp.summary = (currentHelp.summary == null ? "" : currentHelp.summary + "\n") + line;
75+
break;
76+
}
77+
}
78+
}
79+
}
80+
}
81+
82+
public static String getCommandHelp(String command) {
83+
CommandHelp help = commandHelps.get(command);
84+
return help != null ? help.toString() : "No help found for command: " + command;
85+
}
86+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import static org.tron.common.utils.Utils.greenBoldHighlight;
55

66
import java.io.IOException;
7+
import java.security.Provider;
8+
import java.security.Security;
79
import java.util.Map;
810
import java.util.Optional;
911
import java.util.concurrent.TimeUnit;
@@ -17,6 +19,14 @@
1719

1820
public class HttpUtils {
1921

22+
static {
23+
Provider sunEc = Security.getProvider("SunEC");
24+
if (sunEc != null) {
25+
Security.removeProvider("SunEC");
26+
Security.insertProviderAt(sunEc, 1);
27+
}
28+
}
29+
2030
private static final OkHttpClient client = new OkHttpClient.Builder()
2131
.connectTimeout(10, TimeUnit.SECONDS)
2232
.readTimeout(15, TimeUnit.SECONDS)

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.tron.common.utils;
1717

1818
import com.google.protobuf.ByteString;
19+
import com.google.protobuf.InvalidProtocolBufferException;
1920
import java.security.SignatureException;
2021
import java.util.Arrays;
2122
import java.util.List;
@@ -47,6 +48,7 @@
4748
import org.tron.protos.contract.VoteAssetContractOuterClass.VoteAssetContract;
4849
import org.tron.protos.contract.WitnessContract.VoteWitnessContract;
4950
import org.tron.protos.contract.WitnessContract.WitnessCreateContract;
51+
import org.tron.trident.proto.Chain;
5052

5153
public class TransactionUtils {
5254

@@ -63,7 +65,7 @@ public static byte[] getHash(Transaction transaction) {
6365
return Sha256Sm3Hash.hash(tmp.build().toByteArray());
6466
}
6567

66-
public static Sha256Hash getTransactionId(Transaction transaction) {
68+
public static Sha256Hash getTransactionId(Chain.Transaction transaction) {
6769
return Sha256Hash.of(true, transaction.getRawData().toByteArray());
6870
}
6971

@@ -326,6 +328,12 @@ public static boolean validTransaction(Transaction signedTransaction) {
326328
return true;
327329
}
328330

331+
public static Chain.Transaction sign(Chain.Transaction transaction, SignInterface myKey)
332+
throws InvalidProtocolBufferException {
333+
return Chain.Transaction.parseFrom(
334+
sign(Transaction.parseFrom(transaction.toByteArray()), myKey).toByteArray());
335+
}
336+
329337
public static Transaction sign(Transaction transaction, SignInterface myKey) {
330338
Transaction.Builder transactionBuilderSigned = transaction.toBuilder();
331339
byte[] hash = Sha256Sm3Hash.hash(transaction.getRawData().toByteArray());
@@ -339,18 +347,28 @@ public static Transaction sign(Transaction transaction, SignInterface myKey) {
339347
public static Transaction setTimestamp(Transaction transaction) {
340348
long currentTime = System.currentTimeMillis(); // *1000000 + System.nanoTime()%1000000;
341349
Transaction.Builder builder = transaction.toBuilder();
342-
org.tron.protos.Protocol.Transaction.raw.Builder rowBuilder =
350+
Transaction.raw.Builder rowBuilder =
343351
transaction.getRawData().toBuilder();
344352
rowBuilder.setTimestamp(currentTime);
345353
builder.setRawData(rowBuilder.build());
346354
return builder.build();
347355
}
348356

349-
public static Transaction setExpirationTime(Transaction transaction) {
357+
public static Chain.Transaction setTimestamp(Chain.Transaction transaction) {
358+
long currentTime = System.currentTimeMillis(); // *1000000 + System.nanoTime()%1000000;
359+
Chain.Transaction.Builder builder = transaction.toBuilder();
360+
Chain.Transaction.raw.Builder rowBuilder =
361+
transaction.getRawData().toBuilder();
362+
rowBuilder.setTimestamp(currentTime);
363+
builder.setRawData(rowBuilder.build());
364+
return builder.build();
365+
}
366+
367+
public static Chain.Transaction setExpirationTime(Chain.Transaction transaction) {
350368
if (transaction.getSignatureCount() == 0) {
351369
long expirationTime = System.currentTimeMillis() + 6 * 60 * 60 * 1000;
352-
Transaction.Builder builder = transaction.toBuilder();
353-
org.tron.protos.Protocol.Transaction.raw.Builder rowBuilder =
370+
Chain.Transaction.Builder builder = transaction.toBuilder();
371+
Chain.Transaction.raw.Builder rowBuilder =
354372
transaction.getRawData().toBuilder();
355373
rowBuilder.setExpiration(expirationTime);
356374
builder.setRawData(rowBuilder.build());
@@ -359,6 +377,12 @@ public static Transaction setExpirationTime(Transaction transaction) {
359377
return transaction;
360378
}
361379

380+
public static Chain.Transaction setPermissionId(Chain.Transaction transaction, String tipString)
381+
throws CancelException, InvalidProtocolBufferException {
382+
return Chain.Transaction.parseFrom(
383+
setPermissionId(Transaction.parseFrom(transaction.toByteArray()), tipString).toByteArray());
384+
}
385+
362386
public static Transaction setPermissionId(Transaction transaction, String tipString)
363387
throws CancelException {
364388
if (transaction.getSignatureCount() != 0

0 commit comments

Comments
 (0)