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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations