Search in sources :

Example 1 with JsonRpcNoResponse

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcNoResponse in project besu by hyperledger.

the class JsonRpcExecutor method execute.

public JsonRpcResponse execute(final Optional<User> optionalUser, final Tracer tracer, final Context spanContext, final Supplier<Boolean> alive, final JsonObject jsonRpcRequest, final Function<JsonObject, JsonRpcRequest> requestBodyProvider) {
    try {
        final JsonRpcRequest requestBody = requestBodyProvider.apply(jsonRpcRequest);
        final JsonRpcRequestId id = new JsonRpcRequestId(requestBody.getId());
        // Handle notifications
        if (requestBody.isNotification()) {
            // Notifications aren't handled so create empty result for now.
            return new JsonRpcNoResponse();
        }
        final Span span;
        if (tracer != null) {
            span = tracer.spanBuilder(requestBody.getMethod()).setSpanKind(SpanKind.INTERNAL).setParent(spanContext).startSpan();
        } else {
            span = Span.getInvalid();
        }
        final Optional<JsonRpcError> unavailableMethod = validateMethodAvailability(requestBody);
        if (unavailableMethod.isPresent()) {
            span.setStatus(StatusCode.ERROR, "method unavailable");
            return new JsonRpcErrorResponse(id, unavailableMethod.get());
        }
        final JsonRpcMethod method = rpcMethods.get(requestBody.getMethod());
        return rpcProcessor.process(id, method, span, new JsonRpcRequestContext(requestBody, optionalUser, alive));
    } catch (IllegalArgumentException e) {
        try {
            final Integer id = jsonRpcRequest.getInteger("id", null);
            return new JsonRpcErrorResponse(id, INVALID_REQUEST);
        } catch (ClassCastException idNotIntegerException) {
            return new JsonRpcErrorResponse(null, INVALID_REQUEST);
        }
    }
}
Also used : JsonRpcRequestId(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestId) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) JsonRpcError(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError) Span(io.opentelemetry.api.trace.Span) JsonRpcNoResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcNoResponse) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Aggregations

Span (io.opentelemetry.api.trace.Span)1 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)1 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)1 JsonRpcRequestId (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestId)1 JsonRpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod)1 JsonRpcError (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError)1 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)1 JsonRpcNoResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcNoResponse)1