use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class PrivacyGroupManagerProviderTest method provider.
@Test
public void provider() {
try (var enclaveMockedStatic = mockStatic(Enclave.class);
var privacyGroupDAOMockStatic = mockStatic(PrivacyGroupDAO.class);
var batchPrivacyGroupPublisherMockedStatic = mockStatic(BatchPrivacyGroupPublisher.class)) {
enclaveMockedStatic.when(Enclave::create).thenReturn(mock(Enclave.class));
privacyGroupDAOMockStatic.when(PrivacyGroupDAO::create).thenReturn(mock(PrivacyGroupDAO.class));
batchPrivacyGroupPublisherMockedStatic.when(BatchPrivacyGroupPublisher::create).thenReturn(mock(BatchPrivacyGroupPublisher.class));
PrivacyGroupManager result = PrivacyGroupManagerProvider.provider();
assertThat(result).isNotNull();
enclaveMockedStatic.verify(Enclave::create);
enclaveMockedStatic.verifyNoMoreInteractions();
privacyGroupDAOMockStatic.verify(PrivacyGroupDAO::create);
privacyGroupDAOMockStatic.verifyNoMoreInteractions();
batchPrivacyGroupPublisherMockedStatic.verify(BatchPrivacyGroupPublisher::create);
batchPrivacyGroupPublisherMockedStatic.verifyNoMoreInteractions();
}
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class TransactionManagerProvider method provider.
public static TransactionManager provider() {
final TransactionManagerHolder transactionManagerHolder = TransactionManagerHolder.INSTANCE;
if (transactionManagerHolder.getTransactionManager().isPresent()) {
return transactionManagerHolder.getTransactionManager().get();
}
final EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
final Enclave enclave = Enclave.create();
final EncryptedRawTransactionDAO encryptedRawTransactionDAO = EncryptedRawTransactionDAO.create();
LOGGER.debug("Creating ResendManager");
final ResendManager resendManager = ResendManager.create();
LOGGER.debug("Created ResendManager {}", resendManager);
LOGGER.debug("Creating payload publisher");
final PayloadPublisher payloadPublisher = PayloadPublisher.create();
LOGGER.debug("Created payload publisher {}", payloadPublisher);
LOGGER.debug("Creating batchPayloadPublisher");
final BatchPayloadPublisher batchPayloadPublisher = BatchPayloadPublisher.create();
LOGGER.debug("Created batchPayloadPublisher {}", batchPayloadPublisher);
LOGGER.debug("Creating PrivacyHelper");
final PrivacyHelper privacyHelper = PrivacyHelper.create();
LOGGER.debug("Created PrivacyHelper {}", privacyHelper);
int resendBatchSize = 100;
LOGGER.debug("Creating PayloadDigest");
final PayloadDigest messageHashFactory = PayloadDigest.create();
LOGGER.debug("Created PayloadDigest {}", messageHashFactory);
return transactionManagerHolder.store(new TransactionManagerImpl(enclave, encryptedTransactionDAO, encryptedRawTransactionDAO, resendManager, batchPayloadPublisher, privacyHelper, messageHashFactory));
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class BatchWorkflowFactoryImpl method create.
@Override
public BatchWorkflow create(long transactionCount) {
ValidateEnclaveStatus validateEnclaveStatus = new ValidateEnclaveStatus(enclave);
PreparePayloadForRecipient preparePayloadForRecipient = new PreparePayloadForRecipient();
FindRecipientFromPartyInfo findRecipientFromPartyInfo = new FindRecipientFromPartyInfo(discovery);
FilterPayload filterPayload = new FilterPayload(enclave);
SearchRecipientKeyForPayload searchRecipientKeyForPayload = new SearchRecipientKeyForPayload(enclave);
SenderIsNotRecipient senderIsNotRecipient = new SenderIsNotRecipient(enclave);
EncodedPayloadPublisher encodedPayloadPublisher = new EncodedPayloadPublisher(resendBatchPublisher);
List<BatchWorkflowAction> handlers = List.of(validateEnclaveStatus, filterPayload, preparePayloadForRecipient, searchRecipientKeyForPayload, findRecipientFromPartyInfo, senderIsNotRecipient, encodedPayloadPublisher);
return new BatchWorkflow() {
private final AtomicLong filteredMessageCount = new AtomicLong(transactionCount);
@Override
public boolean execute(BatchWorkflowContext context) {
context.setExpectedTotal(filteredMessageCount.get());
boolean outcome = handlers.stream().filter(Predicate.not(h -> h.execute(context))).findFirst().isEmpty();
if (!outcome) {
context.setExpectedTotal(filteredMessageCount.decrementAndGet());
encodedPayloadPublisher.checkOutstandingPayloads(context);
}
return outcome;
}
@Override
public long getPublishedMessageCount() {
return encodedPayloadPublisher.getPublishedCount();
}
};
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class BatchWorkflowFactoryProvider method provider.
public static BatchWorkflowFactory provider() {
Enclave enclave = Enclave.create();
Discovery discovery = Discovery.create();
ResendBatchPublisher resendBatchPublisher = ResendBatchPublisher.create();
return new BatchWorkflowFactoryImpl(enclave, discovery, resendBatchPublisher);
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class LegacyResendManagerImpl method resendIndividual.
protected ResendResponse resendIndividual(final PublicKey targetResendKey, final MessageHash messageHash) {
final EncryptedTransaction encryptedTransaction = encryptedTransactionDAO.retrieveByHash(messageHash).orElseThrow(() -> new TransactionNotFoundException("Message with hash " + messageHash + " was not found"));
final EncodedPayload payload = encryptedTransaction.getPayload();
if (payload.getPrivacyMode() != PrivacyMode.STANDARD_PRIVATE) {
throw new EnhancedPrivacyNotSupportedException("Cannot resend enhanced privacy transaction in legacy resend");
}
if (!Objects.equals(payload.getSenderKey(), targetResendKey)) {
final EncodedPayload formattedPayload = EncodedPayload.Builder.forRecipient(payload, targetResendKey).build();
return ResendResponse.Builder.create().withPayload(formattedPayload).build();
}
// split all the boxes out into their own payload
final Set<EncodedPayload> allTxns = payload.getRecipientBoxes().stream().map(box -> EncodedPayload.Builder.from(payload).withNewRecipientKeys(Collections.emptyList()).withRecipientBoxes(List.of(box.getData())).build()).collect(Collectors.toSet());
final BatchWorkflowContext context = new BatchWorkflowContext();
context.setPayloadsToPublish(allTxns);
context.setEncryptedTransaction(encryptedTransaction);
new SearchRecipientKeyForPayload(enclave).execute(context);
final EncodedPayload.Builder builder = EncodedPayload.Builder.from(payload).withNewRecipientKeys(new ArrayList<>()).withRecipientBoxes(new ArrayList<>());
context.getPayloadsToPublish().forEach(formattedPayload -> {
builder.withRecipientKey(formattedPayload.getRecipientKeys().get(0));
builder.withRecipientBox(formattedPayload.getRecipientBoxes().get(0).getData());
});
return ResendResponse.Builder.create().withPayload(builder.build()).build();
}
Aggregations