Make validate privacy mode function moderately less confusing. Maintain private function as is reused in 2 places. More for exception rather than validation logic. Make function void as boolean is misleading. Remove strealth boolean flag in the guise of an optional.
@@ -138,7 +138,8 @@ public class TransactionManagerImpl implements TransactionManager {
final List<AffectedTransaction> affectedContractTransactions =
buildAffectedContractTransactions(sendRequest.getAffectedContractTransactions());
- validatePrivacyMode(Optional.empty(), privacyMode, affectedContractTransactions);
+ validatePrivacyMode(privacyMode,affectedContractTransactions);
+
if (PrivacyMode.PRIVATE_STATE_VALIDATION == privacyMode) {
validateRecipients(Optional.empty(), recipientList, affectedContractTransactions);
@@ -218,7 +219,15 @@ public class TransactionManagerImpl implements TransactionManager {
final byte[] execHash =
Optional.ofNullable(sendRequest.getExecHash()).map(String::getBytes).orElse(new byte[0]);
- validatePrivacyMode(Optional.empty(), privacyMode, affectedContractTransactions);
+ affectedContractTransactions.stream()
+ .filter(a -> a.getPayload().getPrivacyMode() != privacyMode)
+ .findFirst().ifPresent(affectedTransaction -> {
+ throw new PrivacyViolationException(
+ "Private state validation flag mismatched with Affected Txn "
+ + affectedTransaction.getHash().encodeToBase64());
+ });
+
+ validatePrivacyMode(privacyMode,affectedContractTransactions);
if (PrivacyMode.PRIVATE_STATE_VALIDATION == privacyMode) {
validateRecipients(Optional.of(messageHash), recipientList, affectedContractTransactions);
@@ -364,9 +373,11 @@ public class TransactionManagerImpl implements TransactionManager {
final List<AffectedTransaction> affectedContractTransactions =
buildAffectedContractTransactions(affectedTransactionInBase64);
- if (!validatePrivacyMode(Optional.of(transactionHash), privacyMode, affectedContractTransactions)) {
+ if(affectedContractTransactions.stream()
+ .anyMatch(a -> a.getPayload().getPrivacyMode() != privacyMode)) {
return transactionHash;
}
+
if (PrivacyMode.PRIVATE_STATE_VALIDATION == privacyMode) {
if (affectedContractTransactions.size() != payload.getAffectedContractTransactions().size()) {
@@ -603,30 +614,20 @@ public class TransactionManagerImpl implements TransactionManager {
return affectedContractTransactions;
}
- private boolean validatePrivacyMode(
- Optional<MessageHash> txHash,
+
+
+ protected static void validatePrivacyMode(
PrivacyMode privacyMode,
List<AffectedTransaction> affectedContractTransactions) {
- boolean result = true;
- for (AffectedTransaction entry : affectedContractTransactions) {
- final PrivacyMode affectedContractPrivacyMode = entry.getPayload().getPrivacyMode();
- if (affectedContractPrivacyMode != privacyMode) {
- if (!txHash.isPresent()) {
+
+ affectedContractTransactions.stream()
+ .filter(a -> a.getPayload().getPrivacyMode() != privacyMode)
+ .findFirst().ifPresent(affectedTransaction -> {
throw new PrivacyViolationException(
"Private state validation flag mismatched with Affected Txn "
- + entry.getHash().encodeToBase64());
- } else {
- LOGGER.info(
- "ACOTH {} has PrivacyMode={} for TX {} with PrivacyMode={}. Ignoring transaction.",
- entry.getHash().encodeToBase64(),
- affectedContractPrivacyMode.name(),
- base64Codec.encodeToString(txHash.get().getHashBytes()),
- privacyMode.name());
- result = false;
- }
- }
- }
- return result;
+ + affectedTransaction.getHash().encodeToBase64());
+ });
+
}
private boolean validateRecipients(
@@ -648,15 +649,6 @@ public class TransactionManagerImpl implements TransactionManager {
return true;
}
- private boolean validateIfSenderIsGenuine(EncodedPayload payload, List<AffectedTransaction> affectedContractTransactions) {
-
- final PublicKey senderKey = payload.getSenderKey();
-
- return affectedContractTransactions.stream()
- .map(AffectedTransaction::getPayload)
- .map(p -> p.getRecipientKeys())
- .anyMatch(r -> r.contains(senderKey));
- }
@Override
@Transactional
