use of com.quorum.tessera.transaction.TransactionManager in project tessera by ConsenSys.
the class TransactionResource4 method send.
@POST
@Path("send")
@Consumes({ MIME_TYPE_JSON_4 })
@Produces({ MIME_TYPE_JSON_4 })
public Response send(@NotNull @Valid @PrivacyValid final SendRequest sendRequest) {
final PublicKey sender = Optional.ofNullable(sendRequest.getFrom()).map(base64Decoder::decode).map(PublicKey::from).orElseGet(transactionManager::defaultPublicKey);
final Optional<PrivacyGroup.Id> privacyGroupId = Optional.ofNullable(sendRequest.getPrivacyGroupId()).map(PrivacyGroup.Id::fromBase64String);
final List<PublicKey> recipientList = privacyGroupId.map(privacyGroupManager::retrievePrivacyGroup).map(PrivacyGroup::getMembers).orElse(Stream.of(sendRequest).filter(sr -> Objects.nonNull(sr.getTo())).flatMap(s -> Stream.of(s.getTo())).map(base64Decoder::decode).map(PublicKey::from).collect(Collectors.toList()));
final Set<MessageHash> affectedTransactions = Stream.ofNullable(sendRequest.getAffectedContractTransactions()).flatMap(Arrays::stream).map(base64Decoder::decode).map(MessageHash::new).collect(Collectors.toSet());
final byte[] execHash = Optional.ofNullable(sendRequest.getExecHash()).map(String::getBytes).orElse(new byte[0]);
final PrivacyMode privacyMode = PrivacyMode.fromFlag(sendRequest.getPrivacyFlag());
final Set<PublicKey> mandatoryRecipients = Stream.ofNullable(sendRequest.getMandatoryRecipients()).flatMap(Arrays::stream).map(base64Decoder::decode).map(PublicKey::from).collect(Collectors.toUnmodifiableSet());
final com.quorum.tessera.transaction.SendRequest.Builder requestBuilder = com.quorum.tessera.transaction.SendRequest.Builder.create().withRecipients(recipientList).withSender(sender).withPayload(sendRequest.getPayload()).withExecHash(execHash).withPrivacyMode(privacyMode).withAffectedContractTransactions(affectedTransactions).withMandatoryRecipients(mandatoryRecipients);
privacyGroupId.ifPresent(requestBuilder::withPrivacyGroupId);
final com.quorum.tessera.transaction.SendResponse response = transactionManager.send(requestBuilder.build());
final String encodedKey = Optional.of(response).map(com.quorum.tessera.transaction.SendResponse::getTransactionHash).map(MessageHash::getHashBytes).map(base64Encoder::encodeToString).get();
final String[] managedParties = Optional.of(response).map(com.quorum.tessera.transaction.SendResponse::getManagedParties).orElse(Collections.emptySet()).stream().map(PublicKey::encodeToBase64).toArray(String[]::new);
final SendResponse sendResponse = Optional.of(response).map(com.quorum.tessera.transaction.SendResponse::getTransactionHash).map(MessageHash::getHashBytes).map(base64Encoder::encodeToString).map(messageHash -> new SendResponse(messageHash, managedParties, sender.encodeToBase64())).get();
final URI location = UriBuilder.fromPath("transaction").path(URLEncoder.encode(encodedKey, StandardCharsets.UTF_8)).build();
return Response.created(location).entity(sendResponse).build();
}
use of com.quorum.tessera.transaction.TransactionManager in project tessera by ConsenSys.
the class TransactionManagerHolderTest method storeAndGet.
@Test
public void storeAndGet() {
TransactionManagerHolder transactionManagerHolder = TransactionManagerHolder.INSTANCE;
assertThat(transactionManagerHolder.getTransactionManager()).isNotPresent();
TransactionManager transactionManager = mock(TransactionManager.class);
assertThat(transactionManagerHolder.store(transactionManager)).isSameAs(transactionManager);
assertThat(transactionManagerHolder.getTransactionManager()).containsSame(transactionManager);
}
use of com.quorum.tessera.transaction.TransactionManager in project tessera by ConsenSys.
the class TransactionManagerProviderTest method provider.
@Test
public void provider() {
try (var mockedStaticConfigFactory = mockStatic(ConfigFactory.class);
var mockedStaticEncryptedTransactionDAO = mockStatic(EncryptedTransactionDAO.class);
var mockedStaticEnclave = mockStatic(Enclave.class);
var mockedStaticEncryptedRawTransactionDAO = mockStatic(EncryptedRawTransactionDAO.class);
var mockedStaticPayloadPublisher = mockStatic(PayloadPublisher.class);
var mockedStaticBatchPayloadPublisher = mockStatic(BatchPayloadPublisher.class);
var mockedStaticPrivacyHelper = mockStatic(PrivacyHelper.class);
var mockedStaticResendManager = mockStatic(ResendManager.class);
var mockedStaticPayloadDigest = mockStatic(PayloadDigest.class)) {
ConfigFactory configFactory = mock(ConfigFactory.class);
Config config = mock(Config.class);
when(configFactory.getConfig()).thenReturn(config);
mockedStaticConfigFactory.when(ConfigFactory::create).thenReturn(configFactory);
PayloadPublisher payloadPublisher = mock(PayloadPublisher.class);
mockedStaticPayloadPublisher.when(PayloadPublisher::create).thenReturn(payloadPublisher);
BatchPayloadPublisher batchPayloadPublisher = mock(BatchPayloadPublisher.class);
mockedStaticBatchPayloadPublisher.when(BatchPayloadPublisher::create).thenReturn(batchPayloadPublisher);
mockedStaticEncryptedRawTransactionDAO.when(EncryptedRawTransactionDAO::create).thenReturn(mock(EncryptedRawTransactionDAO.class));
mockedStaticEnclave.when(Enclave::create).thenReturn(mock(Enclave.class));
mockedStaticEncryptedTransactionDAO.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
mockedStaticPrivacyHelper.when(PrivacyHelper::create).thenReturn(mock(PrivacyHelper.class));
mockedStaticResendManager.when(ResendManager::create).thenReturn(mock(ResendManager.class));
mockedStaticPayloadDigest.when(PayloadDigest::create).thenReturn(mock(PayloadDigest.class));
TransactionManager transactionManager = TransactionManagerProvider.provider();
assertThat(transactionManager).isNotNull();
assertThat(TransactionManagerProvider.provider()).describedAs("Second invocation should return same instance").isSameAs(transactionManager);
mockedStaticEncryptedTransactionDAO.verify(EncryptedTransactionDAO::create);
mockedStaticEncryptedTransactionDAO.verifyNoMoreInteractions();
mockedStaticEnclave.verify(Enclave::create);
mockedStaticEnclave.verifyNoMoreInteractions();
mockedStaticEncryptedRawTransactionDAO.verify(EncryptedRawTransactionDAO::create);
mockedStaticEncryptedRawTransactionDAO.verifyNoMoreInteractions();
mockedStaticPayloadPublisher.verify(PayloadPublisher::create);
mockedStaticPayloadPublisher.verifyNoMoreInteractions();
mockedStaticBatchPayloadPublisher.verify(BatchPayloadPublisher::create);
mockedStaticBatchPayloadPublisher.verifyNoMoreInteractions();
mockedStaticPrivacyHelper.verify(PrivacyHelper::create);
mockedStaticPrivacyHelper.verifyNoMoreInteractions();
mockedStaticResendManager.verify(ResendManager::create);
mockedStaticResendManager.verifyNoMoreInteractions();
mockedStaticPayloadDigest.verify(PayloadDigest::create);
mockedStaticPayloadDigest.verifyNoMoreInteractions();
}
}
use of com.quorum.tessera.transaction.TransactionManager in project tessera by ConsenSys.
the class RecoveryProviderTest method provider.
@Test
public void provider() {
try (var staticStagingEntityDAO = mockStatic(StagingEntityDAO.class);
var staticDiscovery = mockStatic(Discovery.class);
var staticBatchTransactionRequester = mockStatic(BatchTransactionRequester.class);
var staticTransactionManager = mockStatic(TransactionManager.class)) {
staticStagingEntityDAO.when(StagingEntityDAO::create).thenReturn(mock(StagingEntityDAO.class));
staticDiscovery.when(Discovery::create).thenReturn(mock(Discovery.class));
staticBatchTransactionRequester.when(BatchTransactionRequester::create).thenReturn(mock(BatchTransactionRequester.class));
TransactionManager transactionManager = mock(TransactionManager.class);
staticTransactionManager.when(TransactionManager::create).thenReturn(transactionManager);
Recovery recovery = RecoveryProvider.provider();
assertThat(recovery).isNotNull().isExactlyInstanceOf(RecoveryImpl.class);
staticStagingEntityDAO.verify(StagingEntityDAO::create);
staticStagingEntityDAO.verifyNoMoreInteractions();
verifyNoMoreInteractions(transactionManager);
staticDiscovery.verify(Discovery::create);
staticDiscovery.verifyNoMoreInteractions();
staticBatchTransactionRequester.verify(BatchTransactionRequester::create);
staticBatchTransactionRequester.verifyNoMoreInteractions();
staticTransactionManager.verify(TransactionManager::create);
staticTransactionManager.verifyNoMoreInteractions();
}
}
use of com.quorum.tessera.transaction.TransactionManager in project tessera by ConsenSys.
the class RecoveryProvider method provider.
public static Recovery provider() {
StagingEntityDAO stagingEntityDAO = StagingEntityDAO.create();
Discovery discovery = Discovery.create();
BatchTransactionRequester batchTransactionRequester = BatchTransactionRequester.create();
TransactionManager transactionManager = TransactionManager.create();
return new RecoveryImpl(stagingEntityDAO, discovery, batchTransactionRequester, transactionManager);
}
Aggregations