Skip to content

Commit b89790c

Browse files
BarbatosBarbatos
authored andcommitted
refactor(crypto): remove unused web3j-era helpers from WalletUtils
The following methods had no production callers after the keystore refactor — the only reference was a coverage-padding test at SupplementTest.testGet (no assertions, just "call these to bump the coverage number") plus internal self-references: - generateFullNewWalletFile(String, File, boolean) - generateLightNewWalletFile(String, File, boolean) - generateNewWalletFile(String, File, boolean, boolean) - getDefaultKeyDirectory() / getDefaultKeyDirectory(String) - getTestnetKeyDirectory() - getMainnetKeyDirectory() The three generate* wrappers were identical calls into the real generateWalletFile(String, SignInterface, File, boolean) (which is kept and actively used). The three getDirectory helpers returned Ethereum- style paths (~/Library/Ethereum, %APPDATA%/Ethereum, ~/.ethereum) — hard-coded from the web3j origin of this code, never applicable in a TRON context, and capable of misleading anyone who tried to use them. Also drops the corresponding five noop invocations from SupplementTest.testGet and its now-unused WalletUtils import (the static import of passwordValid elsewhere in the file is preserved — it's still exercised by testPasswordValid). No production behavior change. Reduces the crypto module's public API surface and keeps the keystore library focused on what TRON actually uses.
1 parent fc6ab92 commit b89790c

2 files changed

Lines changed: 0 additions & 64 deletions

File tree

crypto/src/main/java/org/tron/keystore/WalletUtils.java

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
import java.nio.file.StandardCopyOption;
1313
import java.nio.file.attribute.PosixFilePermission;
1414
import java.nio.file.attribute.PosixFilePermissions;
15-
import java.security.InvalidAlgorithmParameterException;
16-
import java.security.NoSuchAlgorithmException;
17-
import java.security.NoSuchProviderException;
1815
import java.time.ZoneOffset;
1916
import java.time.ZonedDateTime;
2017
import java.time.format.DateTimeFormatter;
@@ -24,8 +21,6 @@
2421
import java.util.Set;
2522
import org.apache.commons.lang3.StringUtils;
2623
import org.tron.common.crypto.SignInterface;
27-
import org.tron.common.crypto.SignUtils;
28-
import org.tron.common.utils.Utils;
2924
import org.tron.core.exception.CipherException;
3025

3126
/**
@@ -44,31 +39,6 @@ public class WalletUtils {
4439
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
4540
}
4641

47-
public static String generateFullNewWalletFile(String password, File destinationDirectory,
48-
boolean ecKey)
49-
throws NoSuchAlgorithmException, NoSuchProviderException,
50-
InvalidAlgorithmParameterException, CipherException, IOException {
51-
52-
return generateNewWalletFile(password, destinationDirectory, true, ecKey);
53-
}
54-
55-
public static String generateLightNewWalletFile(String password, File destinationDirectory,
56-
boolean ecKey)
57-
throws NoSuchAlgorithmException, NoSuchProviderException,
58-
InvalidAlgorithmParameterException, CipherException, IOException {
59-
60-
return generateNewWalletFile(password, destinationDirectory, false, ecKey);
61-
}
62-
63-
public static String generateNewWalletFile(
64-
String password, File destinationDirectory, boolean useFullScrypt, boolean ecKey)
65-
throws CipherException, IOException, InvalidAlgorithmParameterException,
66-
NoSuchAlgorithmException, NoSuchProviderException {
67-
68-
SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(), ecKey);
69-
return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt);
70-
}
71-
7242
public static String generateWalletFile(
7343
String password, SignInterface ecKeyPair, File destinationDirectory, boolean useFullScrypt)
7444
throws CipherException, IOException {
@@ -159,33 +129,6 @@ public static String getWalletFileName(WalletFile walletFile) {
159129
return now.format(format) + walletFile.getAddress() + ".json";
160130
}
161131

162-
public static String getDefaultKeyDirectory() {
163-
return getDefaultKeyDirectory(System.getProperty("os.name"));
164-
}
165-
166-
static String getDefaultKeyDirectory(String osName1) {
167-
String osName = osName1.toLowerCase();
168-
169-
if (osName.startsWith("mac")) {
170-
return String.format(
171-
"%s%sLibrary%sEthereum", System.getProperty("user.home"), File.separator,
172-
File.separator);
173-
} else if (osName.startsWith("win")) {
174-
return String.format("%s%sEthereum", System.getenv("APPDATA"), File.separator);
175-
} else {
176-
return String.format("%s%s.ethereum", System.getProperty("user.home"), File.separator);
177-
}
178-
}
179-
180-
public static String getTestnetKeyDirectory() {
181-
return String.format(
182-
"%s%stestnet%skeystore", getDefaultKeyDirectory(), File.separator, File.separator);
183-
}
184-
185-
public static String getMainnetKeyDirectory() {
186-
return String.format("%s%skeystore", getDefaultKeyDirectory(), File.separator);
187-
}
188-
189132
/**
190133
* Strip trailing line terminators ({@code \n}/{@code \r}) and a leading
191134
* UTF-8 BOM ({@code \uFEFF}) from a line of input. Unlike

framework/src/test/java/org/tron/program/SupplementTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.tron.core.config.args.Args;
2828
import org.tron.core.services.http.HttpSelfFormatFieldName;
2929
import org.tron.core.store.StorageRowStore;
30-
import org.tron.keystore.WalletUtils;
3130

3231
public class SupplementTest extends BaseTest {
3332

@@ -54,12 +53,6 @@ public void testGet() throws Exception {
5453
String p = dbPath + File.separator;
5554
dbBackupConfig.initArgs(true, p + "propPath", p + "bak1path/", p + "bak2path/", 1);
5655

57-
WalletUtils.generateFullNewWalletFile("123456", new File(dbPath), true);
58-
WalletUtils.generateLightNewWalletFile("123456", new File(dbPath), true);
59-
WalletUtils.getDefaultKeyDirectory();
60-
WalletUtils.getTestnetKeyDirectory();
61-
WalletUtils.getMainnetKeyDirectory();
62-
6356
Value value = new Value(new byte[]{1});
6457
value.asBytes();
6558
value = new Value(1);

0 commit comments

Comments
 (0)