Skip to content

Commit 1458da5

Browse files
committed
modify some syntax style
1 parent 94d6485 commit 1458da5

5 files changed

Lines changed: 86 additions & 91 deletions

File tree

‎src/main/java/org/tron/core/Wallet.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ public GrpcAPI.DecryptNotes scanNoteByIvk(long startNum, long endNum,
24162416
if (!(startNum >= 0 && endNum > startNum
24172417
&& endNum - startNum <= 1000)) {
24182418
throw new BadItemException(
2419-
"request require startNum >= 0 && endNum > startNum && endNum - startNum <= 1000");
2419+
"request require start_block_index >= 0 && end_block_index > start_block_index && end_block_index - start_block_index <= 1000");
24202420
}
24212421
BlockList blockList = this
24222422
.getBlocksByLimitNext(startNum, endNum - startNum);
@@ -2498,7 +2498,7 @@ public GrpcAPI.DecryptNotes scanNoteByOvk(long startNum, long endNum,
24982498
if (!(startNum >= 0 && endNum > startNum
24992499
&& endNum - startNum <= 1000)) {
25002500
throw new BadItemException(
2501-
"request require startNum >= 0 && endNum > startNum && endNum - startNum <= 1000");
2501+
"request require start_block_index >= 0 && end_block_index > start_block_index && end_block_index - start_block_index <= 1000");
25022502
}
25032503
BlockList blockList = this
25042504
.getBlocksByLimitNext(startNum, endNum - startNum);
@@ -2534,33 +2534,33 @@ public GrpcAPI.DecryptNotes scanNoteByOvk(long startNum, long endNum,
25342534
index++) {
25352535
ReceiveDescription r = stContract
25362536
.getReceiveDescription(index);
2537-
Encryption.OutCiphertext c_out = new Encryption.OutCiphertext();
2538-
c_out.data = r.getCOut().toByteArray();
2537+
Encryption.OutCiphertext cOut = new Encryption.OutCiphertext();
2538+
cOut.data = r.getCOut().toByteArray();
25392539
Optional<OutgoingPlaintext> notePlaintext = OutgoingPlaintext
2540-
.decrypt(c_out,//ciphertext
2540+
.decrypt(cOut,//ciphertext
25412541
ovk,
25422542
r.getValueCommitment().toByteArray(), //cv
25432543
r.getNoteCommitment().toByteArray(), //cmu
25442544
r.getEpk().toByteArray() //epk
25452545
);
25462546

25472547
if (notePlaintext.isPresent()) {
2548-
OutgoingPlaintext decrypted_out_ct_unwrapped = notePlaintext
2548+
OutgoingPlaintext decryptedOutCtUnwrapped = notePlaintext
25492549
.get();
25502550
//decode c_enc with pkd、esk
25512551
Encryption.EncCiphertext ciphertext = new Encryption.EncCiphertext();
25522552
ciphertext.data = r.getCEnc().toByteArray();
25532553
Optional<Note> foo = Note
25542554
.decrypt(ciphertext,
25552555
r.getEpk().toByteArray(),
2556-
decrypted_out_ct_unwrapped.esk,
2557-
decrypted_out_ct_unwrapped.pk_d,
2556+
decryptedOutCtUnwrapped.esk,
2557+
decryptedOutCtUnwrapped.pk_d,
25582558
r.getNoteCommitment().toByteArray());
25592559

25602560
if (foo.isPresent()) {
25612561
Note bar = foo.get();
25622562
String paymentAddress = KeyIo.encodePaymentAddress(
2563-
new PaymentAddress(bar.d, decrypted_out_ct_unwrapped.pk_d));
2563+
new PaymentAddress(bar.d, decryptedOutCtUnwrapped.pk_d));
25642564
GrpcAPI.Note note = GrpcAPI.Note.newBuilder()
25652565
.setPaymentAddress(paymentAddress)
25662566
.setValue(bar.value)

‎src/main/java/org/tron/core/services/http/ScanNoteByIvkServlet.java‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.stereotype.Component;
1212
import org.tron.api.GrpcAPI;
13+
import org.tron.api.GrpcAPI.IvkDecryptParameters;
14+
import org.tron.api.GrpcAPI.OvkDecryptParameters;
1315
import org.tron.common.utils.ByteArray;
1416
import org.tron.core.Wallet;
1517

@@ -23,22 +25,19 @@ public class ScanNoteByIvkServlet extends HttpServlet {
2325
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
2426
try {
2527
String input = request.getReader().lines()
26-
.collect(Collectors.joining(System.lineSeparator()));
28+
.collect(Collectors.joining(System.lineSeparator()));
2729
Util.checkBodySize(input);
28-
JSONObject jsonObject = JSONObject.parseObject(input);
2930
boolean visible = Util.getVisiblePost(input);
30-
31-
long startNum = Util.getJsonLongValue(jsonObject,"startNum", true);
32-
long endNum = Util.getJsonLongValue(jsonObject,"endNum", true);
33-
34-
String ivk = jsonObject.getString("ivk");
35-
31+
IvkDecryptParameters.Builder ivkDecryptParameters = IvkDecryptParameters.newBuilder();
32+
JsonFormat.merge(input, ivkDecryptParameters);
33+
3634
GrpcAPI.DecryptNotes notes = wallet
37-
.scanNoteByIvk(startNum, endNum, ByteArray.fromHexString(ivk));
35+
.scanNoteByIvk(ivkDecryptParameters.getStartBlockIndex(),
36+
ivkDecryptParameters.getEndBlockIndex(),
37+
ivkDecryptParameters.getIvk().toByteArray());
3838

3939
response.getWriter()
4040
.println(JsonFormat.printToString(notes, visible));
41-
4241
} catch (Exception e) {
4342
logger.debug("Exception: {}", e.getMessage());
4443
try {
@@ -51,17 +50,15 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
5150

5251
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
5352
try {
54-
long startNum = Long.parseLong(request.getParameter("startNum"));
55-
long endNum = Long.parseLong(request.getParameter("endNum"));
53+
long startNum = Long.parseLong(request.getParameter("start_block_index"));
54+
long endNum = Long.parseLong(request.getParameter("end_block_index"));
5655
String ivk = request.getParameter("ivk");
5756
boolean visible = Util.getVisible(request);
5857

5958
GrpcAPI.DecryptNotes notes = wallet
6059
.scanNoteByIvk(startNum, endNum, ByteArray.fromHexString(ivk));
61-
6260
response.getWriter()
6361
.println(JsonFormat.printToString(notes, visible));
64-
6562
} catch (Exception e) {
6663
logger.debug("Exception: {}", e.getMessage());
6764
try {

‎src/main/java/org/tron/core/services/http/ScanNoteByOvkServlet.java‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.stereotype.Component;
1212
import org.tron.api.GrpcAPI;
13+
import org.tron.api.GrpcAPI.NfParameters;
14+
import org.tron.api.GrpcAPI.OvkDecryptParameters;
1315
import org.tron.common.utils.ByteArray;
1416
import org.tron.core.Wallet;
1517

@@ -23,18 +25,17 @@ public class ScanNoteByOvkServlet extends HttpServlet {
2325
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
2426
try {
2527
String input = request.getReader().lines()
26-
.collect(Collectors.joining(System.lineSeparator()));
28+
.collect(Collectors.joining(System.lineSeparator()));
2729
Util.checkBodySize(input);
28-
JSONObject jsonObject = JSONObject.parseObject(input);
2930
boolean visible = Util.getVisiblePost(input);
30-
31-
long startNum = Util.getJsonLongValue(jsonObject,"startNum", true);
32-
long endNum = Util.getJsonLongValue(jsonObject,"endNum", true);
33-
34-
String ovk = jsonObject.getString("ovk");
35-
31+
32+
OvkDecryptParameters.Builder ovkDecryptParameters = OvkDecryptParameters.newBuilder();
33+
JsonFormat.merge(input, ovkDecryptParameters);
34+
3635
GrpcAPI.DecryptNotes notes = wallet
37-
.scanNoteByOvk(startNum, endNum, ByteArray.fromHexString(ovk));
36+
.scanNoteByOvk(ovkDecryptParameters.getStartBlockIndex(),
37+
ovkDecryptParameters.getEndBlockIndex(),
38+
ovkDecryptParameters.getOvk().toByteArray());
3839

3940
response.getWriter()
4041
.println(JsonFormat.printToString(notes, visible));
@@ -52,16 +53,14 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
5253
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
5354
try {
5455
boolean visible = Util.getVisible(request);
55-
long startNum = Long.parseLong(request.getParameter("startNum"));
56-
long endNum = Long.parseLong(request.getParameter("endNum"));
56+
long startBlockIndex = Long.parseLong(request.getParameter("start_block_index"));
57+
long endBlockIndex = Long.parseLong(request.getParameter("end_block_index"));
5758
String ovk = request.getParameter("ovk");
58-
5959
GrpcAPI.DecryptNotes notes = wallet
60-
.scanNoteByOvk(startNum, endNum, ByteArray.fromHexString(ovk));
61-
60+
.scanNoteByOvk(startBlockIndex, endBlockIndex, ByteArray.fromHexString(ovk));
6261
response.getWriter()
6362
.println(JsonFormat.printToString(notes, visible));
64-
63+
6564
} catch (Exception e) {
6665
logger.debug("Exception: {}", e.getMessage());
6766
try {

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

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -349,31 +349,30 @@ public void testDecryptReceiveWithIvk() throws ZksnarkException {
349349
receiveDescription.getNoteCommitment().toByteArray() //cm
350350
);
351351

352-
if (ret1.isPresent()) {
353-
Note noteText = ret1.get();
354-
355-
byte[] pk_d = new byte[32];
356-
if (!JLibrustzcash.librustzcashIvkToPkd(
357-
new IvkToPkdParams(incomingViewingKey.getValue(), noteText.d.getData(), pk_d))) {
358-
JLibrustzcash.librustzcashSaplingProvingCtxFree(ctx);
359-
return;
360-
}
361-
362-
Assert.assertArrayEquals(paymentAddress.getPkD(), pk_d);
363-
Assert.assertEquals(noteText.value, 4000);
364-
Assert.assertArrayEquals(noteText.memo, memo);
352+
Assert.assertTrue(ret1.isPresent());
353+
354+
Note noteText = ret1.get();
355+
byte[] pkD = new byte[32];
356+
if (!JLibrustzcash.librustzcashIvkToPkd(
357+
new IvkToPkdParams(incomingViewingKey.getValue(), noteText.d.getData(), pkD))) {
358+
JLibrustzcash.librustzcashSaplingProvingCtxFree(ctx);
359+
return;
360+
}
365361

366-
String paymentAddressStr = KeyIo.encodePaymentAddress(
367-
new PaymentAddress(noteText.d, pk_d));
362+
Assert.assertArrayEquals(paymentAddress.getPkD(), pkD);
363+
Assert.assertEquals(noteText.value, 4000);
364+
Assert.assertArrayEquals(noteText.memo, memo);
368365

369-
GrpcAPI.Note decrypt_note = GrpcAPI.Note.newBuilder()
370-
.setPaymentAddress(paymentAddressStr)
371-
.setValue(noteText.value)
372-
.setRcm(ByteString.copyFrom(noteText.rcm))
373-
.setMemo(ByteString.copyFrom(noteText.memo))
374-
.build();
375-
}
366+
String paymentAddressStr = KeyIo.encodePaymentAddress(
367+
new PaymentAddress(noteText.d, pkD));
376368

369+
GrpcAPI.Note grpcAPINote = GrpcAPI.Note.newBuilder()
370+
.setPaymentAddress(paymentAddressStr)
371+
.setValue(noteText.value)
372+
.setRcm(ByteString.copyFrom(noteText.rcm))
373+
.setMemo(ByteString.copyFrom(noteText.memo))
374+
.build();
375+
377376
JLibrustzcash.librustzcashSaplingProvingCtxFree(ctx);
378377
}
379378

@@ -415,15 +414,15 @@ public void testDecryptReceiveWithOvk() throws Exception {
415414
byte[] memo = org.tron.keystore.Wallet.generateRandomBytes(512);
416415
note.memo = memo;
417416

418-
byte[] cmu_opt = note.cm();
419-
Assert.assertNotNull(cmu_opt);
417+
byte[] cmuOpt = note.cm();
418+
Assert.assertNotNull(cmuOpt);
420419

421420
NotePlaintextEncryptionResult enc = note.encrypt(pkd).get();
422421
NoteEncryption encryptor = enc.noteEncryption;
423-
OutgoingPlaintext out_pt = new OutgoingPlaintext(note.pkD, encryptor.esk);
422+
OutgoingPlaintext outgoingPlaintext = new OutgoingPlaintext(note.pkD, encryptor.esk);
424423

425424
// encrypt with ovk
426-
Encryption.OutCiphertext outCiphertext = out_pt.encrypt(
425+
Encryption.OutCiphertext outCiphertext = outgoingPlaintext.encrypt(
427426
fullViewingKey.getOvk(),
428427
receiveDescription.getValueCommitment().toByteArray(),
429428
receiveDescription.getNoteCommitment().toByteArray(),
@@ -438,19 +437,19 @@ public void testDecryptReceiveWithOvk() throws Exception {
438437
);
439438

440439
if (ret2.isPresent()) {
441-
OutgoingPlaintext decrypted_out_ct_unwrapped = ret2.get();
442-
Assert.assertArrayEquals(decrypted_out_ct_unwrapped.pk_d, out_pt.pk_d);
443-
Assert.assertArrayEquals(decrypted_out_ct_unwrapped.esk, out_pt.esk);
440+
OutgoingPlaintext decryptedOutgoingPlaintext = ret2.get();
441+
Assert.assertArrayEquals(decryptedOutgoingPlaintext.pk_d, outgoingPlaintext.pk_d);
442+
Assert.assertArrayEquals(decryptedOutgoingPlaintext.esk, outgoingPlaintext.esk);
444443

445444
//decrypt c_enc with pkd、esk
446445
Encryption.EncCiphertext ciphertext = new Encryption.EncCiphertext();
447446
ciphertext.data = enc.encCiphertext;
448447
Optional<Note> foo = Note
449448
.decrypt(ciphertext,
450-
encryptor.epk,
451-
decrypted_out_ct_unwrapped.esk,
452-
decrypted_out_ct_unwrapped.pk_d,
453-
cmu_opt);
449+
encryptor.epk,
450+
decryptedOutgoingPlaintext.esk,
451+
decryptedOutgoingPlaintext.pk_d,
452+
cmuOpt);
454453

455454
if (foo.isPresent()) {
456455
Note bar = foo.get();
@@ -529,13 +528,13 @@ public void pushShieldedTransactionAndDecryptWithIvk()
529528

530529
if (ret1.isPresent()) {
531530
Note noteText = ret1.get();
532-
byte[] pk_d = new byte[32];
531+
byte[] pkD = new byte[32];
533532
if (!JLibrustzcash.librustzcashIvkToPkd(
534-
new IvkToPkdParams(incomingViewingKey.getValue(), noteText.d.getData(), pk_d))) {
533+
new IvkToPkdParams(incomingViewingKey.getValue(), noteText.d.getData(), pkD))) {
535534
JLibrustzcash.librustzcashSaplingProvingCtxFree(ctx);
536535
return;
537536
}
538-
Assert.assertArrayEquals(paymentAddress.getPkD(), pk_d);
537+
Assert.assertArrayEquals(paymentAddress.getPkD(), pkD);
539538
Assert.assertEquals(1000 * 1000000 - wallet.getShieldedTransactionFee(), noteText.value);
540539
Assert.assertArrayEquals(memo, noteText.memo);
541540
} else {
@@ -603,27 +602,27 @@ public void pushShieldedTransactionAndDecryptWithOvk()
603602
.unpack(Contract.ShieldedTransferContract.class);
604603
ReceiveDescription receiveDescription = stContract.getReceiveDescription(0);
605604

606-
Encryption.OutCiphertext c_out = new Encryption.OutCiphertext();
607-
c_out.data = receiveDescription.getCOut().toByteArray();
605+
Encryption.OutCiphertext cOut = new Encryption.OutCiphertext();
606+
cOut.data = receiveDescription.getCOut().toByteArray();
608607
Optional<OutgoingPlaintext> notePlaintext = OutgoingPlaintext.decrypt(
609-
c_out,//ciphertext
608+
cOut,//ciphertext
610609
fullViewingKey.getOvk(),
611610
receiveDescription.getValueCommitment().toByteArray(), //cv
612611
receiveDescription.getNoteCommitment().toByteArray(), //cmu
613612
receiveDescription.getEpk().toByteArray() //epk
614613
);
615614

616615
if (notePlaintext.isPresent()) {
617-
OutgoingPlaintext decrypted_out_ct_unwrapped = notePlaintext.get();
616+
OutgoingPlaintext decryptedOutgoingPlaintext = notePlaintext.get();
618617
//decode c_enc with pkd、esk
619618
Encryption.EncCiphertext ciphertext = new Encryption.EncCiphertext();
620619
ciphertext.data = receiveDescription.getCEnc().toByteArray();
621620
Optional<Note> foo = Note
622621
.decrypt(ciphertext,
623-
receiveDescription.getEpk().toByteArray(),
624-
decrypted_out_ct_unwrapped.esk,
625-
decrypted_out_ct_unwrapped.pk_d,
626-
receiveDescription.getNoteCommitment().toByteArray());
622+
receiveDescription.getEpk().toByteArray(),
623+
decryptedOutgoingPlaintext.esk,
624+
decryptedOutgoingPlaintext.pk_d,
625+
receiveDescription.getNoteCommitment().toByteArray());
627626

628627
if (foo.isPresent()) {
629628
Note bar = foo.get();

‎src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private void createCapsule() {
202202
dbManager.getAccountStore().put(ownerCapsule.getAddress().toByteArray(), ownerCapsule);
203203
}
204204

205-
private void librustzcashInitZksnarkParams() throws ZksnarkException {
205+
private void librustzcashInitZksnarkParams(){
206206
FullNodeHttpApiService.librustzcashInitZksnarkParams();
207207
}
208208

@@ -1950,8 +1950,8 @@ public void testIsolateSignature()
19501950
actuator.get(0).validate();
19511951
//execute
19521952
TransactionResultCapsule resultCapsule = new TransactionResultCapsule();
1953-
boolean execute_result = actuator.get(0).execute(resultCapsule);
1954-
Assert.assertTrue(execute_result);
1953+
boolean executeResult = actuator.get(0).execute(resultCapsule);
1954+
Assert.assertTrue(executeResult);
19551955
}
19561956

19571957
public TransactionCapsule buildShieldedTransactionWithoutSpendAuthSig(PaymentAddress address,
@@ -2083,14 +2083,14 @@ public void testMemoTooLong()
20832083

20842084
if (ret1.isPresent()) {
20852085
Note noteText = ret1.get();
2086-
byte[] pk_d = new byte[32];
2086+
byte[] pkD = new byte[32];
20872087
if (!JLibrustzcash.librustzcashIvkToPkd(
20882088
new LibrustzcashParam.IvkToPkdParams(incomingViewingKey.getValue(),
2089-
noteText.d.getData(), pk_d))) {
2089+
noteText.d.getData(), pkD))) {
20902090
JLibrustzcash.librustzcashSaplingProvingCtxFree(ctx);
20912091
return;
20922092
}
2093-
Assert.assertArrayEquals(paymentAddress.getPkD(), pk_d);
2093+
Assert.assertArrayEquals(paymentAddress.getPkD(), pkD);
20942094
Assert.assertEquals(100 * 1000000 - wallet.getShieldedTransactionFee(),
20952095
noteText.value);
20962096

@@ -2166,14 +2166,14 @@ public void testMemoNotEnough()
21662166

21672167
if (ret1.isPresent()) {
21682168
Note noteText = ret1.get();
2169-
byte[] pk_d = new byte[32];
2169+
byte[] pkD = new byte[32];
21702170
if (!JLibrustzcash.librustzcashIvkToPkd(
21712171
new LibrustzcashParam.IvkToPkdParams(incomingViewingKey.getValue(),
2172-
noteText.d.getData(), pk_d))) {
2172+
noteText.d.getData(), pkD))) {
21732173
JLibrustzcash.librustzcashSaplingProvingCtxFree(ctx);
21742174
return;
21752175
}
2176-
Assert.assertArrayEquals(paymentAddress.getPkD(), pk_d);
2176+
Assert.assertArrayEquals(paymentAddress.getPkD(), pkD);
21772177
Assert.assertEquals(100 * 1000000 - wallet.getShieldedTransactionFee(),
21782178
noteText.value);
21792179

0 commit comments

Comments
 (0)