Skip to content

Commit 5aefa93

Browse files
committed
feat(crypto): optimize the code
1 parent 04eca9f commit 5aefa93

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

chainbase/src/main/java/org/tron/common/utils/LocalWitnesses.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public LocalWitnesses(List<String> privateKeys) {
4646
}
4747

4848
public byte[] getWitnessAccountAddress(boolean isECKeyCryptoEngine) {
49-
if (witnessAccountAddress == null && !this.privateKeys.isEmpty()) {
49+
if (witnessAccountAddress == null && !CollectionUtils.isEmpty(privateKeys)) {
5050
byte[] privateKey = ByteArray.fromHexString(getPrivateKey());
5151
final SignInterface cryptoEngine = SignUtils.fromPrivate(privateKey, isECKeyCryptoEngine);
5252
this.witnessAccountAddress = cryptoEngine.getAddress();
@@ -59,7 +59,7 @@ public void setWitnessAccountAddress(final byte[] localWitnessAccountAddress) {
5959
}
6060

6161
public void initWitnessAccountAddress(boolean isECKeyCryptoEngine) {
62-
if (witnessAccountAddress == null && !this.privateKeys.isEmpty()) {
62+
if (witnessAccountAddress == null && !CollectionUtils.isEmpty(privateKeys)) {
6363
byte[] privateKey = ByteArray.fromHexString(getPrivateKey());
6464
final SignInterface ecKey = SignUtils.fromPrivate(privateKey,
6565
isECKeyCryptoEngine);

crypto/src/main/java/org/tron/common/crypto/ECKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public static ECKey fromPrivate(BigInteger privKey) {
285285
* @return -
286286
*/
287287
public static ECKey fromPrivate(byte[] privKeyBytes) {
288-
if (Objects.isNull(privKeyBytes) || privKeyBytes.length == 0) {
288+
if (ByteUtil.isNullOrZeroArray(privKeyBytes)) {
289289
return null;
290290
}
291291
return fromPrivate(new BigInteger(1, privKeyBytes));

crypto/src/main/java/org/tron/common/crypto/sm2/SM2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public static SM2 fromPrivate(BigInteger privKey) {
247247
* @return -
248248
*/
249249
public static SM2 fromPrivate(byte[] privKeyBytes) {
250-
if (Objects.isNull(privKeyBytes) || privKeyBytes.length == 0) {
250+
if (ByteUtil.isNullOrZeroArray(privKeyBytes)) {
251251
return null;
252252
}
253253
return fromPrivate(new BigInteger(1, privKeyBytes));

framework/src/main/java/org/tron/core/metrics/node/NodeMetricManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.stereotype.Component;
66
import org.tron.common.backup.BackupManager;
77
import org.tron.common.parameter.CommonParameter;
8+
import org.tron.common.utils.ByteUtil;
89
import org.tron.core.ChainBaseManager;
910
import org.tron.core.config.args.Args;
1011
import org.tron.program.Version;
@@ -38,8 +39,8 @@ private void setNodeInfo(NodeInfo nodeInfo) {
3839

3940
byte[] witnessAccountAddress = Args.getLocalWitnesses()
4041
.getWitnessAccountAddress(CommonParameter.getInstance().isECKeyCryptoEngine());
41-
ByteString witnessAddress =
42-
witnessAccountAddress != null ? ByteString.copyFrom(witnessAccountAddress) : null;
42+
ByteString witnessAddress = !ByteUtil.isNullOrZeroArray(witnessAccountAddress) ? ByteString
43+
.copyFrom(witnessAccountAddress) : null;
4344
if (chainBaseManager.getWitnessScheduleStore().getActiveWitnesses().contains(witnessAddress)) {
4445
nodeInfo.setNodeType(1);
4546
} else {

0 commit comments

Comments
 (0)