Remove duplicate code (TODO) in FlexiblePrivacyPrecompiledContract (#3132)

Signed-off-by: Romeet Puhar <Romeet27@outlook.com>

Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/3143/head
RP27 3 years ago committed by GitHub
parent 6ad73e6375
commit db749c128c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/FlexiblePrivacyPrecompiledContract.java

@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
import org.hyperledger.besu.ethereum.privacy.FlexiblePrivacyGroupContract;
import org.hyperledger.besu.ethereum.privacy.FlexibleUtil;
import org.hyperledger.besu.ethereum.privacy.PrivateStateGenesisAllocator;
import org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver;
import org.hyperledger.besu.ethereum.privacy.PrivateTransaction;
@ -46,7 +47,6 @@ import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import org.hyperledger.besu.plugin.data.Hash;
import org.hyperledger.besu.util.Subscribers;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
@ -292,23 +292,14 @@ public class FlexiblePrivacyPrecompiledContract extends PrivacyPrecompiledContra
if (members.isEmpty() && isAddingParticipant) {
// creating a new group, so we are checking whether the privateFrom is one of the members of
// the new group
participantsFromParameter = getParticipantsFromParameter(privateTransaction.getPayload());
participantsFromParameter =
FlexibleUtil.getParticipantsFromParameter(privateTransaction.getPayload());
}
final String base64privateFrom = privateFrom.toBase64String();
return members.contains(base64privateFrom)
|| participantsFromParameter.contains(base64privateFrom);
}
// TODO: this method is copied from DefaultPrivacyController. Fix the duplication in a separate GI
private List<String> getParticipantsFromParameter(final Bytes input) {
final List<String> participants = new ArrayList<>();
final Bytes mungedParticipants = input.slice(4 + 32 + 32);
for (int i = 0; i <= mungedParticipants.size() - 32; i += 32) {
participants.add(mungedParticipants.slice(i, 32).toBase64String());
}
return participants;
}
private String getRemovedParticipantFromParameter(final Bytes input) {
return input.slice(4).toBase64String();
}

Loading…
Cancel
Save