Skip to content

Commit 3c62ee7

Browse files
authored
Merge pull request tronprotocol#3166 from helloboy12345/develop
refactore code and fix check style problem
2 parents 7444c61 + c35d3ee commit 3c62ee7

File tree

7 files changed

+32
-41
lines changed

7 files changed

+32
-41
lines changed

chainbase/src/main/java/org/tron/core/capsule/BlockCapsule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.tron.common.crypto.SignInterface;
3636
import org.tron.common.crypto.SignUtils;
3737
import org.tron.common.parameter.CommonParameter;
38+
import org.tron.common.utils.ByteArray;
3839
import org.tron.common.utils.ByteUtil;
3940
import org.tron.common.utils.Sha256Hash;
4041
import org.tron.common.utils.Time;
@@ -305,7 +306,7 @@ public String toString() {
305306
toStringBuff.append("number=").append(getNum()).append("\n");
306307
toStringBuff.append("parentId=").append(getParentHash()).append("\n");
307308
toStringBuff.append("witness address=")
308-
.append(ByteUtil.toHexString(getWitnessAddress().toByteArray())).append("\n");
309+
.append(ByteArray.toHexString(getWitnessAddress().toByteArray())).append("\n");
309310

310311
toStringBuff.append("generated by myself=").append(generatedByMyself).append("\n");
311312
toStringBuff.append("generate time=").append(Time.getTimeString(getTimeStamp())).append("\n");

common/src/main/java/org/tron/common/runtime/vm/DataWord.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.nio.ByteBuffer;
2424
import org.spongycastle.util.Arrays;
2525
import org.spongycastle.util.encoders.Hex;
26+
import org.tron.common.utils.ByteArray;
2627
import org.tron.common.utils.ByteUtil;
2728
import org.tron.common.utils.FastByteComparisons;
2829
import org.tron.core.db.ByteArrayWrapper;
@@ -81,7 +82,7 @@ public DataWord(byte[] data) {
8182
} else if (data.length < WORD_SIZE) {
8283
System.arraycopy(data, 0, this.data, WORD_SIZE - data.length, data.length);
8384
} else {
84-
throw new RuntimeException("Data word can't exceed 32 bytes: " + ByteUtil.toHexString(data));
85+
throw new RuntimeException("Data word can't exceed 32 bytes: " + ByteArray.toHexString(data));
8586
}
8687
}
8788

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,6 @@ public static String oneByteToHexString(byte value) {
150150
return retVal;
151151
}
152152

153-
/**
154-
* Convert a byte-array into a hex String.<br> Works similar to {@link Hex#toHexString} but allows
155-
* for <code>null</code>
156-
*
157-
* @param data - byte-array to convert to a hex-string
158-
* @return hex representation of the data.<br> Returns an empty String if the input is
159-
* <code>null</code>
160-
* @see Hex#toHexString
161-
*/
162-
public static String toHexString(byte[] data) {
163-
return data == null ? "" : Hex.toHexString(data);
164-
}
165-
166153
/**
167154
* Cast hex encoded value from byte[] to int Limited to Integer.MAX_VALUE: 2^32-1 (4 bytes)
168155
*

framework/src/main/java/org/tron/core/capsule/utils/RLPList.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.tron.core.capsule.utils;
22

33
import java.util.ArrayList;
4+
import org.tron.common.utils.ByteArray;
45
import org.tron.common.utils.ByteUtil;
56

67
/**
@@ -23,7 +24,7 @@ public static void recursivePrint(RLPElement element) {
2324
}
2425
System.out.print("]");
2526
} else {
26-
String hex = ByteUtil.toHexString(element.getRLPData());
27+
String hex = ByteArray.toHexString(element.getRLPData());
2728
System.out.print(hex + ", ");
2829
}
2930
}

framework/src/main/java/org/tron/core/db/accountstate/callback/AccountStateCallBack.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.springframework.beans.factory.annotation.Autowired;
1010
import org.springframework.stereotype.Component;
1111
import org.tron.common.crypto.Hash;
12+
import org.tron.common.utils.ByteArray;
1213
import org.tron.common.utils.ByteUtil;
1314
import org.tron.core.ChainBaseManager;
1415
import org.tron.core.capsule.BlockCapsule;
@@ -86,8 +87,8 @@ public void executePushFinish() throws BadBlockException {
8687
}
8788
if (!oldRoot.isEmpty() && !Arrays.equals(oldRoot.toByteArray(), newRoot)) {
8889
logger.error("the accountStateRoot hash is error. {}, oldRoot: {}, newRoot: {}",
89-
blockCapsule, ByteUtil.toHexString(oldRoot.toByteArray()),
90-
ByteUtil.toHexString(newRoot));
90+
blockCapsule, ByteArray.toHexString(oldRoot.toByteArray()),
91+
ByteArray.toHexString(newRoot));
9192
throw new BadBlockException("the accountStateRoot hash is error");
9293
}
9394
}

framework/src/main/java/org/tron/core/trie/TrieImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import static org.apache.commons.lang3.concurrent.ConcurrentUtils.constantFuture;
44
import static org.tron.common.crypto.Hash.EMPTY_TRIE_HASH;
5+
import static org.tron.common.utils.ByteArray.toHexString;
56
import static org.tron.common.utils.ByteUtil.EMPTY_BYTE_ARRAY;
6-
import static org.tron.common.utils.ByteUtil.toHexString;
77
import static org.tron.core.capsule.utils.RLP.EMPTY_ELEMENT_RLP;
88
import static org.tron.core.capsule.utils.RLP.encodeList;
99

framework/src/test/java/org/tron/core/zksnark/SendCoinShieldTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -878,24 +878,24 @@ public void getSpendingKey() throws Exception {
878878
.decode("0b862f0e70048551c08518ff49a19db027d62cdeeb2fa974db91c10e6ebcdc16");
879879
System.out.println(sk.encode());
880880
System.out.println(
881-
"sk.expandedSpendingKey()" + ByteUtil.toHexString(sk.expandedSpendingKey().encode()));
882-
System.out.println("sk.fullViewKey()" + ByteUtil.toHexString(sk.fullViewingKey().encode()));
881+
"sk.expandedSpendingKey()" + ByteArray.toHexString(sk.expandedSpendingKey().encode()));
882+
System.out.println("sk.fullViewKey()" + ByteArray.toHexString(sk.fullViewingKey().encode()));
883883
System.out
884-
.println("sk.ivk()" + ByteUtil.toHexString(sk.fullViewingKey().inViewingKey().getValue()));
884+
.println("sk.ivk()" + ByteArray.toHexString(sk.fullViewingKey().inViewingKey().getValue()));
885885
System.out.println(
886-
"sk.defaultDiversifier:" + ByteUtil.toHexString(sk.defaultDiversifier().getData()));
886+
"sk.defaultDiversifier:" + ByteArray.toHexString(sk.defaultDiversifier().getData()));
887887

888-
System.out.println("sk.defaultAddress:" + ByteUtil.toHexString(sk.defaultAddress().encode()));
888+
System.out.println("sk.defaultAddress:" + ByteArray.toHexString(sk.defaultAddress().encode()));
889889

890-
System.out.println("rcm:" + ByteUtil.toHexString(Note.generateR()));
890+
System.out.println("rcm:" + ByteArray.toHexString(Note.generateR()));
891891

892892
int count = 10;
893893
for (int i = 0; i < count; i++) {
894894
// new sk
895895
System.out.println("---- random " + i + " ----");
896896

897897
sk = SpendingKey.random();
898-
System.out.println("sk is: " + ByteUtil.toHexString(sk.getValue()));
898+
System.out.println("sk is: " + ByteArray.toHexString(sk.getValue()));
899899

900900
DiversifierT diversifierT = new DiversifierT();
901901
byte[] d;
@@ -906,39 +906,39 @@ public void getSpendingKey() throws Exception {
906906
}
907907
}
908908
diversifierT.setData(d);
909-
System.out.println("d is: " + ByteUtil.toHexString(d));
909+
System.out.println("d is: " + ByteArray.toHexString(d));
910910

911911
ExpandedSpendingKey expsk = sk.expandedSpendingKey();
912-
System.out.println("expsk-ask is: " + ByteUtil.toHexString(expsk.getAsk()));
913-
System.out.println("expsk-nsk is: " + ByteUtil.toHexString(expsk.getNsk()));
914-
System.out.println("expsk-ovk is: " + ByteUtil.toHexString(expsk.getOvk()));
912+
System.out.println("expsk-ask is: " + ByteArray.toHexString(expsk.getAsk()));
913+
System.out.println("expsk-nsk is: " + ByteArray.toHexString(expsk.getNsk()));
914+
System.out.println("expsk-ovk is: " + ByteArray.toHexString(expsk.getOvk()));
915915

916916
FullViewingKey fullViewingKey = expsk.fullViewingKey();
917-
System.out.println("fullviewkey-ak is: " + ByteUtil.toHexString(fullViewingKey.getAk()));
918-
System.out.println("fullviewkey-nk is: " + ByteUtil.toHexString(fullViewingKey.getNk()));
919-
System.out.println("fullviewkey-ovk is: " + ByteUtil.toHexString(fullViewingKey.getOvk()));
917+
System.out.println("fullviewkey-ak is: " + ByteArray.toHexString(fullViewingKey.getAk()));
918+
System.out.println("fullviewkey-nk is: " + ByteArray.toHexString(fullViewingKey.getNk()));
919+
System.out.println("fullviewkey-ovk is: " + ByteArray.toHexString(fullViewingKey.getOvk()));
920920

921921
IncomingViewingKey incomingViewingKey = fullViewingKey.inViewingKey();
922-
System.out.println("ivk is: " + ByteUtil.toHexString(incomingViewingKey.getValue()));
922+
System.out.println("ivk is: " + ByteArray.toHexString(incomingViewingKey.getValue()));
923923

924924
Optional<PaymentAddress> op = incomingViewingKey.address(diversifierT);
925-
System.out.println("pkD is: " + ByteUtil.toHexString(op.get().getPkD()));
925+
System.out.println("pkD is: " + ByteArray.toHexString(op.get().getPkD()));
926926

927927
byte[] rcm = Note.generateR();
928-
System.out.println("rcm is " + ByteUtil.toHexString(rcm));
928+
System.out.println("rcm is " + ByteArray.toHexString(rcm));
929929

930930
byte[] alpha = Note.generateR();
931-
System.out.println("alpha is " + ByteUtil.toHexString(alpha));
931+
System.out.println("alpha is " + ByteArray.toHexString(alpha));
932932

933933
String address = KeyIo.encodePaymentAddress(op.get());
934934
System.out.println("saplingaddress is: " + address);
935935

936936
// check
937937
PaymentAddress paymentAddress = KeyIo.decodePaymentAddress(address);
938-
Assert.assertEquals(ByteUtil.toHexString(paymentAddress.getD().getData()),
939-
ByteUtil.toHexString(d));
940-
Assert.assertEquals(ByteUtil.toHexString(paymentAddress.getPkD()),
941-
ByteUtil.toHexString(op.get().getPkD()));
938+
Assert.assertEquals(ByteArray.toHexString(paymentAddress.getD().getData()),
939+
ByteArray.toHexString(d));
940+
Assert.assertEquals(ByteArray.toHexString(paymentAddress.getPkD()),
941+
ByteArray.toHexString(op.get().getPkD()));
942942

943943
}
944944
}

0 commit comments

Comments
 (0)