@@ -1615,19 +1615,21 @@ public IncrementalMerkleTree getMerkleTreeOfBlock(long blockNum) {
16151615 return null ;
16161616 }
16171617
1618- public long getShieldedTransactionFee (){
1618+ public long getShieldedTransactionFee () {
16191619 return dbManager .getDynamicPropertiesStore ().getShieldedTransactionFee ();
16201620 }
16211621
1622- public TransactionCapsule createShieldedTransaction (PrivateParameters request ) throws ContractValidateException , RuntimeException {
1622+ public TransactionCapsule createShieldedTransaction (PrivateParameters request )
1623+ throws ContractValidateException , RuntimeException {
16231624 ZenTransactionBuilder builder = new ZenTransactionBuilder (this );
16241625
16251626 byte [] transparentFromAddress = request .getTransparentFromAddress ().toByteArray ();
16261627 byte [] ask = request .getAsk ().toByteArray ();
16271628 byte [] nsk = request .getNsk ().toByteArray ();
16281629 byte [] ovk = request .getOvk ().toByteArray ();
16291630
1630- if (ArrayUtils .isEmpty (transparentFromAddress ) && (ArrayUtils .isEmpty (ask ) || ArrayUtils .isEmpty (nsk ) || ArrayUtils .isEmpty (ovk ))) {
1631+ if (ArrayUtils .isEmpty (transparentFromAddress ) && (ArrayUtils .isEmpty (ask ) || ArrayUtils
1632+ .isEmpty (nsk ) || ArrayUtils .isEmpty (ovk ))) {
16311633 throw new ContractValidateException ("No input address" );
16321634 }
16331635
@@ -1637,7 +1639,8 @@ public TransactionCapsule createShieldedTransaction(PrivateParameters request) t
16371639 }
16381640
16391641 List <SpendNote > shieldedSpends = request .getShieldedSpendsList ();
1640- if (!(ArrayUtils .isEmpty (ask ) || ArrayUtils .isEmpty (nsk ) || ArrayUtils .isEmpty (ovk )) && shieldedSpends .isEmpty ()) {
1642+ if (!(ArrayUtils .isEmpty (ask ) || ArrayUtils .isEmpty (nsk ) || ArrayUtils .isEmpty (ovk ))
1643+ && shieldedSpends .isEmpty ()) {
16411644 throw new ContractValidateException ("No input note" );
16421645 }
16431646
@@ -1665,8 +1668,8 @@ public TransactionCapsule createShieldedTransaction(PrivateParameters request) t
16651668 if (!(ArrayUtils .isEmpty (ask ) || ArrayUtils .isEmpty (nsk ) || ArrayUtils .isEmpty (ovk ))) {
16661669 ExpandedSpendingKey expsk = new ExpandedSpendingKey (ask , nsk , ovk );
16671670 for (SpendNote spendNote : shieldedSpends ) {
1668- IncrementalMerkleTreeCapsule merkleTreeCapsule = new IncrementalMerkleTreeCapsule (
1669- spendNote .getPath ().toByteArray ());
1671+ IncrementalMerkleTreeCapsule merkleTreeCapsule = dbManager . getMerkleContainer ()
1672+ . getMerkleTree ( spendNote .getAnchor ().toByteArray ());
16701673
16711674 GrpcAPI .Note note = spendNote .getNote ();
16721675 BaseNote .Note baseNote = new BaseNote .Note (new DiversifierT (note .getD ().toByteArray ()),
@@ -1700,7 +1703,7 @@ public TransactionCapsule createShieldedTransaction(PrivateParameters request) t
17001703 }
17011704
17021705 public BytesMessage getSpendingKey () {
1703- byte [] sk ;
1706+ byte [] sk ;
17041707 try {
17051708 sk = SpendingKey .random ().getValue ();
17061709 return BytesMessage .newBuilder ().setValue (ByteString .copyFrom (sk )).build ();
@@ -1740,7 +1743,7 @@ public BytesMessage getAkFromAsk(ByteString ask) {
17401743 return null ;
17411744 }
17421745
1743- byte [] ak ;
1746+ byte [] ak ;
17441747 try {
17451748 ak = ExpandedSpendingKey .getAkFromAsk (ask .toByteArray ());
17461749 return BytesMessage .newBuilder ().setValue (ByteString .copyFrom (ak )).build ();
@@ -1754,7 +1757,7 @@ public BytesMessage getNkFromNsk(ByteString nsk) {
17541757 return null ;
17551758 }
17561759
1757- byte [] nk ;
1760+ byte [] nk ;
17581761 try {
17591762 nk = ExpandedSpendingKey .getNkFromNsk (nsk .toByteArray ());
17601763 return BytesMessage .newBuilder ().setValue (ByteString .copyFrom (nk )).build ();
@@ -1763,20 +1766,20 @@ public BytesMessage getNkFromNsk(ByteString nsk) {
17631766 }
17641767 }
17651768
1766- public IncomingViewingKeyMessage getIncomingViewingKey (byte [] ak , byte [] nk ){
1769+ public IncomingViewingKeyMessage getIncomingViewingKey (byte [] ak , byte [] nk ) {
17671770
1768- if (ak .length != 32 || nk .length != 32 ){
1771+ if (ak .length != 32 || nk .length != 32 ) {
17691772 return null ;
17701773 }
17711774
17721775 byte [] ivk = new byte [32 ]; // the incoming viewing key
17731776 Librustzcash .librustzcashCrhIvk (ak , nk , ivk );
17741777 return IncomingViewingKeyMessage .newBuilder ()
1775- .setIvk (ByteString .copyFrom (ivk ))
1776- .build ();
1778+ .setIvk (ByteString .copyFrom (ivk ))
1779+ .build ();
17771780 }
17781781
1779- public DiversifierMessage getDiversifier (){
1782+ public DiversifierMessage getDiversifier () {
17801783 byte [] d ;
17811784 while (true ) {
17821785 d = org .tron .keystore .Wallet .generateRandomBytes (Constant .ZC_DIVERSIFIER_SIZE );
@@ -1785,14 +1788,14 @@ public DiversifierMessage getDiversifier(){
17851788 }
17861789 }
17871790 DiversifierMessage diversifierMessage = DiversifierMessage .newBuilder ()
1788- .setD (ByteString .copyFrom (d ))
1789- .build ();
1791+ .setD (ByteString .copyFrom (d ))
1792+ .build ();
17901793
17911794 return diversifierMessage ;
17921795 }
17931796
17941797 public BytesMessage getRcm () {
1795- byte [] rcm ;
1798+ byte [] rcm ;
17961799 try {
17971800 rcm = BaseNote .Note .generateR ();
17981801 return BytesMessage .newBuilder ().setValue (ByteString .copyFrom (rcm )).build ();
@@ -1801,7 +1804,8 @@ public BytesMessage getRcm() {
18011804 }
18021805 }
18031806
1804- public SaplingPaymentAddressMessage getSaplingPaymentAddress (IncomingViewingKey ivk , DiversifierT d ){
1807+ public SaplingPaymentAddressMessage getSaplingPaymentAddress (IncomingViewingKey ivk ,
1808+ DiversifierT d ) {
18051809 //get pk_d from paymentAddress
18061810 SaplingPaymentAddressMessage spa = null ;
18071811
@@ -1810,15 +1814,15 @@ public SaplingPaymentAddressMessage getSaplingPaymentAddress(IncomingViewingKey
18101814 }
18111815
18121816 Optional <PaymentAddress > op = ivk .address (d );
1813- if (op .isPresent ()){
1817+ if (op .isPresent ()) {
18141818 DiversifierMessage ds = DiversifierMessage .newBuilder ()
1815- .setD (ByteString .copyFrom (d .getData ()))
1816- .build ();
1819+ .setD (ByteString .copyFrom (d .getData ()))
1820+ .build ();
18171821
18181822 spa = SaplingPaymentAddressMessage .newBuilder ()
1819- .setD (ds )
1820- .setPkD (ByteString .copyFrom (op .get ().getPkD ()))
1821- .build ();
1823+ .setD (ds )
1824+ .setPkD (ByteString .copyFrom (op .get ().getPkD ()))
1825+ .build ();
18221826
18231827 }
18241828 return spa ;
@@ -2156,8 +2160,9 @@ public GrpcAPI.DecryptNotes scanNoteByBlockRangeAndIvk(long startNum, long endNu
21562160 TransactionCapsule transactionCapsule = new TransactionCapsule (transaction );
21572161 byte [] txid = transactionCapsule .getTransactionId ().getBytes ();
21582162
2159- List <org .tron .protos .Protocol .Transaction .Contract > contracts = transaction .getRawData ().getContractList ();
2160- if (contracts .size () == 0 ){
2163+ List <org .tron .protos .Protocol .Transaction .Contract > contracts = transaction .getRawData ()
2164+ .getContractList ();
2165+ if (contracts .size () == 0 ) {
21612166 continue ;
21622167 }
21632168
@@ -2175,7 +2180,7 @@ public GrpcAPI.DecryptNotes scanNoteByBlockRangeAndIvk(long startNum, long endNu
21752180 throw new RuntimeException ("unpack ShieldedTransferContract failed." );
21762181 }
21772182
2178- for (int index = 0 ; index < stContract .getReceiveDescriptionList ().size (); index ++){
2183+ for (int index = 0 ; index < stContract .getReceiveDescriptionList ().size (); index ++) {
21792184 org .tron .protos .Contract .ReceiveDescription r = stContract .getReceiveDescription (index );
21802185
21812186 Optional <BaseNotePlaintext .NotePlaintext > notePlaintext = BaseNotePlaintext .NotePlaintext
@@ -2201,10 +2206,10 @@ public GrpcAPI.DecryptNotes scanNoteByBlockRangeAndIvk(long startNum, long endNu
22012206 .setPkD (ByteString .copyFrom (pk_d ))
22022207 .build ();
22032208 DecryptNotes .NoteTx noteTx = DecryptNotes .NoteTx .newBuilder ()
2204- .setNote (note )
2205- .setTxid (ByteString .copyFrom (txid ))
2206- .setIndex (index )
2207- .build ();
2209+ .setNote (note )
2210+ .setTxid (ByteString .copyFrom (txid ))
2211+ .setIndex (index )
2212+ .build ();
22082213
22092214 builder .addNoteTxs (noteTx );
22102215 }
@@ -2237,8 +2242,9 @@ public GrpcAPI.DecryptNotes scanNoteByBlockRangeAndOvk(long startNum, long endNu
22372242 TransactionCapsule transactionCapsule = new TransactionCapsule (transaction );
22382243 byte [] txid = transactionCapsule .getTransactionId ().getBytes ();
22392244
2240- List <org .tron .protos .Protocol .Transaction .Contract > contracts = transaction .getRawData ().getContractList ();
2241- if (contracts .size () == 0 ){
2245+ List <org .tron .protos .Protocol .Transaction .Contract > contracts = transaction .getRawData ()
2246+ .getContractList ();
2247+ if (contracts .size () == 0 ) {
22422248 continue ;
22432249 }
22442250
@@ -2256,56 +2262,57 @@ public GrpcAPI.DecryptNotes scanNoteByBlockRangeAndOvk(long startNum, long endNu
22562262 throw new RuntimeException ("unpack ShieldedTransferContract failed." );
22572263 }
22582264
2259- for (int index = 0 ; index < stContract .getReceiveDescriptionList ().size (); index ++){
2265+ for (int index = 0 ; index < stContract .getReceiveDescriptionList ().size (); index ++) {
22602266 org .tron .protos .Contract .ReceiveDescription r = stContract .getReceiveDescription (index );
22612267
2262- NoteEncryption .OutCiphertext c_out = new NoteEncryption .OutCiphertext ();
2263- c_out .data = r .getCOut ().toByteArray ();
2268+ NoteEncryption .OutCiphertext c_out = new NoteEncryption .OutCiphertext ();
2269+ c_out .data = r .getCOut ().toByteArray ();
22642270
2265- Optional <SaplingOutgoingPlaintext > notePlaintext = SaplingOutgoingPlaintext .decrypt (c_out ,//ciphertext
2266- ovk ,
2267- r .getValueCommitment ().toByteArray (), //cv
2268- r .getNoteCommitment ().toByteArray (), //cmu
2269- r .getEpk ().toByteArray () //epk
2270- );
2271+ Optional <SaplingOutgoingPlaintext > notePlaintext = SaplingOutgoingPlaintext
2272+ .decrypt (c_out ,//ciphertext
2273+ ovk ,
2274+ r .getValueCommitment ().toByteArray (), //cv
2275+ r .getNoteCommitment ().toByteArray (), //cmu
2276+ r .getEpk ().toByteArray () //epk
2277+ );
22712278
2272- if (notePlaintext .isPresent ()) {
2279+ if (notePlaintext .isPresent ()) {
22732280
2274- SaplingOutgoingPlaintext decrypted_out_ct_unwrapped = notePlaintext .get ();
2281+ SaplingOutgoingPlaintext decrypted_out_ct_unwrapped = notePlaintext .get ();
22752282
2276- //decode c_enc with pkd、esk
2277- NoteEncryption .EncCiphertext ciphertext = new NoteEncryption .EncCiphertext ();
2278- ciphertext .data = r .getCEnc ().toByteArray ();
2283+ //decode c_enc with pkd、esk
2284+ NoteEncryption .EncCiphertext ciphertext = new NoteEncryption .EncCiphertext ();
2285+ ciphertext .data = r .getCEnc ().toByteArray ();
22792286
2280- Optional <BaseNotePlaintext .NotePlaintext > foo = BaseNotePlaintext .NotePlaintext
2281- .decrypt (ciphertext ,
2282- r .getEpk ().toByteArray (),
2283- decrypted_out_ct_unwrapped .esk ,
2284- decrypted_out_ct_unwrapped .pk_d ,
2285- r .getNoteCommitment ().toByteArray ());
2287+ Optional <BaseNotePlaintext .NotePlaintext > foo = BaseNotePlaintext .NotePlaintext
2288+ .decrypt (ciphertext ,
2289+ r .getEpk ().toByteArray (),
2290+ decrypted_out_ct_unwrapped .esk ,
2291+ decrypted_out_ct_unwrapped .pk_d ,
2292+ r .getNoteCommitment ().toByteArray ());
22862293
2287- if (foo .isPresent ()) {
2294+ if (foo .isPresent ()) {
22882295
2289- BaseNotePlaintext .NotePlaintext bar = foo .get ();
2296+ BaseNotePlaintext .NotePlaintext bar = foo .get ();
22902297
2291- Note note = Note .newBuilder ()
2292- .setD (ByteString .copyFrom (bar .d .getData ()))
2293- .setValue (bar .value )
2294- .setRcm (ByteString .copyFrom (bar .rcm ))
2295- .setPkD (ByteString .copyFrom (decrypted_out_ct_unwrapped .pk_d ))
2296- .build ();
2298+ Note note = Note .newBuilder ()
2299+ .setD (ByteString .copyFrom (bar .d .getData ()))
2300+ .setValue (bar .value )
2301+ .setRcm (ByteString .copyFrom (bar .rcm ))
2302+ .setPkD (ByteString .copyFrom (decrypted_out_ct_unwrapped .pk_d ))
2303+ .build ();
22972304
2298- DecryptNotes .NoteTx noteTx = DecryptNotes .NoteTx .newBuilder ()
2299- .setNote (note )
2300- .setTxid (ByteString .copyFrom (txid ))
2301- .setIndex (index )
2302- .build ();
2305+ DecryptNotes .NoteTx noteTx = DecryptNotes .NoteTx .newBuilder ()
2306+ .setNote (note )
2307+ .setTxid (ByteString .copyFrom (txid ))
2308+ .setIndex (index )
2309+ .build ();
23032310
2304- builder .addNoteTxs (noteTx );
2305- }
2311+ builder .addNoteTxs (noteTx );
23062312 }
2313+ }
23072314
2308- } // end of ReceiveDescriptionList
2315+ } // end of ReceiveDescriptionList
23092316
23102317 } // end of transaction
23112318
0 commit comments