Search in sources :

Example 21 with PayloadEncoder

use of com.quorum.tessera.enclave.PayloadEncoder in project tessera by ConsenSys.

the class StagingTransactionListener method onLoad.

@PostLoad
public void onLoad(StagingTransaction stagingTransaction) {
    LOGGER.debug("onLoad[{}]", stagingTransaction);
    final EncodedPayloadCodec encodedPayloadCodec = stagingTransaction.getEncodedPayloadCodec();
    final byte[] encodedPayloadData = stagingTransaction.getPayload();
    final PayloadEncoder payloadEncoder = PayloadEncoder.create(encodedPayloadCodec);
    final EncodedPayload encodedPayload = payloadEncoder.decode(encodedPayloadData);
    stagingTransaction.setEncodedPayload(encodedPayload);
}
Also used : PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) PostLoad(jakarta.persistence.PostLoad)

Example 22 with PayloadEncoder

use of com.quorum.tessera.enclave.PayloadEncoder in project tessera by ConsenSys.

the class EncryptedTransactionListener method onSave.

@PrePersist
public void onSave(EncryptedTransaction encryptedTransaction) {
    LOGGER.debug("onSave {}", encryptedTransaction);
    final EncodedPayload encodedPayload = encryptedTransaction.getPayload();
    final EncodedPayloadCodec encodedPayloadCodec = EncodedPayloadCodec.current();
    final PayloadEncoder payloadEncoder = PayloadEncoder.create(encodedPayloadCodec);
    final byte[] encodedPayloadData = payloadEncoder.encode(encodedPayload);
    encryptedTransaction.setEncodedPayloadCodec(encodedPayloadCodec);
    encryptedTransaction.setEncodedPayload(encodedPayloadData);
}
Also used : PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) PrePersist(jakarta.persistence.PrePersist)

Example 23 with PayloadEncoder

use of com.quorum.tessera.enclave.PayloadEncoder in project tessera by ConsenSys.

the class EncryptedTransactionListener method onLoad.

@PostLoad
public void onLoad(EncryptedTransaction encryptedTransaction) {
    LOGGER.debug("onLoad[{}]", encryptedTransaction);
    final EncodedPayloadCodec encodedPayloadCodec = Optional.ofNullable(encryptedTransaction.getEncodedPayloadCodec()).orElse(EncodedPayloadCodec.LEGACY);
    final byte[] encodedPayloadData = encryptedTransaction.getEncodedPayload();
    final PayloadEncoder payloadEncoder = PayloadEncoder.create(encodedPayloadCodec);
    final EncodedPayload encodedPayload = payloadEncoder.decode(encodedPayloadData);
    encryptedTransaction.setPayload(encodedPayload);
    encryptedTransaction.setEncodedPayloadCodec(encodedPayloadCodec);
}
Also used : PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) PostLoad(jakarta.persistence.PostLoad)

Example 24 with PayloadEncoder

use of com.quorum.tessera.enclave.PayloadEncoder in project tessera by ConsenSys.

the class RestResendBatchPublisherTest method publishBatchRecoveryClientFails.

@Test
public void publishBatchRecoveryClientFails() {
    PayloadEncoder payloadEncoder = mock(PayloadEncoder.class);
    RecoveryClient recoveryClient = mock(RecoveryClient.class);
    ArgumentCaptor<PushBatchRequest> requestArgumentCaptor = ArgumentCaptor.forClass(PushBatchRequest.class);
    when(recoveryClient.pushBatch(anyString(), requestArgumentCaptor.capture())).thenReturn(false);
    List<EncodedPayload> encodedPayloads = payloadDatList.stream().map(o -> {
        EncodedPayload encodedPayload = mock(EncodedPayload.class);
        when(payloadEncoder.encode(encodedPayload)).thenReturn(o);
        return encodedPayload;
    }).collect(Collectors.toList());
    RestResendBatchPublisher restRecoveryClient = new RestResendBatchPublisher(payloadEncoder, recoveryClient);
    PublishPayloadException ex = catchThrowableOfType(() -> restRecoveryClient.publishBatch(encodedPayloads, targetUrl), PublishPayloadException.class);
    assertThat(ex).hasMessage(String.format("Unable to push payload batch to recipient %s", targetUrl));
    verify(recoveryClient).pushBatch(targetUrl, requestArgumentCaptor.getValue());
    encodedPayloads.forEach(p -> {
        verify(payloadEncoder).encode(p);
    });
    assertThat(requestArgumentCaptor.getValue().getEncodedPayloads()).isEqualTo(payloadDatList);
    verifyNoMoreInteractions(recoveryClient);
    verifyNoMoreInteractions(payloadEncoder);
}
Also used : IntStream(java.util.stream.IntStream) Assertions.catchThrowableOfType(org.assertj.core.api.Assertions.catchThrowableOfType) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) PublishPayloadException(com.quorum.tessera.transaction.publish.PublishPayloadException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collection(java.util.Collection) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) List(java.util.List) ArgumentCaptor(org.mockito.ArgumentCaptor) Map(java.util.Map) Parameterized(org.junit.runners.Parameterized) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) PublishPayloadException(com.quorum.tessera.transaction.publish.PublishPayloadException) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Example 25 with PayloadEncoder

use of com.quorum.tessera.enclave.PayloadEncoder in project tessera by ConsenSys.

the class RestResendBatchPublisherTest method publishBatch.

@Test
public void publishBatch() {
    PayloadEncoder payloadEncoder = mock(PayloadEncoder.class);
    RecoveryClient recoveryClient = mock(RecoveryClient.class);
    ArgumentCaptor<PushBatchRequest> requestArgumentCaptor = ArgumentCaptor.forClass(PushBatchRequest.class);
    when(recoveryClient.pushBatch(anyString(), requestArgumentCaptor.capture())).thenReturn(true);
    List<EncodedPayload> encodedPayloads = payloadDatList.stream().map(o -> {
        EncodedPayload encodedPayload = mock(EncodedPayload.class);
        when(payloadEncoder.encode(encodedPayload)).thenReturn(o);
        return encodedPayload;
    }).collect(Collectors.toList());
    RestResendBatchPublisher restRecoveryClient = new RestResendBatchPublisher(payloadEncoder, recoveryClient);
    restRecoveryClient.publishBatch(encodedPayloads, targetUrl);
    verify(recoveryClient).pushBatch(targetUrl, requestArgumentCaptor.getValue());
    encodedPayloads.forEach(p -> {
        verify(payloadEncoder).encode(p);
    });
    assertThat(requestArgumentCaptor.getValue().getEncodedPayloads()).isEqualTo(payloadDatList);
    verifyNoMoreInteractions(recoveryClient);
    verifyNoMoreInteractions(payloadEncoder);
}
Also used : IntStream(java.util.stream.IntStream) Assertions.catchThrowableOfType(org.assertj.core.api.Assertions.catchThrowableOfType) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) PublishPayloadException(com.quorum.tessera.transaction.publish.PublishPayloadException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collection(java.util.Collection) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) List(java.util.List) ArgumentCaptor(org.mockito.ArgumentCaptor) Map(java.util.Map) Parameterized(org.junit.runners.Parameterized) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Aggregations

PayloadEncoder (com.quorum.tessera.enclave.PayloadEncoder)27 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)23 EncodedPayloadCodec (com.quorum.tessera.enclave.EncodedPayloadCodec)10 Response (jakarta.ws.rs.core.Response)6 Collectors (java.util.stream.Collectors)5 MessageHash (com.quorum.tessera.data.MessageHash)3 ResendRequest (com.quorum.tessera.p2p.resend.ResendRequest)3 PublishPayloadException (com.quorum.tessera.transaction.publish.PublishPayloadException)3 Operation (io.swagger.v3.oas.annotations.Operation)3 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)3 java.util (java.util)3 IntStream (java.util.stream.IntStream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Test (org.junit.Test)3 RunWith (org.junit.runner.RunWith)3 Parameterized (org.junit.runners.Parameterized)3 Mockito (org.mockito.Mockito)3 PublicKey (com.quorum.tessera.encryption.PublicKey)2 ResendBatchResponse (com.quorum.tessera.recovery.resend.ResendBatchResponse)2 BatchResendManager (com.quorum.tessera.recovery.workflow.BatchResendManager)2