Search in sources :

Example 1 with MultiTenancyPrivacyController

use of org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController in project besu by hyperledger.

the class PrivUnsubscribe method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    try {
        final PrivateUnsubscribeRequest unsubscribeRequest = getMapper().mapPrivateUnsubscribeRequest(requestContext);
        if (privacyController instanceof MultiTenancyPrivacyController) {
            checkIfPrivacyGroupMatchesAuthenticatedPrivacyUserId(requestContext, unsubscribeRequest.getPrivacyGroupId());
        }
        final boolean unsubscribed = subscriptionManager().unsubscribe(unsubscribeRequest);
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), unsubscribed);
    } catch (final InvalidSubscriptionRequestException isEx) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST);
    } catch (final SubscriptionNotFoundException snfEx) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.SUBSCRIPTION_NOT_FOUND);
    }
}
Also used : PrivateUnsubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateUnsubscribeRequest) SubscriptionNotFoundException(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) InvalidSubscriptionRequestException(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException) MultiTenancyPrivacyController(org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 2 with MultiTenancyPrivacyController

use of org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController in project besu by hyperledger.

the class PrivNewFilter method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext request) {
    final String privacyGroupId = request.getRequiredParameter(0, String.class);
    final FilterParameter filter = request.getRequiredParameter(1, FilterParameter.class);
    final String privacyUserId = privacyIdProvider.getPrivacyUserId(request.getUser());
    if (privacyController instanceof MultiTenancyPrivacyController) {
        // no need to pass blockNumber. To create a filter, you need to be a current member of the
        // group
        checkIfPrivacyGroupMatchesAuthenticatedPrivacyUserId(privacyUserId, privacyGroupId);
    }
    if (!filter.isValid()) {
        return new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
    }
    final String logFilterId = filterManager.installPrivateLogFilter(privacyGroupId, privacyUserId, filter.getFromBlock(), filter.getToBlock(), filter.getLogsQuery());
    return new JsonRpcSuccessResponse(request.getRequest().getId(), logFilterId);
}
Also used : JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) FilterParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter) MultiTenancyPrivacyController(org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 3 with MultiTenancyPrivacyController

use of org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController in project besu by hyperledger.

the class PrivGetFilterLogs method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext request) {
    final String privacyGroupId = request.getRequiredParameter(0, String.class);
    final String filterId = request.getRequiredParameter(1, String.class);
    if (privacyController instanceof MultiTenancyPrivacyController) {
        checkIfPrivacyGroupMatchesAuthenticatedPrivacyUserId(request, privacyGroupId);
    }
    final List<LogWithMetadata> logs = filterManager.logs(filterId);
    if (logs != null) {
        return new JsonRpcSuccessResponse(request.getRequest().getId(), new LogsResult(logs));
    }
    return new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.LOGS_FILTER_NOT_FOUND);
}
Also used : LogWithMetadata(org.hyperledger.besu.ethereum.core.LogWithMetadata) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) LogsResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult) MultiTenancyPrivacyController(org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 4 with MultiTenancyPrivacyController

use of org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController in project besu by hyperledger.

the class PrivGetFilterChanges method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    final String privacyGroupId = requestContext.getRequiredParameter(0, String.class);
    final String filterId = requestContext.getRequiredParameter(1, String.class);
    if (privacyController instanceof MultiTenancyPrivacyController) {
        checkIfPrivacyGroupMatchesAuthenticatedPrivacyUserId(requestContext, privacyGroupId);
    }
    final List<LogWithMetadata> logs = filterManager.logsChanges(filterId);
    if (logs != null) {
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), new LogsResult(logs));
    }
    return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.FILTER_NOT_FOUND);
}
Also used : LogWithMetadata(org.hyperledger.besu.ethereum.core.LogWithMetadata) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) LogsResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult) MultiTenancyPrivacyController(org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 5 with MultiTenancyPrivacyController

use of org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController in project besu by hyperledger.

the class PrivSubscribe method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    try {
        final String privacyUserId = privacyIdProvider.getPrivacyUserId(requestContext.getUser());
        final PrivateSubscribeRequest subscribeRequest = getMapper().mapPrivateSubscribeRequest(requestContext, privacyUserId);
        if (privacyController instanceof MultiTenancyPrivacyController) {
            checkIfPrivacyGroupMatchesAuthenticatedPrivacyUserId(requestContext, subscribeRequest.getPrivacyGroupId());
        }
        final Long subscriptionId = subscriptionManager().subscribe(subscribeRequest);
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), Quantity.create(subscriptionId));
    } catch (final InvalidSubscriptionRequestException isEx) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST);
    }
}
Also used : PrivateSubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) InvalidSubscriptionRequestException(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException) MultiTenancyPrivacyController(org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Aggregations

JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)5 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)5 MultiTenancyPrivacyController (org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController)5 LogsResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult)2 InvalidSubscriptionRequestException (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException)2 LogWithMetadata (org.hyperledger.besu.ethereum.core.LogWithMetadata)2 FilterParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter)1 SubscriptionNotFoundException (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException)1 PrivateSubscribeRequest (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest)1 PrivateUnsubscribeRequest (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateUnsubscribeRequest)1