5098 branch 21 update more invalid params (#7467)

* 5098: Add RpcErrorTypes

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

* 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless

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

* 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless

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

* 5098: Add JsonRpcParameterException for later use

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

* 5098: Update locations for RpcErrorType.INVALID_ACCOUNTS_PARAMS

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

* 5098: Address review comments, apply spotless

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

* 5098: Update with changes from branch 1

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

* 5098: Update code to use RpcErrorType.INVALID_ADDRESS_HASH_PARAMS

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

* 5098: apply spotless

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

* 5098: apply spotless

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

* 5098: Update plugin-api gradle hash

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

* 5098: Add comment on INVALID_PARAMS_ERROR_CODE

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

* 5098: Apply spotless on latest changes

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

* 5098: Update code to use RpcErrorType.INVALID_ADDRESS_PARAMS

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

* 5098: Fix broken unit test

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

* 5098: Fix broken unit test

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

* 5098: Update with usage of RpcErrorType.INVALID_AUTH_PARAMS

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOB_COUNT

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_COUNT_PARAMS

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

* 5098: Fix broken integration test

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

* 5098: Add index to exception messages

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

* 5098: apoply spotless

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

* 5098: Update BaseJsonRpcProcessor to utilise RpcErrorType from InvalidJsonRpcParameters

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

* 5098: Include parameter index in INVALID_AUTH_PARAMS

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

* 5098: Include parameter index in INVALID_BLOCK_PARAMS

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

* 5098: Include parameter index in INVALID_BLOCK_COUNT_PARAMS

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

* 5098: Fix broken integration test

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

* 5098: Rename INVALID_AUTH_PARAMS to INVALID_PROPOSAL_PARAMS

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

* 5098: apply spotless

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

* 5098: Update INVALID_BLOCK_HASH_PARAMS locations

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

* 5098: Fix broken unit test

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

* 5098: apply spotless

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

* 5098: Update RpcErrorType.INVALID_BLOCK_INDEX

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

* 5098: Update RpcErrorType.INVALID_BLOCK_NUMBER

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

* 5098: apply spotless

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

* 5098: Fix broken tests

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

* 5098: Update RpcErrorType.INVALID_CALL_PARAMS

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

* 5098: Update RpcErrorType.INVALID_CONSOLIDATION_REQUEST_PARAMS

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

* 5098: Update RpcErrorType.INVALID_CREATE_PRIVACY_GROUP_PARAMS

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

* 5098: Fix broken test

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

* 5098: Update RpcErrorType.INVALID_DATA_PARAMS

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

* 5098: Update RpcErrorType.INVALID_DEPOSIT_REQUEST_PARAMS

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

* 5098: Update RpcErrorType.INVALID_ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_PARAMS

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

* 5098: Update RpcErrorType.INVALID_ENGINE_FORKCHOICE_UPDATED_PARAMS

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

* 5098: Update RpcErrorType.INVALID_ENGINE_PAYLOAD_ATTRIBUTES_PARAMS

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

* 5098: Update RpcErrorType.INVALID_ENGINE_PAYLOAD_PARAMS

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

* 5098: Update RpcErrorType.INVALID_ENGINE_PREPARE_PAYLOAD_PARAMS

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

* 5098: Apply spotless

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

* 5098: Update RpcErrorType.INVALID_ENODE_PARAMS

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

* 5098: Update RpcErrorType.INVALID_EXCESS_BLOB_GAS_PARAMS

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

* 5098: Apply spotless

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

* 5098: Update RpcErrorType.INVALID_EXTRA_DATA_PARAMS

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

* 5098: Update RpcErrorType.INVALID_FILTER_PARAMS

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

* 5098: Apply spotless

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

* 5098: Fix broken tests

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

* 5098: Update several RpcErrorTypes

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

* 5098: Apply spotless

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

* 5098: Hopefully fix broken integration test

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

* 5098: Hopefully fix broken integration test

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

* 5098: Update several more RpcErrorTypes

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

* 5098: Apply spotless

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

* 5098: Update RpcErrorType.INVALID_PARAM_COUNT

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

* 5098: Update RpcErrorType.INVALID_PAYLOAD_ID_PARAMS

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

* 5098: Update RpcErrorType.INVALID_PENDING_TRANSACTIONS_PARAMS

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

* 5098: Update RpcErrorType.INVAlID_PLUGIN_NAME_PARAMS

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

* 5098: Apply spotless

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

* 5098: Fix broken tests

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

* 5098: Update RpcErrorTypes

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

* 5098: Fix broken tests

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

* 5098: Apply spotless

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

* Update ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
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 2 months ago committed by GitHub
parent d7041d4221
commit 8523ed0e43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java
  2. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java
  3. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java
  4. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitHashRate.java
  5. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWork.java
  6. 15
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeCapabilities.java
  7. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java
  8. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java
  9. 12
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java
  10. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java
  11. 12
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java
  12. 12
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java
  13. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java
  14. 16
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java
  15. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java
  16. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java
  17. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java
  18. 75
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/request/SubscriptionRequestMapper.java
  19. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java
  20. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java
  21. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCallTest.java
  22. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRootTest.java
  23. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetFilterChangesTest.java
  24. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetFilterLogsTest.java
  25. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogsTest.java
  26. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilterTest.java
  27. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivUninstallFilterTest.java
  28. 6
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/request/SubscriptionRequestMapperTest.java
  29. 8
      ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumProtocol.java

@ -106,8 +106,15 @@ public class EthFeeHistory implements JsonRpcMethod {
"Invalid highest block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
final Optional<List<Double>> maybeRewardPercentiles =
request.getOptionalParameter(2, Double[].class).map(Arrays::asList);
final Optional<List<Double>> maybeRewardPercentiles;
try {
maybeRewardPercentiles = request.getOptionalParameter(2, Double[].class).map(Arrays::asList);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid reward percentiles parameter (index 2)",
RpcErrorType.INVALID_REWARD_PERCENTILES_PARAMS,
e);
}
final BlockHeader chainHeadHeader = blockchain.getChainHeadHeader();
final long chainHeadBlockNumber = chainHeadHeader.getNumber();

@ -106,8 +106,13 @@ public class EthGetProof extends AbstractBlockParameterOrBlockHashMethod {
}
private List<UInt256> getStorageKeys(final JsonRpcRequestContext request) {
return Arrays.stream(request.getRequiredParameter(1, String[].class))
.map(UInt256::fromHexString)
.collect(Collectors.toList());
try {
return Arrays.stream(request.getRequiredParameter(1, String[].class))
.map(UInt256::fromHexString)
.collect(Collectors.toList());
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid storage keys parameters (index 1)", RpcErrorType.INVALID_STORAGE_KEYS_PARAMS, e);
}
}
}

@ -56,7 +56,13 @@ public class EthGetStorageAt extends AbstractBlockParameterOrBlockHashMethod {
throw new InvalidJsonRpcParameters(
"Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
}
final UInt256 position = request.getRequiredParameter(1, UInt256Parameter.class).getValue();
final UInt256 position;
try {
position = request.getRequiredParameter(1, UInt256Parameter.class).getValue();
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid position parameter (index 1)", RpcErrorType.INVALID_POSITION_PARAMS, e);
}
return blockchainQueries
.get()
.storageAt(address, position, blockHash)

@ -42,11 +42,17 @@ public class EthSubmitHashRate implements JsonRpcMethod {
final String hashRate;
try {
hashRate = requestContext.getRequiredParameter(0, String.class);
} catch (Exception e) {
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid hash rate parameter (index 0)", RpcErrorType.INVALID_HASH_RATE_PARAMS, e);
}
final String id = requestContext.getRequiredParameter(1, String.class);
final String id;
try {
id = requestContext.getRequiredParameter(1, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid sealer ID parameter (index 1)", RpcErrorType.INVALID_SEALER_ID_PARAMS, e);
}
return new JsonRpcSuccessResponse(
requestContext.getRequest().getId(),
miningCoordinator.submitHashRate(

@ -65,7 +65,13 @@ public class EthSubmitWork implements JsonRpcMethod {
throw new InvalidJsonRpcParameters(
"Invalid mix hash parameter (index 2)", RpcErrorType.INVALID_MIX_HASH_PARAMS, e);
}
Bytes powHash = Bytes.fromHexString(requestContext.getRequiredParameter(1, String.class));
Bytes powHash;
try {
powHash = Bytes.fromHexString(requestContext.getRequiredParameter(1, String.class));
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid PoW hash parameter (index 1)", RpcErrorType.INVALID_POW_HASH_PARAMS, e);
}
final PoWSolution solution = new PoWSolution(nonce, mixHash, null, powHash);
final boolean result = miner.submitWork(solution);
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result);

@ -20,9 +20,11 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.ENGINE_PREPARE
import org.hyperledger.besu.ethereum.ProtocolContext;
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.ExecutionEngineJsonRpcMethod;
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 java.util.List;
import java.util.stream.Collectors;
@ -55,7 +57,18 @@ public class EngineExchangeCapabilities extends ExecutionEngineJsonRpcMethod {
LOG.atTrace()
.setMessage("received remote capabilities: {}")
.addArgument(() -> requestContext.getRequiredParameter(0, String[].class))
.addArgument(
() -> {
try {
return requestContext.getRequiredParameter(0, String[].class);
} catch (
Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid remote capabilities parameters (index 0)",
RpcErrorType.INVALID_REMOTE_CAPABILITIES_PARAMS,
e);
}
})
.log();
final List<String> localCapabilities =

@ -52,7 +52,15 @@ public class PrivGetFilterChanges implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final String privacyGroupId = requestContext.getRequiredParameter(0, String.class);
final String privacyGroupId;
try {
privacyGroupId = requestContext.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
final String filterId;
try {
filterId = requestContext.getRequiredParameter(1, String.class);

@ -52,7 +52,15 @@ public class PrivGetFilterLogs implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext request) {
final String privacyGroupId = request.getRequiredParameter(0, String.class);
final String privacyGroupId;
try {
privacyGroupId = request.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
final String filterId;
try {
filterId = request.getRequiredParameter(1, String.class);

@ -47,13 +47,21 @@ public class PrivUninstallFilter implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext request) {
final String privacyGroupId = request.getRequiredParameter(0, String.class);
final String privacyGroupId;
try {
privacyGroupId = request.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
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);
"Invalid filter ID parameter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e);
}
if (privacyController instanceof MultiTenancyPrivacyController) {

@ -65,7 +65,15 @@ public class PrivCall extends AbstractBlockParameterMethod {
protected Object resultByBlockNumber(
final JsonRpcRequestContext request, final long blockNumber) {
final JsonCallParameter callParams = validateAndGetCallParams(request);
final String privacyGroupId = request.getRequiredParameter(0, String.class);
final String privacyGroupId;
try {
privacyGroupId = request.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
final String privacyUserId = privacyIdProvider.getPrivacyUserId(request.getUser());

@ -72,7 +72,15 @@ public class PrivDebugGetStateRoot extends AbstractBlockParameterMethod {
@Override
protected Object resultByBlockNumber(
final JsonRpcRequestContext requestContext, final long blockNumber) {
final String privacyGroupId = requestContext.getRequiredParameter(0, String.class);
final String privacyGroupId;
try {
privacyGroupId = requestContext.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
final String privacyUserId = privacyIdProvider.getPrivacyUserId(requestContext.getUser());
if (LOG.isTraceEnabled()) {
LOG.trace("Executing {}", getName());
@ -97,7 +105,7 @@ public class PrivDebugGetStateRoot extends AbstractBlockParameterMethod {
}
} catch (final Exception e) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS);
}
if (privacyGroup.isEmpty()) {

@ -18,11 +18,13 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErr
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.privacy.methods.PrivacyIdProvider;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
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.MultiTenancyValidationException;
import org.hyperledger.besu.ethereum.privacy.PrivacyController;
@ -50,7 +52,15 @@ public class PrivDeletePrivacyGroup implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
LOG.trace("Executing {}", RpcMethod.PRIV_DELETE_PRIVACY_GROUP.getMethodName());
final String privacyGroupId = requestContext.getRequiredParameter(0, String.class);
final String privacyGroupId;
try {
privacyGroupId = requestContext.getRequiredParameter(0, String.class);
} catch (Exception e) {
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
final String response;
try {

@ -59,7 +59,15 @@ public class PrivGetCode extends AbstractBlockParameterMethod {
@Override
protected String resultByBlockNumber(
final JsonRpcRequestContext request, final long blockNumber) {
final String privacyGroupId = request.getRequiredParameter(0, String.class);
final String privacyGroupId;
try {
privacyGroupId = request.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
final Address address;
try {
address = request.getRequiredParameter(1, Address.class);

@ -73,8 +73,20 @@ public class PrivGetEeaTransactionCount implements JsonRpcMethod {
throw new InvalidJsonRpcParameters(
"Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
}
final String privateFrom = requestContext.getRequiredParameter(1, String.class);
final String[] privateFor = requestContext.getRequiredParameter(2, String[].class);
final String privateFrom;
try {
privateFrom = requestContext.getRequiredParameter(1, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid private from parameter (index 1)", RpcErrorType.INVALID_PRIVATE_FROM_PARAMS, e);
}
final String[] privateFor;
try {
privateFor = requestContext.getRequiredParameter(2, String[].class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid private for parameter (index 2)", RpcErrorType.INVALID_PRIVATE_FOR_PARAMS, e);
}
final String privacyUserId = privacyIdProvider.getPrivacyUserId(requestContext.getUser());

@ -62,7 +62,15 @@ public class PrivGetLogs implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final String privacyGroupId = requestContext.getRequiredParameter(0, String.class);
final String privacyGroupId;
try {
privacyGroupId = requestContext.getRequiredParameter(0, String.class);
} catch (Exception e) {
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
final FilterParameter filter;
try {
filter = requestContext.getRequiredParameter(1, FilterParameter.class);

@ -64,7 +64,15 @@ public class PrivGetTransactionCount implements JsonRpcMethod {
throw new InvalidJsonRpcParameters(
"Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
}
final String privacyGroupId = requestContext.getRequiredParameter(1, String.class);
final String privacyGroupId;
try {
privacyGroupId = requestContext.getRequiredParameter(1, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 1)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
try {
final long nonce =

@ -50,7 +50,15 @@ public class PrivNewFilter implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext request) {
final String privacyGroupId = request.getRequiredParameter(0, String.class);
final String privacyGroupId;
try { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
privacyGroupId = request.getRequiredParameter(0, String.class);
} catch (Exception e) {
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
final FilterParameter filter;
try {
filter = request.getRequiredParameter(1, FilterParameter.class);

@ -32,8 +32,15 @@ public class SubscriptionRequestMapper {
try {
final WebSocketRpcRequest webSocketRpcRequestBody = validateRequest(jsonRpcRequestContext);
final SubscriptionType subscriptionType =
webSocketRpcRequestBody.getRequiredParameter(0, SubscriptionType.class);
final SubscriptionType subscriptionType;
try {
subscriptionType = webSocketRpcRequestBody.getRequiredParameter(0, SubscriptionType.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid subscription type parameter (index 0)",
RpcErrorType.INVALID_SUBSCRIPTION_PARAMS,
e);
}
switch (subscriptionType) {
case NEW_BLOCK_HEADERS:
{
@ -60,8 +67,13 @@ public class SubscriptionRequestMapper {
}
private boolean includeTransactions(final WebSocketRpcRequest webSocketRpcRequestBody) {
final Optional<SubscriptionParam> params =
webSocketRpcRequestBody.getOptionalParameter(1, SubscriptionParam.class);
final Optional<SubscriptionParam> params;
try {
params = webSocketRpcRequestBody.getOptionalParameter(1, SubscriptionParam.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid subscription parameter (index 1)", RpcErrorType.INVALID_SUBSCRIPTION_PARAMS, e);
}
return params.isPresent() && params.get().includeTransaction();
}
@ -88,8 +100,16 @@ public class SubscriptionRequestMapper {
try {
final WebSocketRpcRequest webSocketRpcRequestBody = validateRequest(jsonRpcRequestContext);
final long subscriptionId =
webSocketRpcRequestBody.getRequiredParameter(0, UnsignedLongParameter.class).getValue();
final long subscriptionId;
try {
subscriptionId =
webSocketRpcRequestBody.getRequiredParameter(0, UnsignedLongParameter.class).getValue();
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid subscription ID parameter (index 0)",
RpcErrorType.INVALID_SUBSCRIPTION_PARAMS,
e);
}
return new UnsubscribeRequest(subscriptionId, webSocketRpcRequestBody.getConnectionId());
} catch (final Exception e) {
throw new InvalidSubscriptionRequestException("Error parsing unsubscribe request", e);
@ -102,9 +122,24 @@ public class SubscriptionRequestMapper {
try {
final WebSocketRpcRequest webSocketRpcRequestBody = validateRequest(jsonRpcRequestContext);
final String privacyGroupId = webSocketRpcRequestBody.getRequiredParameter(0, String.class);
final SubscriptionType subscriptionType =
webSocketRpcRequestBody.getRequiredParameter(1, SubscriptionType.class);
final String privacyGroupId;
try {
privacyGroupId = webSocketRpcRequestBody.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
final SubscriptionType subscriptionType;
try {
subscriptionType = webSocketRpcRequestBody.getRequiredParameter(1, SubscriptionType.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid subscription type parameter (index 1)",
RpcErrorType.INVALID_SUBSCRIPTION_PARAMS,
e);
}
switch (subscriptionType) {
case LOGS:
@ -142,9 +177,25 @@ public class SubscriptionRequestMapper {
try {
final WebSocketRpcRequest webSocketRpcRequestBody = validateRequest(jsonRpcRequestContext);
final String privacyGroupId = webSocketRpcRequestBody.getRequiredParameter(0, String.class);
final long subscriptionId =
webSocketRpcRequestBody.getRequiredParameter(1, UnsignedLongParameter.class).getValue();
final String privacyGroupId;
try {
privacyGroupId = webSocketRpcRequestBody.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid privacy group ID parameter (index 0)",
RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS,
e);
}
final long subscriptionId;
try {
subscriptionId =
webSocketRpcRequestBody.getRequiredParameter(1, UnsignedLongParameter.class).getValue();
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid subscription ID parameter (index 1)",
RpcErrorType.INVALID_SUBSCRIPTION_PARAMS,
e);
}
return new PrivateUnsubscribeRequest(
subscriptionId, webSocketRpcRequestBody.getConnectionId(), privacyGroupId);
} catch (final Exception e) {

@ -2033,7 +2033,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final JsonObject json = new JsonObject(resp.body().string());
final RpcErrorType expectedError = RpcErrorType.INVALID_PARAMS;
final RpcErrorType expectedError = RpcErrorType.INVALID_POSITION_PARAMS;
testHelper.assertValidJsonRpcError(
json, id, expectedError.getCode(), expectedError.getMessage());
}

@ -120,7 +120,7 @@ class EthGetProofTest {
Assertions.assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Missing required json rpc parameter at index 1");
.hasMessageContaining("Invalid storage keys parameters (index 1)");
}
@Test

@ -173,8 +173,7 @@ public class PrivCallTest {
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasNoCause()
.hasMessage("Missing required json rpc parameter at index 0");
.hasMessage("Invalid privacy group ID parameter (index 0)");
}
private JsonCallParameter callParameter() {

@ -82,8 +82,7 @@ public class PrivDebugGetStateRootTest {
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasNoCause()
.hasMessage("Missing required json rpc parameter at index 0");
.hasMessage("Invalid privacy group ID parameter (index 0)");
}
@Test

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

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

@ -87,7 +87,7 @@ public class PrivGetLogsTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Missing required json rpc parameter at index 0");
.hasMessageContaining("Invalid privacy group ID parameter (index 0)");
}
@Test

@ -78,7 +78,7 @@ public class PrivNewFilterTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Missing required json rpc parameter at index 0");
.hasMessageContaining("Invalid privacy group ID parameter (index 0)");
}
@Test

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

@ -83,7 +83,7 @@ public class SubscriptionRequestMapperTest {
.isInstanceOf(InvalidSubscriptionRequestException.class)
.getCause()
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Missing required json rpc parameter at index 0");
.hasMessage("Invalid subscription type parameter (index 0)");
}
@Test
@ -138,7 +138,7 @@ public class SubscriptionRequestMapperTest {
.isInstanceOf(InvalidSubscriptionRequestException.class)
.getCause()
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid subscription parameter (index 1)");
}
@Test
@ -372,7 +372,7 @@ public class SubscriptionRequestMapperTest {
.isInstanceOf(InvalidSubscriptionRequestException.class)
.getCause()
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid subscription type parameter (index 0)");
}
@Test

@ -87,7 +87,13 @@ public interface StratumProtocol {
throw new InvalidJsonRpcParameters(
"Invalid hash rate parameter (index 0)", RpcErrorType.INVALID_HASH_RATE_PARAMS, e);
}
final String id = message.getRequiredParameter(1, String.class);
final String id;
try {
id = message.getRequiredParameter(1, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid sealer ID parameter (index 1)", RpcErrorType.INVALID_SEALER_ID_PARAMS, e);
}
String response;
try {
response =

Loading…
Cancel
Save