Skip to content

Commit 4bee12f

Browse files
author
Wenhua Zhang
committed
feat: check note number when create shielded transaction
1 parent ba30909 commit 4bee12f

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,10 +1686,21 @@ public long getShieldedTransactionFee() {
16861686
return dbManager.getDynamicPropertiesStore().getShieldedTransactionFee();
16871687
}
16881688

1689+
public void checkCmNumber(List<SpendNote> shieldedSpends, List<ReceiveNote> shieldedReceives)
1690+
throws ContractValidateException {
1691+
if (!shieldedSpends.isEmpty() && shieldedSpends.size() > 1) {
1692+
throw new ContractValidateException("The number of spend note must <=1");
1693+
}
1694+
1695+
if (!shieldedReceives.isEmpty() && shieldedReceives.size() > 2) {
1696+
throw new ContractValidateException("The number of receive note must <=2");
1697+
}
1698+
}
1699+
16891700
public TransactionCapsule createShieldedTransaction(PrivateParameters request)
16901701
throws ContractValidateException, RuntimeException, ZksnarkException {
16911702
if (!getFullNodeAllowShieldedTransaction()) {
1692-
throw new ZksnarkException("createshieldedtransaction is not allowed");
1703+
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
16931704
}
16941705
ZenTransactionBuilder builder = new ZenTransactionBuilder(this);
16951706

@@ -1725,6 +1736,8 @@ public TransactionCapsule createShieldedTransaction(PrivateParameters request)
17251736
throw new ContractValidateException("Output amount must > 0");
17261737
}
17271738

1739+
checkCmNumber(shieldedSpends, shieldedReceives);
1740+
17281741
// add
17291742
if (!ArrayUtils.isEmpty(transparentFromAddress)) {
17301743
builder.setTransparentInput(transparentFromAddress, fromAmount);
@@ -1783,7 +1796,7 @@ public TransactionCapsule createShieldedTransactionWithoutSpendAuthSig(
17831796
PrivateParametersWithoutAsk request)
17841797
throws ContractValidateException, ZksnarkException {
17851798
if (!getFullNodeAllowShieldedTransaction()) {
1786-
throw new ZksnarkException("createshieldedtransactionwithoutspendauthsig is not allowed");
1799+
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
17871800
}
17881801

17891802
ZenTransactionBuilder builder = new ZenTransactionBuilder(this);
@@ -1820,6 +1833,8 @@ public TransactionCapsule createShieldedTransactionWithoutSpendAuthSig(
18201833
throw new ContractValidateException("Output amount must > 0");
18211834
}
18221835

1836+
checkCmNumber(shieldedSpends, shieldedReceives);
1837+
18231838
// add
18241839
if (!ArrayUtils.isEmpty(transparentFromAddress)) {
18251840
builder.setTransparentInput(transparentFromAddress, fromAmount);

0 commit comments

Comments
 (0)