5098 branch 17 update extra data and filter params (#7458)

* 5098: Add RpcErrorTypes

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

---------

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda-Clerke <matilda.clerke@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/7473/head
Matilda-Clerke 3 months ago committed by GitHub
parent 137515de44
commit f5d6e7237c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterChanges.java
  2. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterLogs.java
  3. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java
  4. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthNewFilter.java
  5. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthUninstallFilter.java
  6. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java
  7. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java
  8. 17
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/PendingTransactionsParams.java
  9. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java
  10. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java
  11. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java
  12. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java
  13. 12
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java
  14. 18
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/request/SubscriptionRequestMapper.java
  15. 5
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterChangesTest.java
  16. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterLogsTest.java
  17. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogsTest.java
  18. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthNewFilterTest.java
  19. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraDataTest.java
  20. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetFilterChangesTest.java
  21. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetFilterLogsTest.java
  22. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogsTest.java
  23. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilterTest.java
  24. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivUninstallFilterTest.java
  25. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/request/SubscriptionRequestMapperTest.java
  26. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getLogs_invalidInput.json
  27. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getNewFilter_invalidFilter.json

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
@ -43,7 +44,13 @@ public class EthGetFilterChanges implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final String filterId = requestContext.getRequiredParameter(0, String.class);
final String filterId;
try {
filterId = requestContext.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter ID parameter (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
final List<Hash> blockHashes = filterManager.blockChanges(filterId);
if (blockHashes != null) {

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
@ -41,7 +42,13 @@ public class EthGetFilterLogs implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final String filterId = requestContext.getRequiredParameter(0, String.class);
final String filterId;
try {
filterId = requestContext.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter ID parameter (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
final List<LogWithMetadata> logs = filterManager.logs(filterId);
if (logs != null) {

@ -52,12 +52,18 @@ public class EthGetLogs implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final FilterParameter filter = requestContext.getRequiredParameter(0, FilterParameter.class);
final FilterParameter filter;
try {
filter = requestContext.getRequiredParameter(0, FilterParameter.class);
} catch (Exception e) {
throw new InvalidJsonRpcParameters(
"Invalid filter parameter (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
LOG.atTrace().setMessage("eth_getLogs FilterParameter: {}").addArgument(filter).log();
if (!filter.isValid()) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_FILTER_PARAMS);
}
final AtomicReference<Exception> ex = new AtomicReference<>();

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
@ -38,11 +39,17 @@ public class EthNewFilter implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final FilterParameter filter = requestContext.getRequiredParameter(0, FilterParameter.class);
final FilterParameter filter;
try {
filter = requestContext.getRequiredParameter(0, FilterParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter paramters (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
if (!filter.isValid()) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_FILTER_PARAMS);
}
final String logFilterId =

@ -16,9 +16,11 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
public class EthUninstallFilter implements JsonRpcMethod {
@ -35,7 +37,13 @@ public class EthUninstallFilter implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final String filterId = requestContext.getRequiredParameter(0, String.class);
final String filterId;
try {
filterId = requestContext.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter ID parameter (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
return new JsonRpcSuccessResponse(
requestContext.getRequest().getId(), filterManager.uninstallFilter(filterId));

@ -19,6 +19,7 @@ import static org.hyperledger.besu.services.pipeline.PipelineBuilder.createPipel
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer;
@ -86,8 +87,13 @@ public class TraceFilter extends TraceBlock {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final FilterParameter filterParameter =
requestContext.getRequiredParameter(0, FilterParameter.class);
final FilterParameter filterParameter;
try {
filterParameter = requestContext.getRequiredParameter(0, FilterParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter parameter (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
final long fromBlock = resolveBlockNumber(filterParameter.getFromBlock());
final long toBlock = resolveBlockNumber(filterParameter.getToBlock());

@ -60,10 +60,12 @@ public class MinerSetExtraData implements JsonRpcMethod {
.addArgument(() -> new String(extraData.toArray(), StandardCharsets.UTF_8))
.log();
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true);
} catch (final IllegalArgumentException invalidJsonRpcParameters) {
} catch (Exception invalidJsonRpcParameters) { // TODO:replace with "IllegalArgumentException |
// JsonRpcParameter.JsonRpcParameterException"
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(),
new JsonRpcError(RpcErrorType.INVALID_PARAMS, invalidJsonRpcParameters.getMessage()));
new JsonRpcError(
RpcErrorType.INVALID_EXTRA_DATA_PARAMS, invalidJsonRpcParameters.getMessage()));
}
}
}

@ -24,6 +24,7 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.transac
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.transaction.pool.Predicate.EQ;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.transaction.pool.PendingTransactionFilter.Filter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.transaction.pool.Predicate;
@ -79,7 +80,8 @@ public class PendingTransactionsParams {
private Optional<Filter> getFilter(final String key, final Map<String, String> map) {
if (map != null) {
if (map.size() > 1) {
throw new InvalidJsonRpcParameters("Only one operator per filter type allowed");
throw new InvalidJsonRpcParameters(
"Only one operator per filter type allowed", RpcErrorType.INVALID_FILTER_PARAMS);
} else if (!map.isEmpty()) {
final Map.Entry<String, String> foundEntry = map.entrySet().stream().findFirst().get();
final Predicate predicate =
@ -87,17 +89,22 @@ public class PendingTransactionsParams {
.orElseThrow(
() ->
new InvalidJsonRpcParameters(
"Unknown field expected one of `eq`, `gt`, `lt`, `action`"));
"Unknown field expected one of `eq`, `gt`, `lt`, `action`",
RpcErrorType.INVALID_FILTER_PARAMS));
final Filter filter = new Filter(key, foundEntry.getValue(), predicate);
if (key.equals(FROM_FIELD) && !predicate.equals(EQ)) {
throw new InvalidJsonRpcParameters("The `from` filter only supports the `eq` operator");
throw new InvalidJsonRpcParameters(
"The `from` filter only supports the `eq` operator",
RpcErrorType.INVALID_FILTER_PARAMS);
} else if (key.equals(TO_FIELD) && !predicate.equals(EQ) && !predicate.equals(ACTION)) {
throw new InvalidJsonRpcParameters(
"The `to` filter only supports the `eq` or `action` operator");
"The `to` filter only supports the `eq` or `action` operator",
RpcErrorType.INVALID_FILTER_PARAMS);
} else if (!key.equals(TO_FIELD) && predicate.equals(ACTION)) {
throw new InvalidJsonRpcParameters(
"The operator `action` is only supported by the `to` filter");
"The operator `action` is only supported by the `to` filter",
RpcErrorType.INVALID_FILTER_PARAMS);
}
return Optional.of(filter);
}

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
@ -52,7 +53,13 @@ public class PrivGetFilterChanges implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final String privacyGroupId = requestContext.getRequiredParameter(0, String.class);
final String filterId = requestContext.getRequiredParameter(1, String.class);
final String filterId;
try {
filterId = requestContext.getRequiredParameter(1, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter ID parameter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
if (privacyController instanceof MultiTenancyPrivacyController) {
checkIfPrivacyGroupMatchesAuthenticatedPrivacyUserId(requestContext, privacyGroupId);

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
@ -52,7 +53,13 @@ public class PrivGetFilterLogs implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext request) {
final String privacyGroupId = request.getRequiredParameter(0, String.class);
final String filterId = request.getRequiredParameter(1, String.class);
final String filterId;
try {
filterId = request.getRequiredParameter(1, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter ID parameter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
if (privacyController instanceof MultiTenancyPrivacyController) {
checkIfPrivacyGroupMatchesAuthenticatedPrivacyUserId(request, privacyGroupId);

@ -16,10 +16,12 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController;
import org.hyperledger.besu.ethereum.privacy.PrivacyController;
@ -46,7 +48,13 @@ public class PrivUninstallFilter implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext request) {
final String privacyGroupId = request.getRequiredParameter(0, String.class);
final String filterId = request.getRequiredParameter(1, String.class);
final String filterId;
try {
filterId = request.getRequiredParameter(1, String.class);
} catch (Exception e) {
throw new InvalidJsonRpcParameters(
"Invalid filter ID paramter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
if (privacyController instanceof MultiTenancyPrivacyController) {
checkIfPrivacyGroupMatchesAuthenticatedEnclaveKey(request, privacyGroupId);

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider;
@ -62,11 +63,17 @@ public class PrivGetLogs implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final String privacyGroupId = requestContext.getRequiredParameter(0, String.class);
final FilterParameter filter = requestContext.getRequiredParameter(1, FilterParameter.class);
final FilterParameter filter;
try {
filter = requestContext.getRequiredParameter(1, FilterParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter parameter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
if (!filter.isValid()) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_FILTER_PARAMS);
}
final List<LogWithMetadata> matchingLogs =

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter;
@ -50,7 +51,13 @@ public class PrivNewFilter implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext request) {
final String privacyGroupId = request.getRequiredParameter(0, String.class);
final FilterParameter filter = request.getRequiredParameter(1, FilterParameter.class);
final FilterParameter filter;
try {
filter = request.getRequiredParameter(1, FilterParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter parameter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
final String privacyUserId = privacyIdProvider.getPrivacyUserId(request.getUser());
if (privacyController instanceof MultiTenancyPrivacyController) {
@ -60,7 +67,8 @@ public class PrivNewFilter implements JsonRpcMethod {
}
if (!filter.isValid()) {
return new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
return new JsonRpcErrorResponse(
request.getRequest().getId(), RpcErrorType.INVALID_FILTER_PARAMS);
}
final String logFilterId =

@ -15,8 +15,10 @@
package org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketRpcRequest;
import java.util.Optional;
@ -70,7 +72,13 @@ public class SubscriptionRequestMapper {
}
private SubscribeRequest parseLogsRequest(final WebSocketRpcRequest request) {
final FilterParameter filterParameter = request.getRequiredParameter(1, FilterParameter.class);
final FilterParameter filterParameter;
try {
filterParameter = request.getRequiredParameter(1, FilterParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter parameters (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
return new SubscribeRequest(
SubscriptionType.LOGS, filterParameter, null, request.getConnectionId());
}
@ -101,8 +109,14 @@ public class SubscriptionRequestMapper {
switch (subscriptionType) {
case LOGS:
{
final FilterParameter filterParameter =
final FilterParameter filterParameter;
try {
filterParameter =
jsonRpcRequestContext.getRequiredParameter(2, FilterParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid filter parameter (index 2)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
return new PrivateSubscribeRequest(
SubscriptionType.LOGS,
filterParameter,

@ -69,9 +69,8 @@ public class EthGetFilterChangesTest {
final Throwable thrown = catchThrowable(() -> method.response(request));
assertThat(thrown)
.hasNoCause()
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Missing required json rpc parameter at index 0");
.hasMessage("Invalid filter ID parameter (index 0)");
verifyNoInteractions(filterManager);
}
@ -83,7 +82,7 @@ public class EthGetFilterChangesTest {
final Throwable thrown = catchThrowable(() -> method.response(request));
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Missing required json rpc parameter at index 0");
.hasMessage("Invalid filter ID parameter (index 0)");
verifyNoInteractions(filterManager);
}

@ -70,7 +70,7 @@ public class EthGetFilterLogsTest {
final Throwable thrown = catchThrowable(() -> method.response(request));
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Missing required json rpc parameter at index 0");
.hasMessage("Invalid filter ID parameter (index 0)");
verifyNoInteractions(filterManager);
}
@ -82,7 +82,7 @@ public class EthGetFilterLogsTest {
final Throwable thrown = catchThrowable(() -> method.response(request));
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Missing required json rpc parameter at index 0");
.hasMessage("Invalid filter ID parameter (index 0)");
verifyNoInteractions(filterManager);
}

@ -73,7 +73,7 @@ public class EthGetLogsTest {
final Throwable thrown = catchThrowable(() -> method.response(request));
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Missing required json rpc parameter at index 0");
.hasMessage("Invalid filter parameter (index 0)");
verifyNoInteractions(blockchainQueries);
}

@ -182,7 +182,7 @@ public class EthNewFilterTest {
final JsonRpcRequestContext request = ethNewFilter(invalidFilter);
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(null, RpcErrorType.INVALID_FILTER_PARAMS);
final JsonRpcResponse response = method.response(request);

@ -83,7 +83,7 @@ public class MinerSetExtraDataTest {
new JsonRpcErrorResponse(
request.getRequest().getId(),
new JsonRpcError(
RpcErrorType.INVALID_PARAMS,
RpcErrorType.INVALID_EXTRA_DATA_PARAMS,
"Illegal character 'n' found at index 0 in hex binary representation"));
final JsonRpcResponse actual = method.response(request);
@ -100,7 +100,7 @@ public class MinerSetExtraDataTest {
new JsonRpcErrorResponse(
request.getRequest().getId(),
new JsonRpcError(
RpcErrorType.INVALID_PARAMS,
RpcErrorType.INVALID_EXTRA_DATA_PARAMS,
"Hex value is too large: expected at most 32 bytes but got 37"));
final JsonRpcResponse actual = method.response(request);

@ -107,7 +107,7 @@ public class PrivGetFilterChangesTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Missing required json rpc parameter at index 1");
.hasMessageContaining("Invalid filter ID parameter (index 1)");
}
@Test

@ -84,7 +84,7 @@ public class PrivGetFilterLogsTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Missing required json rpc parameter at index 1");
.hasMessageContaining("Invalid filter ID parameter (index 1)");
}
@Test

@ -96,7 +96,7 @@ public class PrivGetLogsTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Missing required json rpc parameter at index 1");
.hasMessageContaining("Invalid filter parameter (index 1)");
}
@Test
@ -116,7 +116,7 @@ public class PrivGetLogsTest {
final JsonRpcRequestContext request = privGetLogRequest(PRIVACY_GROUP_ID, invalidFilter);
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(null, RpcErrorType.INVALID_FILTER_PARAMS);
final JsonRpcResponse response = method.response(request);

@ -87,7 +87,7 @@ public class PrivNewFilterTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Missing required json rpc parameter at index 1");
.hasMessageContaining("Invalid filter parameter (index 1)");
}
@Test
@ -107,7 +107,7 @@ public class PrivNewFilterTest {
final JsonRpcRequestContext request = privNewFilterRequest(PRIVACY_GROUP_ID, invalidFilter);
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(null, RpcErrorType.INVALID_FILTER_PARAMS);
final JsonRpcResponse response = method.response(request);

@ -70,7 +70,7 @@ public class PrivUninstallFilterTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Missing required json rpc parameter at index 1");
.hasMessageContaining("Invalid filter ID paramter (index 1)");
}
@Test

@ -290,7 +290,7 @@ public class SubscriptionRequestMapperTest {
.isInstanceOf(InvalidSubscriptionRequestException.class)
.getCause()
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid filter parameters (index 1)");
}
@Test
@ -303,7 +303,7 @@ public class SubscriptionRequestMapperTest {
.isInstanceOf(InvalidSubscriptionRequestException.class)
.getCause()
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid filter parameters (index 1)");
}
@Test

@ -16,7 +16,7 @@
"id" : 406,
"error" : {
"code": -32602,
"message": "Invalid params"
"message": "Invalid filter params"
}
},
"statusCode": 200

@ -12,7 +12,7 @@
"id": 406,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid filter params"
}
},
"statusCode": 200

Loading…
Cancel
Save