Skip to content
272 changes: 230 additions & 42 deletions README.md

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/main/java/org/tron/common/enums/NetType.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ public enum NetType {
728126428L,
"TFFAMQLZybALaLb4uxHA9RBE7pxhUAjF3U",
"https://open.gasfree.io",
"/tron")
"/tron"),
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
),
NILE("https://nile.trongrid.io",
new Grpc(FULLNODE_NILE, FULLNODE_NILE_SOLIDITY),
new GasFree(
3448148188L,
"THQGuFzL87ZqhxkgqYEryRAd7gqFqL5rdc",
"https://open-test.gasfree.io",
"/nile")
"/nile"),
"TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf"
),
SHASTA(
"https://api.shasta.trongrid.io",
Expand All @@ -36,18 +38,21 @@ public enum NetType {
2494104990L,
"TSwCtDum13k1PodgNgTWx5be7k1c6eWaNP",
"https://open-test.gasfree.io",
"/shasta")
"/shasta"),
"TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs"
),
CUSTOM(null, null, null);
CUSTOM(null, null, null, null);

private final String http;
private final Grpc grpc;
private final GasFree gasFree;
private final String usdtAddress;

NetType(String http, Grpc grpc, GasFree gasFree) {
NetType(String http, Grpc grpc, GasFree gasFree, String usdtAddress) {
this.http = http;
this.grpc = grpc;
this.gasFree = gasFree;
this.usdtAddress = usdtAddress;
}

@Setter
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/org/tron/common/utils/ByteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

package org.tron.common.utils;

import static org.tron.trident.utils.Numeric.hexStringToByteArray;

import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedBytes;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.bouncycastle.util.encoders.Hex;

public class ByteUtil {
Expand Down Expand Up @@ -415,4 +418,31 @@ public static List<Boolean> convertBytesVectorToVector(final byte[] bytes) {
return ret;
}

public static List<Integer> hexStringToIntegerList(String hexString) {
List<Integer> result = new ArrayList<>();
if (StringUtils.isEmpty(hexString)) {
return result;
}
byte[] bytes = hexStringToByteArray(hexString);

for (int byteIndex = 0; byteIndex < bytes.length; byteIndex++) {
byte currentByte = bytes[byteIndex];

for (int bitIndex = 0; bitIndex < 8; bitIndex++) {
if ((currentByte & (1 << bitIndex)) != 0) {
int value = byteIndex * 8 + bitIndex;
result.add(value);
}
}
}

return result;
}

public static String integerListToHexString(List<Integer> currentOps) {
byte[] operations = new byte[32];
currentOps.forEach(e -> operations[e / 8] |= (1 << e % 8));
return Hex.toHexString(operations);
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/tron/common/utils/JsonFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ private void write(CharSequence data, int size) throws IOException {
*/
protected static class Tokenizer {

// We use possesive quantifiers (*+ and ++) because otherwise the Java
// We use possessive quantifiers (*+ and ++) because otherwise the Java
// regex matcher has stack overflows on large inputs.
private static final Pattern WHITESPACE =
Pattern.compile("(\\s|(#.*$))++", Pattern.MULTILINE);
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/tron/common/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.tron.api.GrpcAPI.TransactionSignWeight;
import org.tron.common.crypto.Hash;
import org.tron.common.crypto.Sha256Sm3Hash;
import org.tron.common.enums.NetType;
import org.tron.core.dao.Tx;
import org.tron.keystore.StringUtils;
import org.tron.keystore.WalletFile;
Expand Down Expand Up @@ -131,7 +132,7 @@ public class Utils {

public static final int MIN_LENGTH = 2;
public static final int MAX_LENGTH = 14;
public static final String VERSION = " v4.9.1";
public static final String VERSION = " v4.9.2";
public static final String TRANSFER_METHOD_ID = "a9059cbb";

private static SecureRandom random = new SecureRandom();
Expand Down Expand Up @@ -610,7 +611,11 @@ public static Tx getTx(Chain.Transaction transaction) {
tx.setType(contract.getType().name());
tx.setFrom(encode58Check(triggerSmartContract.getOwnerAddress().toByteArray()));
tx.setTo(encode58Check(triggerSmartContract.getContractAddress().toByteArray()));
// setTransferParams(tx, triggerSmartContract);
NetType netType = WalletApi.getCurrentNetwork();
if (netType.getUsdtAddress().equals(encode58Check(triggerSmartContract.getContractAddress().toByteArray()))) {
setTransferParams(tx, triggerSmartContract);
tx.setType(contract.getType().name() + "(transferUSDT)");
}
break;
case UpdateSettingContract:
UpdateSettingContract updateSettingContract =
Expand Down Expand Up @@ -1179,6 +1184,10 @@ public static String greenBoldHighlight(int i) {
return ANSI_BOLD + ANSI_GREEN + i + ANSI_RESET;
}

public static String greenBoldHighlight(long i) {
return ANSI_BOLD + ANSI_GREEN + i + ANSI_RESET;
}

public static String blueBoldHighlight(String str) {
return ANSI_BOLD + ANSI_BLUE + str + ANSI_RESET;
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/tron/core/dao/AddressEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.tron.core.dao;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class AddressEntry {
private String name;
private String address;
private String note;

public AddressEntry(String name, String address, String note) {
this.name = name;
this.address = address;
this.note = note;
}

@Override
public String toString() {
return String.format("%-15s %-35s %s", name, address, note == null ? "" : note);
}

public String toFileString() {
return String.join(",", name, address, note == null ? "" : note);
}

public String getDisplayString(int index) {
return String.format("%d. %s (%s) - %s", index, name, address, note);
}
}
10 changes: 7 additions & 3 deletions src/main/java/org/tron/core/manager/TxHistoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ public class TxHistoryManager {
}
}

public TxHistoryManager() {
this.currentUserAddress = null;
}

public TxHistoryManager(String currentUserAddress) {
this.currentUserAddress = Objects.requireNonNull(currentUserAddress);
ensureBaseDirectoryExists();
}

private Path getNetworkFilePath(NetType network) {
public Path getNetworkFilePath(NetType network) {
return Paths.get(BASE_DIR, network.name(), HISTORY_FILE);
}

private void ensureNetworkDirectoryExists(NetType network) {
public void ensureNetworkDirectoryExists(NetType network) {
try {
Files.createDirectories(Paths.get(BASE_DIR, network.name()));
} catch (IOException e) {
Expand Down Expand Up @@ -240,7 +244,7 @@ private String txToLine(Tx tx) {
);
}

private Optional<Tx> lineToTx(String line) {
public Optional<Tx> lineToTx(String line) {
try {
String[] parts = line.split(",");
if (parts.length != 8) return Optional.empty();
Expand Down
Loading