@@ -1698,8 +1698,20 @@ public void checkCmNumber(List<SpendNote> shieldedSpends, List<ReceiveNote> shie
16981698 }
16991699 }
17001700
1701+ public ReceiveNote createReceiveNoteRandom (long value ) throws ZksnarkException , BadItemException {
1702+ SpendingKey spendingKey = SpendingKey .random ();
1703+ PaymentAddress paymentAddress = spendingKey .defaultAddress ();
1704+
1705+ GrpcAPI .Note note = GrpcAPI .Note .newBuilder ().setValue (value )
1706+ .setPaymentAddress (KeyIo .encodePaymentAddress (paymentAddress ))
1707+ .setRcm (ByteString .copyFrom (Note .generateR ()))
1708+ .setMemo (ByteString .copyFrom (new byte [512 ])).build ();
1709+
1710+ return ReceiveNote .newBuilder ().setNote (note ).build ();
1711+ }
1712+
17011713 public TransactionCapsule createShieldedTransaction (PrivateParameters request )
1702- throws ContractValidateException , RuntimeException , ZksnarkException {
1714+ throws ContractValidateException , RuntimeException , ZksnarkException , BadItemException {
17031715 if (!getFullNodeAllowShieldedTransaction ()) {
17041716 throw new ZksnarkException ("ShieldedTransactionApi is not allowed" );
17051717 }
@@ -1748,6 +1760,15 @@ public TransactionCapsule createShieldedTransaction(PrivateParameters request)
17481760 builder .setTransparentOutput (transparentToAddress , toAmount );
17491761 }
17501762
1763+ // from shielded to public, without shielded receive, will create a random shielded address
1764+ if (!shieldedSpends .isEmpty ()
1765+ && !ArrayUtils .isEmpty (transparentToAddress )
1766+ && shieldedReceives .isEmpty ()) {
1767+ shieldedReceives = new ArrayList <>();
1768+ ReceiveNote receiveNote = createReceiveNoteRandom (0 );
1769+ shieldedReceives .add (receiveNote );
1770+ }
1771+
17511772 // input
17521773 if (!(ArrayUtils .isEmpty (ask ) || ArrayUtils .isEmpty (nsk ) || ArrayUtils .isEmpty (ovk ))) {
17531774 ExpandedSpendingKey expsk = new ExpandedSpendingKey (ask , nsk , ovk );
@@ -1795,7 +1816,7 @@ public TransactionCapsule createShieldedTransaction(PrivateParameters request)
17951816
17961817 public TransactionCapsule createShieldedTransactionWithoutSpendAuthSig (
17971818 PrivateParametersWithoutAsk request )
1798- throws ContractValidateException , ZksnarkException {
1819+ throws ContractValidateException , ZksnarkException , BadItemException {
17991820 if (!getFullNodeAllowShieldedTransaction ()) {
18001821 throw new ZksnarkException ("ShieldedTransactionApi is not allowed" );
18011822 }
@@ -1845,6 +1866,15 @@ public TransactionCapsule createShieldedTransactionWithoutSpendAuthSig(
18451866 builder .setTransparentOutput (transparentToAddress , toAmount );
18461867 }
18471868
1869+ // from shielded to public, without shielded receive, will create a random shielded address
1870+ if (!shieldedSpends .isEmpty ()
1871+ && !ArrayUtils .isEmpty (transparentToAddress )
1872+ && shieldedReceives .isEmpty ()) {
1873+ shieldedReceives = new ArrayList <>();
1874+ ReceiveNote receiveNote = createReceiveNoteRandom (0 );
1875+ shieldedReceives .add (receiveNote );
1876+ }
1877+
18481878 // input
18491879 if (!(ArrayUtils .isEmpty (ak ) || ArrayUtils .isEmpty (nsk ) || ArrayUtils .isEmpty (ovk ))) {
18501880 for (SpendNote spendNote : shieldedSpends ) {
0 commit comments