6767import org .tron .core .zen .address .*;
6868import org .tron .core .zen .merkle .*;
6969import org .tron .core .zen .note .*;
70- import org .tron .core .zen .transaction .Recipient ;
71- import org .tron .core .zen .utils .KeyIo ;
72- import org .tron .core .zen .walletdb .CKeyMetadata ;
73- import org .tron .core .zen .zip32 .ExtendedSpendingKey ;
74- import org .tron .core .zen .zip32 .HDSeed ;
75- import org .tron .core .zen .zip32 .HdChain ;
70+ import org .tron .core .zen .note .Note ;
71+ import org .tron .core .zen .note .NoteEncryption .Encryption ;
7672import org .tron .protos .Contract .MerklePath ;
7773import org .tron .protos .Contract .*;
7874import org .tron .protos .Protocol ;
8985
9086import static org .tron .core .config .Parameter .DatabaseConstants .EXCHANGE_COUNT_LIMIT_MAX ;
9187import static org .tron .core .config .Parameter .DatabaseConstants .PROPOSAL_COUNT_LIMIT_MAX ;
92- import static org .tron .core .zen .zip32 .ExtendedSpendingKey .ZIP32_HARDENED_KEY_LIMIT ;
9388
9489@ Slf4j
9590@ Component
@@ -1638,7 +1633,7 @@ public TransactionCapsule createShieldedTransaction(PrivateParameters request)
16381633
16391634
16401635 GrpcAPI .Note note = spendNote .getNote ();
1641- BaseNote . Note baseNote = new BaseNote . Note (new DiversifierT (note .getD ().toByteArray ()),
1636+ Note baseNote = new Note (new DiversifierT (note .getD ().toByteArray ()),
16421637 note .getPkD ().toByteArray (), note .getValue (), note .getRcm ().toByteArray ());
16431638
16441639 IncrementalMerkleVoucherContainer voucherContainer = new IncrementalMerkleVoucherCapsule (
@@ -1765,7 +1760,7 @@ public DiversifierMessage getDiversifier() {
17651760 public BytesMessage getRcm () {
17661761 byte [] rcm ;
17671762 try {
1768- rcm = BaseNote . Note .generateR ();
1763+ rcm = Note .generateR ();
17691764 return BytesMessage .newBuilder ().setValue (ByteString .copyFrom (rcm )).build ();
17701765 } catch (Exception e ) {
17711766 return null ;
@@ -2018,95 +2013,6 @@ public ExchangeList getPaginatedExchangeList(long offset, long limit) {
20182013
20192014 }
20202015
2021- //for shield transactions
2022-
2023- public String getNewZenAddress () {
2024- //seed
2025- //AccountCounter
2026-
2027- // Create new metadata
2028- long nCreationTime = System .currentTimeMillis ();
2029- CKeyMetadata metadata = new CKeyMetadata (nCreationTime );
2030-
2031- // Try to get the seed
2032- HDSeed seed = KeyStore .seed ;
2033- // init data for test
2034- seed .random (32 );
2035-
2036- if (seed == null ) {
2037- throw new RuntimeException ("CWallet::GenerateNewSaplingZKey(): HD seed not found" );
2038- }
2039-
2040- ExtendedSpendingKey master = ExtendedSpendingKey .Master (seed );
2041- int bip44CoinType = ZkChainParams .BIP44CoinType ;
2042-
2043- // We use a fixed keypath scheme of m/32'/coin_type'/account'
2044- // Derive m/32'
2045- ExtendedSpendingKey master32h = master .Derive (32 | ZIP32_HARDENED_KEY_LIMIT );
2046- // Derive m/32'/coin_type'
2047- ExtendedSpendingKey master32hCth = master32h .Derive (bip44CoinType | ZIP32_HARDENED_KEY_LIMIT );
2048-
2049- System .out .println ("depth=" + ByteArray .toInt (master32hCth .getDepth ()));
2050- System .out .println ("depth=" + ByteArray .toStr (master32hCth .getParentFVKTag ()));
2051- System .out .println ("depth=" + ByteArray .toInt (master32hCth .getChildIndex ()));
2052-
2053- // Derive account key at next index, skip keys already known to the wallet
2054- ExtendedSpendingKey xsk = null ;
2055-
2056- while (xsk == null || KeyStore .haveSpendingKey (xsk .getExpsk ().fullViewingKey ())) {
2057- //
2058- xsk = master32hCth .Derive (HdChain .saplingAccountCounter | ZIP32_HARDENED_KEY_LIMIT );
2059- metadata .hdKeyPath = "m/32'/" + bip44CoinType + "'/" + HdChain .saplingAccountCounter + "'" ;
2060- metadata .seedFp = HdChain .seedFp ;
2061- // Increment childkey index
2062- HdChain .saplingAccountCounter ++;
2063- }
2064-
2065- // Update the chain model in the database
2066- // if (fFileBacked && !CWalletDB(strWalletFile).WriteHDChain(hdChain))
2067- // throw new RuntimeException("CWallet::GenerateNewSaplingZKey(): Writing HD chain model failed");
2068-
2069- IncomingViewingKey ivk = xsk .getExpsk ().fullViewingKey ().inViewingKey ();
2070- ZenWallet .mapSaplingZKeyMetadata .put (ivk , metadata );
2071-
2072- PaymentAddress addr = xsk .DefaultAddress ();
2073- if (!ZenWallet .AddSaplingZKey (xsk , addr )) {
2074- throw new RuntimeException ("CWallet::GenerateNewSaplingZKey(): AddSaplingZKey failed" );
2075- }
2076-
2077- // return default sapling payment address.
2078- String paymentAddress = KeyIo .EncodePaymentAddress (addr );
2079- System .out .println ("paymentAddress = " + paymentAddress );
2080- return paymentAddress ;
2081- }
2082-
2083- public void sendZenCoinShield (String [] params ) {
2084- String fromAddr = params [0 ];
2085- List <Recipient > outputs = new ArrayList <>();
2086-
2087- ZenTransactionBuilderFactory constructor =
2088- new ZenTransactionBuilderFactory (fromAddr , outputs );
2089- TransactionCapsule result = constructor .build ();
2090- // broadcastTX();
2091- }
2092-
2093-
2094- public long getBalanceZenAddress (String address , int minDepth , boolean requireSpendingKey ) {
2095- long balance = 0 ;
2096- List <NoteEntry > saplingEntries ;
2097-
2098- PaymentAddress filterAddresses = null ;// TODO can be null
2099- if (address .length () > 0 ) {
2100- filterAddresses = KeyIo .decodePaymentAddress (address );
2101- }
2102-
2103- saplingEntries = ZenWallet .GetFilteredNotes (filterAddresses , true , requireSpendingKey );
2104- for (NoteEntry entry : saplingEntries ) {
2105- balance += entry .note .value ;
2106- }
2107-
2108- return balance ;
2109- }
21102016
21112017 /*
21122018 * try to get cm belongs to ivk
@@ -2151,7 +2057,7 @@ public GrpcAPI.DecryptNotes scanNoteByIvk(long startNum, long endNum, byte[] ivk
21512057 for (int index = 0 ; index < stContract .getReceiveDescriptionList ().size (); index ++) {
21522058 org .tron .protos .Contract .ReceiveDescription r = stContract .getReceiveDescription (index );
21532059
2154- Optional <BaseNotePlaintext . NotePlaintext > notePlaintext = BaseNotePlaintext . NotePlaintext
2060+ Optional <NotePlaintext > notePlaintext = NotePlaintext
21552061 .decrypt (
21562062 r .getCEnc ().toByteArray (),//ciphertext
21572063 ivk ,
@@ -2160,14 +2066,14 @@ public GrpcAPI.DecryptNotes scanNoteByIvk(long startNum, long endNum, byte[] ivk
21602066 );
21612067
21622068 if (notePlaintext .isPresent ()) {
2163- BaseNotePlaintext . NotePlaintext noteText = notePlaintext .get ();
2069+ NotePlaintext noteText = notePlaintext .get ();
21642070
21652071 byte [] pk_d = new byte [32 ];
21662072 if (!Librustzcash .librustzcashIvkToPkd (ivk , noteText .d .getData (), pk_d )) {
21672073 continue ;
21682074 }
21692075
2170- Note note = Note .newBuilder ()
2076+ GrpcAPI . Note note = GrpcAPI . Note .newBuilder ()
21712077 .setD (ByteString .copyFrom (noteText .d .getData ()))
21722078 .setValue (noteText .value )
21732079 .setRcm (ByteString .copyFrom (noteText .rcm ))
@@ -2233,10 +2139,10 @@ public GrpcAPI.DecryptNotes scanNoteByOvk(long startNum, long endNum, byte[] ovk
22332139 for (int index = 0 ; index < stContract .getReceiveDescriptionList ().size (); index ++) {
22342140 org .tron .protos .Contract .ReceiveDescription r = stContract .getReceiveDescription (index );
22352141
2236- NoteEncryption .OutCiphertext c_out = new NoteEncryption .OutCiphertext ();
2142+ Encryption .OutCiphertext c_out = new Encryption .OutCiphertext ();
22372143 c_out .data = r .getCOut ().toByteArray ();
22382144
2239- Optional <SaplingOutgoingPlaintext > notePlaintext = SaplingOutgoingPlaintext
2145+ Optional <OutgoingPlaintext > notePlaintext = OutgoingPlaintext
22402146 .decrypt (c_out ,//ciphertext
22412147 ovk ,
22422148 r .getValueCommitment ().toByteArray (), //cv
@@ -2246,13 +2152,13 @@ public GrpcAPI.DecryptNotes scanNoteByOvk(long startNum, long endNum, byte[] ovk
22462152
22472153 if (notePlaintext .isPresent ()) {
22482154
2249- SaplingOutgoingPlaintext decrypted_out_ct_unwrapped = notePlaintext .get ();
2155+ OutgoingPlaintext decrypted_out_ct_unwrapped = notePlaintext .get ();
22502156
22512157 //decode c_enc with pkd、esk
2252- NoteEncryption .EncCiphertext ciphertext = new NoteEncryption .EncCiphertext ();
2158+ Encryption .EncCiphertext ciphertext = new Encryption .EncCiphertext ();
22532159 ciphertext .data = r .getCEnc ().toByteArray ();
22542160
2255- Optional <BaseNotePlaintext . NotePlaintext > foo = BaseNotePlaintext . NotePlaintext
2161+ Optional <NotePlaintext > foo = NotePlaintext
22562162 .decrypt (ciphertext ,
22572163 r .getEpk ().toByteArray (),
22582164 decrypted_out_ct_unwrapped .esk ,
@@ -2261,9 +2167,9 @@ public GrpcAPI.DecryptNotes scanNoteByOvk(long startNum, long endNum, byte[] ovk
22612167
22622168 if (foo .isPresent ()) {
22632169
2264- BaseNotePlaintext . NotePlaintext bar = foo .get ();
2170+ NotePlaintext bar = foo .get ();
22652171
2266- Note note = Note .newBuilder ()
2172+ GrpcAPI . Note note = GrpcAPI . Note .newBuilder ()
22672173 .setD (ByteString .copyFrom (bar .d .getData ()))
22682174 .setValue (bar .value )
22692175 .setRcm (ByteString .copyFrom (bar .rcm ))
0 commit comments