Search in sources :

Example 81 with MessageHash

use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.

the class RecoveryResource method push.

// path /push with application/octet-stream is overloaded (RecoveryResource &
// TransactionResource); swagger annotations cannot handle situations like this so hide this
// operation and use TransactionResource::push to document both
@Hidden
@POST
@Path("push")
@Consumes(APPLICATION_OCTET_STREAM)
public Response push(final byte[] payload, @HeaderParam(Constants.API_VERSION_HEADER) final List<String> headers) {
    LOGGER.debug("Received push request during recovery mode");
    final Set<String> versions = Optional.ofNullable(headers).orElse(emptyList()).stream().filter(Objects::nonNull).flatMap(v -> Arrays.stream(v.split(","))).collect(Collectors.toSet());
    final EncodedPayloadCodec codec = EncodedPayloadCodec.getPreferredCodec(versions);
    final PayloadEncoder payloadEncoder = PayloadEncoder.create(codec);
    final EncodedPayload encodedPayload = payloadEncoder.decode(payload);
    if (encodedPayload.getPrivacyMode() != PrivacyMode.STANDARD_PRIVATE) {
        return Response.status(Response.Status.FORBIDDEN).entity("Transactions with enhanced privacy are not accepted during recovery mode").build();
    }
    final MessageHash messageHash = transactionManager.storePayload(encodedPayload);
    LOGGER.debug("Push request generated hash {}", messageHash);
    return Response.status(Response.Status.CREATED).entity(Objects.toString(messageHash)).build();
}
Also used : java.util(java.util) PrivacyMode(com.quorum.tessera.enclave.PrivacyMode) HeaderParam(jakarta.ws.rs.HeaderParam) LoggerFactory(org.slf4j.LoggerFactory) BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) PushBatchRequest(com.quorum.tessera.p2p.recovery.PushBatchRequest) Valid(jakarta.validation.Valid) NotNull(jakarta.validation.constraints.NotNull) Path(jakarta.ws.rs.Path) Operation(io.swagger.v3.oas.annotations.Operation) Response(jakarta.ws.rs.core.Response) APPLICATION_OCTET_STREAM(jakarta.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) MessageHash(com.quorum.tessera.data.MessageHash) Constants(com.quorum.tessera.shared.Constants) Consumes(jakarta.ws.rs.Consumes) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Logger(org.slf4j.Logger) Hidden(io.swagger.v3.oas.annotations.Hidden) POST(jakarta.ws.rs.POST) Collections.emptyList(java.util.Collections.emptyList) TransactionManager(com.quorum.tessera.transaction.TransactionManager) Collectors(java.util.stream.Collectors) Tag(io.swagger.v3.oas.annotations.tags.Tag) APPLICATION_JSON(jakarta.ws.rs.core.MediaType.APPLICATION_JSON) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) MessageHash(com.quorum.tessera.data.MessageHash) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Hidden(io.swagger.v3.oas.annotations.Hidden)

Aggregations

MessageHash (com.quorum.tessera.data.MessageHash)81 PublicKey (com.quorum.tessera.encryption.PublicKey)56 Test (org.junit.Test)51 Response (jakarta.ws.rs.core.Response)44 Operation (io.swagger.v3.oas.annotations.Operation)21 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)21 SendResponse (com.quorum.tessera.api.SendResponse)17 ReceiveResponse (com.quorum.tessera.transaction.ReceiveResponse)16 SendRequest (com.quorum.tessera.api.SendRequest)15 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)15 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)15 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)13 java.util (java.util)13 Collectors (java.util.stream.Collectors)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)12 TransactionManager (com.quorum.tessera.transaction.TransactionManager)12 Tag (io.swagger.v3.oas.annotations.tags.Tag)11 Valid (jakarta.validation.Valid)11