From 018225252397f059ee317c18bb07cb76e04f50c1 Mon Sep 17 00:00:00 2001 From: Matilda-Clerke Date: Tue, 20 Aug 2024 14:54:00 +1000 Subject: [PATCH] 5098 branch 24 throw checked exception to remove todos (#7481) * 5098: Add RpcErrorTypes Signed-off-by: Matilda Clerke --------- Signed-off-by: Matilda Clerke Signed-off-by: Matilda-Clerke Co-authored-by: Sally MacFarlane --- .../jsonrpc/methods/CliqueGetSigners.java | 3 ++- .../methods/CliqueGetSignersAtHash.java | 3 ++- .../clique/jsonrpc/methods/Discard.java | 3 ++- .../clique/jsonrpc/methods/Propose.java | 5 ++-- .../AbstractGetSignerMetricsMethod.java | 5 ++-- .../methods/IbftDiscardValidatorVote.java | 3 ++- .../methods/IbftGetValidatorsByBlockHash.java | 3 ++- .../IbftGetValidatorsByBlockNumber.java | 3 ++- .../methods/IbftProposeValidatorVote.java | 5 ++-- .../methods/QbftDiscardValidatorVote.java | 3 ++- .../methods/QbftGetValidatorsByBlockHash.java | 3 ++- .../QbftGetValidatorsByBlockNumber.java | 3 ++- .../methods/QbftProposeValidatorVote.java | 5 ++-- .../jsonrpc/internal/DebugReplayBlock.java | 3 ++- .../api/jsonrpc/internal/JsonRpcRequest.java | 10 ++++--- .../internal/JsonRpcRequestContext.java | 11 +++++--- .../methods/AbstractTraceByBlock.java | 3 ++- .../internal/methods/AdminChangeLogLevel.java | 5 ++-- .../methods/AdminGenerateLogBloomCache.java | 5 ++-- .../methods/AdminLogsRemoveCache.java | 5 ++-- .../methods/AdminLogsRepairCache.java | 3 ++- .../internal/methods/AdminModifyPeer.java | 3 ++- .../internal/methods/DebugAccountAt.java | 7 ++--- .../internal/methods/DebugAccountRange.java | 7 ++--- .../methods/DebugBatchSendRawTransaction.java | 13 +++++++-- .../internal/methods/DebugGetRawBlock.java | 3 ++- .../internal/methods/DebugGetRawHeader.java | 3 ++- .../internal/methods/DebugGetRawReceipts.java | 3 ++- .../methods/DebugGetRawTransaction.java | 3 ++- .../internal/methods/DebugSetHead.java | 3 ++- .../DebugStandardTraceBadBlockToFile.java | 5 ++-- .../DebugStandardTraceBlockToFile.java | 5 ++-- .../internal/methods/DebugStorageRangeAt.java | 11 ++++---- .../internal/methods/DebugTraceBlock.java | 7 ++--- .../methods/DebugTraceBlockByHash.java | 5 ++-- .../methods/DebugTraceBlockByNumber.java | 5 ++-- .../internal/methods/DebugTraceCall.java | 5 ++-- .../methods/DebugTraceTransaction.java | 5 ++-- .../api/jsonrpc/internal/methods/EthCall.java | 3 ++- .../internal/methods/EthFeeHistory.java | 7 ++--- .../internal/methods/EthGetBalance.java | 5 ++-- .../internal/methods/EthGetBlockByHash.java | 5 ++-- .../internal/methods/EthGetBlockByNumber.java | 5 ++-- .../internal/methods/EthGetBlockReceipts.java | 3 ++- .../EthGetBlockTransactionCountByHash.java | 3 ++- .../EthGetBlockTransactionCountByNumber.java | 3 ++- .../jsonrpc/internal/methods/EthGetCode.java | 5 ++-- .../internal/methods/EthGetFilterChanges.java | 3 ++- .../internal/methods/EthGetFilterLogs.java | 3 ++- .../jsonrpc/internal/methods/EthGetLogs.java | 3 ++- .../methods/EthGetMinerDataByBlockHash.java | 3 ++- .../methods/EthGetMinerDataByBlockNumber.java | 3 ++- .../jsonrpc/internal/methods/EthGetProof.java | 7 ++--- .../internal/methods/EthGetStorageAt.java | 7 ++--- .../EthGetTransactionByBlockHashAndIndex.java | 5 ++-- ...thGetTransactionByBlockNumberAndIndex.java | 5 ++-- .../methods/EthGetTransactionByHash.java | 3 ++- .../methods/EthGetTransactionCount.java | 7 ++--- .../methods/EthGetTransactionReceipt.java | 3 ++- .../EthGetUncleByBlockHashAndIndex.java | 5 ++-- .../EthGetUncleByBlockNumberAndIndex.java | 5 ++-- .../methods/EthGetUncleCountByBlockHash.java | 3 ++- .../EthGetUncleCountByBlockNumber.java | 10 ++++++- .../internal/methods/EthNewFilter.java | 3 ++- .../methods/EthSendRawTransaction.java | 3 ++- .../internal/methods/EthSubmitHashRate.java | 5 ++-- .../internal/methods/EthSubmitWork.java | 7 ++--- .../internal/methods/EthUninstallFilter.java | 3 ++- .../methods/JsonCallParameterUtil.java | 3 ++- .../methods/PluginsReloadConfiguration.java | 3 ++- .../jsonrpc/internal/methods/TraceBlock.java | 3 ++- .../jsonrpc/internal/methods/TraceCall.java | 3 ++- .../internal/methods/TraceCallMany.java | 3 ++- .../jsonrpc/internal/methods/TraceFilter.java | 3 ++- .../jsonrpc/internal/methods/TraceGet.java | 5 ++-- .../internal/methods/TraceRawTransaction.java | 5 ++-- .../methods/TraceReplayBlockTransactions.java | 5 ++-- .../internal/methods/TraceTransaction.java | 3 ++- .../TxPoolBesuPendingTransactions.java | 5 ++-- .../jsonrpc/internal/methods/Web3Sha3.java | 3 ++- .../AbstractEngineForkchoiceUpdated.java | 5 ++-- .../engine/AbstractEngineGetPayload.java | 3 ++- .../engine/AbstractEngineNewPayload.java | 7 ++--- .../engine/EngineExchangeCapabilities.java | 4 +-- ...EngineExchangeTransitionConfiguration.java | 3 ++- .../EngineGetPayloadBodiesByHashV1.java | 3 ++- .../EngineGetPayloadBodiesByRangeV1.java | 5 ++-- .../engine/EnginePreparePayloadDebug.java | 3 ++- .../miner/MinerChangeTargetGasLimit.java | 3 ++- .../methods/miner/MinerSetCoinbase.java | 3 ++- .../methods/miner/MinerSetExtraData.java | 7 +++-- .../methods/miner/MinerSetMinGasPrice.java | 3 ++- .../methods/miner/MinerSetMinPriorityFee.java | 6 ++--- .../PermAddAccountsToAllowlist.java | 3 ++- .../PermAddNodesToAllowlist.java | 3 ++- .../PermRemoveAccountsFromAllowlist.java | 3 ++- .../PermRemoveNodesFromAllowlist.java | 3 ++- .../internal/parameters/JsonRpcParameter.java | 27 +++++++------------ .../privacy/methods/PrivGetFilterChanges.java | 5 ++-- .../privacy/methods/PrivGetFilterLogs.java | 5 ++-- .../privacy/methods/PrivUninstallFilter.java | 5 ++-- .../eea/AbstractEeaSendRawTransaction.java | 3 ++- .../privacy/methods/priv/PrivCall.java | 7 ++--- .../methods/priv/PrivCreatePrivacyGroup.java | 3 ++- .../methods/priv/PrivDebugGetStateRoot.java | 5 ++-- .../methods/priv/PrivDeletePrivacyGroup.java | 3 ++- .../priv/PrivDistributeRawTransaction.java | 3 ++- .../methods/priv/PrivFindPrivacyGroup.java | 3 ++- .../privacy/methods/priv/PrivGetCode.java | 7 ++--- .../priv/PrivGetEeaTransactionCount.java | 7 ++--- .../privacy/methods/priv/PrivGetLogs.java | 3 ++- .../priv/PrivGetPrivateTransaction.java | 3 ++- .../methods/priv/PrivGetTransactionCount.java | 5 ++-- .../priv/PrivGetTransactionReceipt.java | 3 ++- .../privacy/methods/priv/PrivNewFilter.java | 7 ++--- .../methods/priv/PrivTraceTransaction.java | 22 +++++++++++++-- .../privx/PrivxFindFlexiblePrivacyGroup.java | 3 ++- .../request/SubscriptionRequestMapper.java | 19 ++++++------- .../TxPoolBesuPendingTransactionsTest.java | 8 +++--- .../engine/EnginePreparePayloadDebugTest.java | 5 ++-- .../retesteth/methods/TestGetLogHash.java | 3 ++- .../retesteth/methods/TestImportRawBlock.java | 3 ++- .../retesteth/methods/TestMineBlocks.java | 3 ++- .../methods/TestModifyTimestamp.java | 3 ++- .../retesteth/methods/TestRewindToBlock.java | 3 ++- .../ethereum/stratum/Stratum1Protocol.java | 15 ++++++++--- .../ethereum/stratum/StratumProtocol.java | 5 ++-- 127 files changed, 393 insertions(+), 234 deletions(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java index 813c296098..057fb30ee5 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java @@ -20,6 +20,7 @@ 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.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -71,7 +72,7 @@ public class CliqueGetSigners implements JsonRpcMethod { final Optional blockParameter; try { blockParameter = request.getOptionalParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java index c683b9d485..908ff9f412 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java @@ -20,6 +20,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -71,7 +72,7 @@ public class CliqueGetSignersAtHash implements JsonRpcMethod { final Hash hash; try { hash = request.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java index 467164e8c0..da3214b1ef 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java @@ -22,6 +22,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -51,7 +52,7 @@ public class Discard implements JsonRpcMethod { final Address address; try { address = requestContext.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java index 6e198a84fe..26ab19c988 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java @@ -23,6 +23,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -53,14 +54,14 @@ public class Propose implements JsonRpcMethod { final Address address; try { address = requestContext.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final Boolean auth; try { auth = requestContext.getRequiredParameter(1, Boolean.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid auth parameter (index 1)", RpcErrorType.INVALID_PROPOSAL_PARAMS, e); } diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java index 7ef368fb76..e3785976af 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.datatypes.Address; 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -70,14 +71,14 @@ public abstract class AbstractGetSignerMetricsMethod { final Optional startBlockParameter; try { startBlockParameter = requestContext.getOptionalParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } final Optional endBlockParameter; try { endBlockParameter = requestContext.getOptionalParameter(1, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid end block parameter (index 1)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java index 7e6c001088..8953468937 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java @@ -22,6 +22,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -55,7 +56,7 @@ public class IbftDiscardValidatorVote implements JsonRpcMethod { final Address validatorAddress; try { validatorAddress = requestContext.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid validator address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java index 3c3346cd43..dfefe22c53 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java @@ -20,6 +20,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -66,7 +67,7 @@ public class IbftGetValidatorsByBlockHash implements JsonRpcMethod { final Hash hash; try { hash = request.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java index 7992f0918c..a878ebc66e 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonR import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -54,7 +55,7 @@ public class IbftGetValidatorsByBlockNumber extends AbstractBlockParameterMethod protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java index 9364422c57..f010633e63 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java @@ -23,6 +23,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -56,14 +57,14 @@ public class IbftProposeValidatorVote implements JsonRpcMethod { final Address validatorAddress; try { validatorAddress = requestContext.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final Boolean add; try { add = requestContext.getRequiredParameter(1, Boolean.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid vote type parameter (index 1)", RpcErrorType.INVALID_VOTE_TYPE_PARAMS, e); } diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java index 98856caaa6..66e9cf6014 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java @@ -20,6 +20,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -53,7 +54,7 @@ public class QbftDiscardValidatorVote implements JsonRpcMethod { final Address validatorAddress; try { validatorAddress = requestContext.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid validator address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java index e991f7f355..75000bde5d 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java @@ -21,6 +21,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -67,7 +68,7 @@ public class QbftGetValidatorsByBlockHash implements JsonRpcMethod { final Hash hash; try { hash = request.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java index 7a64a7ab22..b33490f0c2 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonR import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -54,7 +55,7 @@ public class QbftGetValidatorsByBlockNumber extends AbstractBlockParameterMethod protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java index aa3a8b267e..e6ad3ff6a8 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java @@ -21,6 +21,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -54,7 +55,7 @@ public class QbftProposeValidatorVote implements JsonRpcMethod { final Address validatorAddress; try { validatorAddress = requestContext.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid validator address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, @@ -63,7 +64,7 @@ public class QbftProposeValidatorVote implements JsonRpcMethod { final Boolean add; try { add = requestContext.getRequiredParameter(1, Boolean.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid vote type parameter (index 1)", RpcErrorType.INVALID_VOTE_TYPE_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java index 6dbf9f586f..ab53e415dd 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -60,7 +61,7 @@ public class DebugReplayBlock extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/JsonRpcRequest.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/JsonRpcRequest.java index 06b495624e..a7c1e15e01 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/JsonRpcRequest.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/JsonRpcRequest.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcRequestException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import java.util.Arrays; @@ -132,15 +133,18 @@ public class JsonRpcRequest { return Objects.hash(id, method, Arrays.hashCode(params), version, isNotification); } - public T getRequiredParameter(final int index, final Class paramClass) { + public T getRequiredParameter(final int index, final Class paramClass) + throws JsonRpcParameterException { return parameterAccessor.required(params, index, paramClass); } - public Optional getOptionalParameter(final int index, final Class paramClass) { + public Optional getOptionalParameter(final int index, final Class paramClass) + throws JsonRpcParameterException { return parameterAccessor.optional(params, index, paramClass); } - public Optional> getOptionalList(final int index, final Class paramClass) { + public Optional> getOptionalList(final int index, final Class paramClass) + throws JsonRpcParameterException { return parameterAccessor.optionalList(params, index, paramClass); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/JsonRpcRequestContext.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/JsonRpcRequestContext.java index b489259eb8..cc96384005 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/JsonRpcRequestContext.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/JsonRpcRequestContext.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; + import java.util.List; import java.util.Objects; import java.util.Optional; @@ -61,15 +63,18 @@ public class JsonRpcRequestContext { return user; } - public T getRequiredParameter(final int index, final Class paramClass) { + public T getRequiredParameter(final int index, final Class paramClass) + throws JsonRpcParameterException { return jsonRpcRequest.getRequiredParameter(index, paramClass); } - public Optional getOptionalParameter(final int index, final Class paramClass) { + public Optional getOptionalParameter(final int index, final Class paramClass) + throws JsonRpcParameterException { return jsonRpcRequest.getOptionalParameter(index, paramClass); } - public Optional> getOptionalList(final int index, final Class listOf) { + public Optional> getOptionalList(final int index, final Class listOf) + throws JsonRpcParameterException { return jsonRpcRequest.getOptionalList(index, listOf); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java index a596521175..36991796b5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.Trac 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -67,7 +68,7 @@ public abstract class AbstractTraceByBlock extends AbstractBlockParameterMethod final Optional maybeBlockParameter; try { maybeBlockParameter = request.getOptionalParameter(2, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminChangeLogLevel.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminChangeLogLevel.java index 3cfd524c14..6081f8f340 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminChangeLogLevel.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminChangeLogLevel.java @@ -17,6 +17,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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -47,7 +48,7 @@ public class AdminChangeLogLevel implements JsonRpcMethod { final String logLevel; try { logLevel = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid log level parameter (index 0)", RpcErrorType.INVALID_LOG_LEVEL_PARAMS, e); } @@ -58,7 +59,7 @@ public class AdminChangeLogLevel implements JsonRpcMethod { final Optional optionalLogFilters; try { optionalLogFilters = requestContext.getOptionalParameter(1, String[].class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid log filter parameters (index 1)", RpcErrorType.INVALID_LOG_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java index 437f7f5821..cad60660c3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -43,7 +44,7 @@ public class AdminGenerateLogBloomCache implements JsonRpcMethod { final Optional startBlockParam; try { startBlockParam = requestContext.getOptionalParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -60,7 +61,7 @@ public class AdminGenerateLogBloomCache implements JsonRpcMethod { final Optional stopBlockParam; try { stopBlockParam = requestContext.getOptionalParameter(1, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid stop block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java index 94430c526f..c7b67b2827 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -46,14 +47,14 @@ public class AdminLogsRemoveCache implements JsonRpcMethod { final Optional startBlockParameter; try { startBlockParameter = requestContext.getOptionalParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } final Optional stopBlockParameter; try { stopBlockParameter = requestContext.getOptionalParameter(1, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid stop block parameter (index 1)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java index 7336faff0e..650a9f74eb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java @@ -17,6 +17,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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -43,7 +44,7 @@ public class AdminLogsRepairCache implements JsonRpcMethod { final Optional blockNumber; try { blockNumber = requestContext.getOptionalParameter(0, Long.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminModifyPeer.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminModifyPeer.java index f1c134ed91..5b70668c32 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminModifyPeer.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminModifyPeer.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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.RpcErrorType; @@ -65,7 +66,7 @@ public abstract class AdminModifyPeer implements JsonRpcMethod { } catch (final P2PDisabledException e) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.P2P_DISABLED); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.INVALID_ENODE_PARAMS); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java index 602f3de3e0..318d8a0b8d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java @@ -20,6 +20,7 @@ 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.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; @@ -69,7 +70,7 @@ public class DebugAccountAt extends AbstractBlockParameterOrBlockHashMethod { final JsonRpcRequestContext requestContext) { try { return requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -81,7 +82,7 @@ public class DebugAccountAt extends AbstractBlockParameterOrBlockHashMethod { final Integer txIndex; try { txIndex = requestContext.getRequiredParameter(1, Integer.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction index parameter (index 1)", RpcErrorType.INVALID_TRANSACTION_INDEX_PARAMS, @@ -90,7 +91,7 @@ public class DebugAccountAt extends AbstractBlockParameterOrBlockHashMethod { final Address address; try { address = requestContext.getRequiredParameter(2, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 2)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java index fc787031da..852972f4d8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.datatypes.Hash; 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.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -62,7 +63,7 @@ public class DebugAccountRange implements JsonRpcMethod { try { blockParameterOrBlockHash = requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, @@ -71,14 +72,14 @@ public class DebugAccountRange implements JsonRpcMethod { final String addressHash; try { addressHash = requestContext.getRequiredParameter(2, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address hash parameter (index 2)", RpcErrorType.INVALID_ADDRESS_HASH_PARAMS, e); } final int maxResults; try { maxResults = requestContext.getRequiredParameter(3, Integer.TYPE); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid max results parameter (index 3)", RpcErrorType.INVALID_MAX_RESULTS_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransaction.java index 83553dc874..d78f9fb6be 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransaction.java @@ -16,8 +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.parameters.JsonRpcParameter.JsonRpcParameterException; 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.api.util.DomainObjectDecodeUtils; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; @@ -56,9 +59,15 @@ public class DebugBatchSendRawTransaction implements JsonRpcMethod { final List executionStatuses = new ArrayList<>(); IntStream.range(0, requestContext.getRequest().getParamLength()) .forEach( - i -> + i -> { + try { executionStatuses.add( - process(i, requestContext.getRequiredParameter(i, String.class)))); + process(i, requestContext.getRequiredParameter(i, String.class))); + } catch (JsonRpcParameterException e) { + throw new InvalidJsonRpcParameters( + "Invalid parameter (index " + i + ")", RpcErrorType.INVALID_PARAMS, e); + } + }); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), executionStatuses); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java index 28d886bd81..c9097583e3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -40,7 +41,7 @@ public class DebugGetRawBlock extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java index e2f2c89e1a..8e4f9ce6ea 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -40,7 +41,7 @@ public class DebugGetRawHeader extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java index cddba5086e..1c634c3c73 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java @@ -19,6 +19,7 @@ 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.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -44,7 +45,7 @@ public class DebugGetRawReceipts extends AbstractBlockParameterOrBlockHashMethod final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawTransaction.java index d6ede25b27..2b1e756d22 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawTransaction.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -43,7 +44,7 @@ public class DebugGetRawTransaction implements JsonRpcMethod { final Hash txHash; try { txHash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction hash parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java index a3b423675f..7958f8e759 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java @@ -22,6 +22,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -47,7 +48,7 @@ public class DebugSetHead extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java index 2d0c4cac4e..b49c94fd6a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java @@ -19,6 +19,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -56,14 +57,14 @@ public class DebugStandardTraceBadBlockToFile extends DebugStandardTraceBlockToF final Hash blockHash; try { blockHash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } final Optional transactionTraceParams; try { transactionTraceParams = requestContext.getOptionalParameter(1, TransactionTraceParams.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction trace parameters (index 1)", RpcErrorType.INVALID_TRANSACTION_TRACE_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java index 5fba2911bd..b3bb32370e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java @@ -20,6 +20,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer; @@ -63,14 +64,14 @@ public class DebugStandardTraceBlockToFile implements JsonRpcMethod { final Hash blockHash; try { blockHash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } final Optional transactionTraceParams; try { transactionTraceParams = requestContext.getOptionalParameter(1, TransactionTraceParams.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction trace parameters (index 1)", RpcErrorType.INVALID_TRANSACTION_TRACE_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java index 5aabff4b57..1fde6610ef 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java @@ -20,6 +20,7 @@ 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.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer.TraceableState; @@ -73,14 +74,14 @@ public class DebugStorageRangeAt implements JsonRpcMethod { try { blockParameterOrBlockHash = requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final int transactionIndex; try { transactionIndex = requestContext.getRequiredParameter(1, Integer.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction index parameter (index 1)", RpcErrorType.INVALID_TRANSACTION_INDEX_PARAMS, @@ -89,21 +90,21 @@ public class DebugStorageRangeAt implements JsonRpcMethod { final Address accountAddress; try { accountAddress = requestContext.getRequiredParameter(2, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid account address parameter (index 2)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final Hash startKey; try { startKey = Hash.fromHexStringLenient(requestContext.getRequiredParameter(3, String.class)); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid data start hash parameter (index 3)", RpcErrorType.INVALID_DATA_HASH_PARAMS, e); } final int limit; try { limit = requestContext.getRequiredParameter(4, Integer.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid limit parameter (index 4)", RpcErrorType.INVALID_TRANSACTION_LIMIT_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java index 2d668c7f22..edfb816bb9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java @@ -17,6 +17,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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; @@ -65,15 +66,15 @@ public class DebugTraceBlock implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final String input = requestContext.getRequiredParameter(0, String.class); final Block block; try { + final String input = requestContext.getRequiredParameter(0, String.class); block = Block.readFrom(RLP.input(Bytes.fromHexString(input)), this.blockHeaderFunctions); } catch (final RLPException e) { LOG.debug("Failed to parse block RLP (index 0)", e); return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_PARAMS); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block params (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -84,7 +85,7 @@ public class DebugTraceBlock implements JsonRpcMethod { .getOptionalParameter(1, TransactionTraceParams.class) .map(TransactionTraceParams::traceOptions) .orElse(TraceOptions.DEFAULT); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction trace parameter (index 1)", RpcErrorType.INVALID_TRANSACTION_TRACE_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java index 4c1d3bfc2a..d98e8abd8d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; @@ -55,7 +56,7 @@ public class DebugTraceBlockByHash implements JsonRpcMethod { final Hash blockHash; try { blockHash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } @@ -66,7 +67,7 @@ public class DebugTraceBlockByHash implements JsonRpcMethod { .getOptionalParameter(1, TransactionTraceParams.class) .map(TransactionTraceParams::traceOptions) .orElse(TraceOptions.DEFAULT); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction trace parameter (index 1)", RpcErrorType.INVALID_TRANSACTION_TRACE_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java index eb90edabb9..99c96c99be 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java @@ -19,6 +19,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; @@ -51,7 +52,7 @@ public class DebugTraceBlockByNumber extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -68,7 +69,7 @@ public class DebugTraceBlockByNumber extends AbstractBlockParameterMethod { .getOptionalParameter(1, TransactionTraceParams.class) .map(TransactionTraceParams::traceOptions) .orElse(TraceOptions.DEFAULT); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction trace parameter (index 1)", RpcErrorType.INVALID_TRANSACTION_TRACE_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java index d309f8dfdd..e808e79ddc 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java @@ -20,6 +20,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; @@ -60,7 +61,7 @@ public class DebugTraceCall extends AbstractTraceCall { .getOptionalParameter(2, TransactionTraceParams.class) .map(TransactionTraceParams::traceOptions) .orElse(TraceOptions.DEFAULT); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction trace parameter (index 2)", RpcErrorType.INVALID_TRANSACTION_TRACE_PARAMS, @@ -73,7 +74,7 @@ public class DebugTraceCall extends AbstractTraceCall { final Optional maybeBlockParameter; try { maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceTransaction.java index 8ec14dc4ad..1e85e6530a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceTransaction.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer; @@ -53,7 +54,7 @@ public class DebugTraceTransaction implements JsonRpcMethod { final Hash hash; try { hash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction hash parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, @@ -69,7 +70,7 @@ public class DebugTraceTransaction implements JsonRpcMethod { .getOptionalParameter(1, TransactionTraceParams.class) .map(TransactionTraceParams::traceOptions) .orElse(TraceOptions.DEFAULT); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction trace parameter (index 1)", RpcErrorType.INVALID_TRANSACTION_TRACE_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java index a08b17dfc6..0e0318f9c2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java @@ -25,6 +25,7 @@ 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.BlockParameterOrBlockHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -60,7 +61,7 @@ public class EthCall extends AbstractBlockParameterOrBlockHashMethod { final JsonRpcRequestContext request) { try { return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block or block hash parameters (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java index 01a0802279..b95746dad9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java @@ -24,6 +24,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -91,7 +92,7 @@ public class EthFeeHistory implements JsonRpcMethod { final int blockCount; try { blockCount = request.getRequiredParameter(0, UnsignedIntParameter.class).getValue(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block count parameter (index 0)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); } @@ -101,7 +102,7 @@ public class EthFeeHistory implements JsonRpcMethod { final BlockParameter highestBlock; try { highestBlock = request.getRequiredParameter(1, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid highest block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -109,7 +110,7 @@ public class EthFeeHistory implements JsonRpcMethod { final Optional> maybeRewardPercentiles; try { maybeRewardPercentiles = request.getOptionalParameter(2, Double[].class).map(Arrays::asList); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid reward percentiles parameter (index 2)", RpcErrorType.INVALID_REWARD_PERCENTILES_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java index e863626c96..cb1d879a05 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java @@ -20,6 +20,7 @@ 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.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -45,7 +46,7 @@ public class EthGetBalance extends AbstractBlockParameterOrBlockHashMethod { final JsonRpcRequestContext request) { try { return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block or block hash parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -56,7 +57,7 @@ public class EthGetBalance extends AbstractBlockParameterOrBlockHashMethod { final Address address; try { address = request.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java index 875daea7f1..f5b633253a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -64,7 +65,7 @@ public class EthGetBlockByHash implements JsonRpcMethod { final Hash hash; try { hash = request.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } @@ -95,7 +96,7 @@ public class EthGetBlockByHash implements JsonRpcMethod { private boolean isCompleteTransactions(final JsonRpcRequestContext requestContext) { try { return requestContext.getRequiredParameter(1, Boolean.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid return complete transaction parameter (index 1)", RpcErrorType.INVALID_RETURN_COMPLETE_TRANSACTION_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java index 8e0954144d..0a26a24ee3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java @@ -19,6 +19,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; @@ -66,7 +67,7 @@ public class EthGetBlockByNumber extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -126,7 +127,7 @@ public class EthGetBlockByNumber extends AbstractBlockParameterMethod { private boolean isCompleteTransactions(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(1, Boolean.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid return complete transaction parameter (index 1)", RpcErrorType.INVALID_RETURN_COMPLETE_TRANSACTION_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java index d9592db8c1..a113e4ee8e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java @@ -19,6 +19,7 @@ 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.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockReceiptsResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionReceiptResult; @@ -57,7 +58,7 @@ public class EthGetBlockReceipts extends AbstractBlockParameterOrBlockHashMethod final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block or block hash parameters (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java index e1fbd79086..fc7c3cc70c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -42,7 +43,7 @@ public class EthGetBlockTransactionCountByHash implements JsonRpcMethod { final Hash hash; try { hash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block header hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java index 2a068a6174..95bd7cc507 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -37,7 +38,7 @@ public class EthGetBlockTransactionCountByNumber extends AbstractBlockParameterM protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameters (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java index 8a9881a012..0c9194b0b3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java @@ -20,6 +20,7 @@ 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.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -47,7 +48,7 @@ public class EthGetCode extends AbstractBlockParameterOrBlockHashMethod { final JsonRpcRequestContext request) { try { return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block or block hash parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -58,7 +59,7 @@ public class EthGetCode extends AbstractBlockParameterOrBlockHashMethod { final Address address; try { address = request.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterChanges.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterChanges.java index 0773651b61..b3fa7565d6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterChanges.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterChanges.java @@ -19,6 +19,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -47,7 +48,7 @@ public class EthGetFilterChanges implements JsonRpcMethod { final String filterId; try { filterId = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter ID parameter (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterLogs.java index b66b7963e1..0fd32455b2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetFilterLogs.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -45,7 +46,7 @@ public class EthGetFilterLogs implements JsonRpcMethod { final String filterId; try { filterId = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter ID parameter (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java index c9645d53e0..225870ba3a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java @@ -18,6 +18,7 @@ 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.FilterParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -55,7 +56,7 @@ public class EthGetLogs implements JsonRpcMethod { final FilterParameter filter; try { filter = requestContext.getRequiredParameter(0, FilterParameter.class); - } catch (Exception e) { + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter parameter (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java index 8e3d55f1ea..8b54364a99 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.datatypes.Wei; 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -65,7 +66,7 @@ public class EthGetMinerDataByBlockHash implements JsonRpcMethod { final Hash hash; try { hash = requestContext.getRequest().getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java index c2df712686..e0fe246062 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java @@ -19,6 +19,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult; import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; @@ -44,7 +45,7 @@ public class EthGetMinerDataByBlockNumber extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java index 7c2f67b724..d1920b5c1a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java @@ -20,6 +20,7 @@ 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.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -51,7 +52,7 @@ public class EthGetProof extends AbstractBlockParameterOrBlockHashMethod { final JsonRpcRequestContext request) { try { return request.getRequiredParameter(2, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block or block hash parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -64,7 +65,7 @@ public class EthGetProof extends AbstractBlockParameterOrBlockHashMethod { final Address address; try { address = requestContext.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } @@ -110,7 +111,7 @@ public class EthGetProof extends AbstractBlockParameterOrBlockHashMethod { return Arrays.stream(request.getRequiredParameter(1, String[].class)) .map(UInt256::fromHexString) .collect(Collectors.toList()); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid storage keys parameters (index 1)", RpcErrorType.INVALID_STORAGE_KEYS_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java index 34ed62b632..a171fc16d1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java @@ -20,6 +20,7 @@ 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.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UInt256Parameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -41,7 +42,7 @@ public class EthGetStorageAt extends AbstractBlockParameterOrBlockHashMethod { final JsonRpcRequestContext request) { try { return request.getRequiredParameter(2, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block or block hash parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -52,14 +53,14 @@ public class EthGetStorageAt extends AbstractBlockParameterOrBlockHashMethod { final Address address; try { address = request.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final UInt256 position; try { position = request.getRequiredParameter(1, UInt256Parameter.class).getValue(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid position parameter (index 1)", RpcErrorType.INVALID_POSITION_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockHashAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockHashAndIndex.java index 9c7cf5e7a8..917c09a326 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockHashAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockHashAndIndex.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; @@ -47,7 +48,7 @@ public class EthGetTransactionByBlockHashAndIndex implements JsonRpcMethod { final Hash hash; try { hash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction hash parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, @@ -56,7 +57,7 @@ public class EthGetTransactionByBlockHashAndIndex implements JsonRpcMethod { final int index; try { index = requestContext.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction id parameter (index 1)", RpcErrorType.INVALID_TRANSACTION_ID_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java index a5383f6680..338a878368 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionCompleteResult; @@ -41,7 +42,7 @@ public class EthGetTransactionByBlockNumberAndIndex extends AbstractBlockParamet protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -53,7 +54,7 @@ public class EthGetTransactionByBlockNumberAndIndex extends AbstractBlockParamet final int index; try { index = request.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction index parameter (index 1)", RpcErrorType.INVALID_TRANSACTION_INDEX_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByHash.java index 90e7a6a1ed..5d8b008522 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByHash.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -54,7 +55,7 @@ public class EthGetTransactionByHash implements JsonRpcMethod { final Hash hash; try { hash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction hash parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java index a9916099ea..4e26f8ee98 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java @@ -20,6 +20,7 @@ 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.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -54,7 +55,7 @@ public class EthGetTransactionCount extends AbstractBlockParameterOrBlockHashMet final JsonRpcRequestContext request) { try { return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block or block hash parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -65,7 +66,7 @@ public class EthGetTransactionCount extends AbstractBlockParameterOrBlockHashMet final Address address; try { address = request.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } @@ -88,7 +89,7 @@ public class EthGetTransactionCount extends AbstractBlockParameterOrBlockHashMet final Address address; try { address = request.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceipt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceipt.java index a437cd86dc..44e4cfe0d6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceipt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceipt.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -51,7 +52,7 @@ public class EthGetTransactionReceipt implements JsonRpcMethod { final Hash hash; try { hash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction hash parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java index 9269bf965c..f76b461cef 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; @@ -49,14 +50,14 @@ public class EthGetUncleByBlockHashAndIndex implements JsonRpcMethod { final Hash hash; try { hash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } final int index; try { index = requestContext.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block index parameter (index 1)", RpcErrorType.INVALID_BLOCK_INDEX_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java index a6c5e6d89d..f7c9ecb0dd 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult; @@ -39,7 +40,7 @@ public class EthGetUncleByBlockNumberAndIndex extends AbstractBlockParameterMeth protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -51,7 +52,7 @@ public class EthGetUncleByBlockNumberAndIndex extends AbstractBlockParameterMeth final int index; try { index = request.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block index (index 1)", RpcErrorType.INVALID_BLOCK_INDEX_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java index 9a5a3b225b..02cd3c4242 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -42,7 +43,7 @@ public class EthGetUncleCountByBlockHash implements JsonRpcMethod { final Hash hash; try { hash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockNumber.java index ddd130542c..8d935942ad 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockNumber.java @@ -16,7 +16,10 @@ 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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -33,7 +36,12 @@ public class EthGetUncleCountByBlockNumber extends AbstractBlockParameterMethod @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (JsonRpcParameterException e) { + throw new InvalidJsonRpcParameters( + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthNewFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthNewFilter.java index 7578b43a2e..d6edccd2e7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthNewFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthNewFilter.java @@ -19,6 +19,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -42,7 +43,7 @@ public class EthNewFilter implements JsonRpcMethod { final FilterParameter filter; try { filter = requestContext.getRequiredParameter(0, FilterParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter paramters (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java index 272014d3bc..10582e7a1c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java @@ -21,6 +21,7 @@ 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.exception.InvalidJsonRpcRequestException; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -72,7 +73,7 @@ public class EthSendRawTransaction implements JsonRpcMethod { final String rawTransaction; try { rawTransaction = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction parameters (index 0)", RpcErrorType.INVALID_TRANSACTION_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitHashRate.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitHashRate.java index c0763e77f6..488f89b3a5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitHashRate.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitHashRate.java @@ -17,6 +17,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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -42,14 +43,14 @@ public class EthSubmitHashRate implements JsonRpcMethod { final String hashRate; try { hashRate = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid hash rate parameter (index 0)", RpcErrorType.INVALID_HASH_RATE_PARAMS, e); } final String id; try { id = requestContext.getRequiredParameter(1, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid sealer ID parameter (index 1)", RpcErrorType.INVALID_SEALER_ID_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWork.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWork.java index 9474fec7ba..9002b2a0dd 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWork.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSubmitWork.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -54,21 +55,21 @@ public class EthSubmitWork implements JsonRpcMethod { try { nonce = Bytes.fromHexString(requestContext.getRequiredParameter(0, String.class)).getLong(0); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid nonce parameter (index 0)", RpcErrorType.INVALID_NONCE_PARAMS, e); } Hash mixHash; try { mixHash = requestContext.getRequiredParameter(2, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid mix hash parameter (index 2)", RpcErrorType.INVALID_MIX_HASH_PARAMS, e); } Bytes powHash; try { powHash = Bytes.fromHexString(requestContext.getRequiredParameter(1, String.class)); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid PoW hash parameter (index 1)", RpcErrorType.INVALID_POW_HASH_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthUninstallFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthUninstallFilter.java index b51dc1f4fd..8771343ecf 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthUninstallFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthUninstallFilter.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -40,7 +41,7 @@ public class EthUninstallFilter implements JsonRpcMethod { final String filterId; try { filterId = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter ID parameter (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java index 7d7bd013be..df593f9fbc 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java @@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; 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.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; public class JsonCallParameterUtil { @@ -27,7 +28,7 @@ public class JsonCallParameterUtil { final JsonCallParameter callParams; try { callParams = request.getRequiredParameter(0, JsonCallParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid call parameters (index 0)", RpcErrorType.INVALID_CALL_PARAMS); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginsReloadConfiguration.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginsReloadConfiguration.java index f895008e23..3761b8114a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginsReloadConfiguration.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginsReloadConfiguration.java @@ -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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -55,7 +56,7 @@ public class PluginsReloadConfiguration implements JsonRpcMethod { } reloadPluginConfig(namedPlugins.get(pluginName)); return new JsonRpcSuccessResponse(requestContext.getRequest().getId()); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.INVAlID_PLUGIN_NAME_PARAMS); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java index 5ec46e08cc..adacf01e76 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java @@ -21,6 +21,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -72,7 +73,7 @@ public class TraceBlock extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java index 9882257143..082283a815 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java @@ -19,6 +19,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -60,7 +61,7 @@ public class TraceCall extends AbstractTraceCall { final JsonRpcRequestContext requestContext) { try { return requestContext.getRequiredParameter(1, TraceTypeParameter.class).getTraceTypes(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid trace type parameter (index 1)", RpcErrorType.INVALID_TRACE_TYPE_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java index 2cbeb8ee7f..10d4018bce 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java @@ -22,6 +22,7 @@ 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.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceCallManyParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; @@ -67,7 +68,7 @@ public class TraceCallMany extends TraceCall implements JsonRpcMethod { final Optional maybeBlockParameter; try { maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java index a3d6b2561f..74bfec87c2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java @@ -22,6 +22,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; @@ -90,7 +91,7 @@ public class TraceFilter extends TraceBlock { final FilterParameter filterParameter; try { filterParameter = requestContext.getRequiredParameter(0, FilterParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter parameter (index 0)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceGet.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceGet.java index b346637ec2..e1c27aed79 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceGet.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceGet.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -58,7 +59,7 @@ public class TraceGet extends AbstractTraceByHash implements JsonRpcMethod { final Hash transactionHash; try { transactionHash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction hash parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, @@ -67,7 +68,7 @@ public class TraceGet extends AbstractTraceByHash implements JsonRpcMethod { final List traceNumbersAsStrings; try { traceNumbersAsStrings = requestContext.getRequiredParameter(1, List.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid trace numbers parameters (index 1)", RpcErrorType.INVALID_TRACE_NUMBERS_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceRawTransaction.java index a720569875..71c8247784 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceRawTransaction.java @@ -19,6 +19,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -74,14 +75,14 @@ public class TraceRawTransaction extends AbstractTraceByBlock implements JsonRpc final String rawTransaction; try { rawTransaction = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction parameters (index 0)", RpcErrorType.INVALID_TRANSACTION_PARAMS, e); } final TraceTypeParameter traceTypeParameter; try { traceTypeParameter = requestContext.getRequiredParameter(1, TraceTypeParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid trace type parameter (index 1)", RpcErrorType.INVALID_TRACE_TYPE_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java index a8b3bbc46d..202d2ddbbb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java @@ -21,6 +21,7 @@ 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.TraceBlock.ChainUpdater; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; @@ -74,7 +75,7 @@ public class TraceReplayBlockTransactions extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -86,7 +87,7 @@ public class TraceReplayBlockTransactions extends AbstractBlockParameterMethod { final TraceTypeParameter traceTypeParameter; try { traceTypeParameter = request.getRequiredParameter(1, TraceTypeParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid trace type parameter (index 1)", RpcErrorType.INVALID_TRACE_TYPE_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceTransaction.java index b79b9620e8..be69423681 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceTransaction.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; @@ -50,7 +51,7 @@ public class TraceTransaction extends AbstractTraceByHash implements JsonRpcMeth final Hash transactionHash; try { transactionHash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction hash parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java index 8dc38135c6..81c366926a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java @@ -17,6 +17,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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.PendingTransactionsParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; @@ -58,7 +59,7 @@ public class TxPoolBesuPendingTransactions implements JsonRpcMethod { try { limit = requestContext.getOptionalParameter(0, Integer.class).orElse(pendingTransactions.size()); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction limit parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_LIMIT_PARAMS, @@ -71,7 +72,7 @@ public class TxPoolBesuPendingTransactions implements JsonRpcMethod { .getOptionalParameter(1, PendingTransactionsParams.class) .map(PendingTransactionsParams::filters) .orElse(Collections.emptyList()); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid pending transactions parameter (index 1)", RpcErrorType.INVALID_PENDING_TRANSACTIONS_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java index b70ad76051..e34a462800 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.crypto.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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -45,7 +46,7 @@ public class Web3Sha3 implements JsonRpcMethod { final String data; try { data = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid data parameter (index 0)", RpcErrorType.INVALID_DATA_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java index 7df76973ac..11ec3d04c5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonR import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EngineForkchoiceUpdatedParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePayloadAttributesParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -84,7 +85,7 @@ public abstract class AbstractEngineForkchoiceUpdated extends ExecutionEngineJso final EngineForkchoiceUpdatedParameter forkChoice; try { forkChoice = requestContext.getRequiredParameter(0, EngineForkchoiceUpdatedParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid engine forkchoice updated parameter (index 0)", RpcErrorType.INVALID_ENGINE_FORKCHOICE_UPDATED_PARAMS, @@ -94,7 +95,7 @@ public abstract class AbstractEngineForkchoiceUpdated extends ExecutionEngineJso try { maybePayloadAttributes = requestContext.getOptionalParameter(1, EnginePayloadAttributesParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid engine payload attributes parameter (index 1)", RpcErrorType.INVALID_ENGINE_FORKCHOICE_UPDATED_PAYLOAD_ATTRIBUTES, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java index a6f94ac00e..d95b532e77 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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.RpcErrorType; @@ -72,7 +73,7 @@ public abstract class AbstractEngineGetPayload extends ExecutionEngineJsonRpcMet final PayloadIdentifier payloadId; try { payloadId = request.getRequiredParameter(0, PayloadIdentifier.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid payload ID parameter (index 0)", RpcErrorType.INVALID_PAYLOAD_ID_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java index 02ccf5d231..78b96796cb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java @@ -39,6 +39,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngin import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.ConsolidationRequestParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.DepositRequestParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePayloadParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalRequestParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -109,7 +110,7 @@ public abstract class AbstractEngineNewPayload extends ExecutionEngineJsonRpcMet final EnginePayloadParameter blockParam; try { blockParam = requestContext.getRequiredParameter(0, EnginePayloadParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcRequestException( "Invalid engine payload parameter (index 0)", RpcErrorType.INVALID_ENGINE_NEW_PAYLOAD_PARAMS, @@ -119,7 +120,7 @@ public abstract class AbstractEngineNewPayload extends ExecutionEngineJsonRpcMet final Optional> maybeVersionedHashParam; try { maybeVersionedHashParam = requestContext.getOptionalList(1, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcRequestException( "Invalid versioned hash parameters (index 1)", RpcErrorType.INVALID_VERSIONED_HASH_PARAMS, @@ -131,7 +132,7 @@ public abstract class AbstractEngineNewPayload extends ExecutionEngineJsonRpcMet Optional maybeParentBeaconBlockRootParam; try { maybeParentBeaconBlockRootParam = requestContext.getOptionalParameter(2, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcRequestException( "Invalid parent beacon block root parameters (index 2)", RpcErrorType.INVALID_PARENT_BEACON_BLOCK_ROOT_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeCapabilities.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeCapabilities.java index 624d9bebdd..2666888ed6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeCapabilities.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeCapabilities.java @@ -22,6 +22,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -61,8 +62,7 @@ public class EngineExchangeCapabilities extends ExecutionEngineJsonRpcMethod { () -> { try { return requestContext.getRequiredParameter(0, String[].class); - } catch ( - Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid remote capabilities parameters (index 0)", RpcErrorType.INVALID_REMOTE_CAPABILITIES_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java index 67b8657533..924e8ac989 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java @@ -23,6 +23,7 @@ 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.parameters.EngineExchangeTransitionConfigurationParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -72,7 +73,7 @@ public class EngineExchangeTransitionConfiguration extends ExecutionEngineJsonRp remoteTransitionConfiguration = requestContext.getRequiredParameter( 0, EngineExchangeTransitionConfigurationParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid engine exchange transition configuration parameters (index 0)", RpcErrorType.INVALID_ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java index 0e6b62d320..facbd026d4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java @@ -20,6 +20,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -64,7 +65,7 @@ public class EngineGetPayloadBodiesByHashV1 extends ExecutionEngineJsonRpcMethod final Hash[] blockHashes; try { blockHashes = request.getRequiredParameter(0, Hash[].class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block hash parameters (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java index ec5d5bf604..2d21a7282a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java @@ -19,6 +19,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -61,7 +62,7 @@ public class EngineGetPayloadBodiesByRangeV1 extends ExecutionEngineJsonRpcMetho final long startBlockNumber; try { startBlockNumber = request.getRequiredParameter(0, UnsignedLongParameter.class).getValue(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid start block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, @@ -70,7 +71,7 @@ public class EngineGetPayloadBodiesByRangeV1 extends ExecutionEngineJsonRpcMetho final long count; try { count = request.getRequiredParameter(1, UnsignedLongParameter.class).getValue(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block count params (index 1)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebug.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebug.java index e55cfb1506..c4bca21803 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebug.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebug.java @@ -26,6 +26,7 @@ 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.parameters.EnginePreparePayloadParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -72,7 +73,7 @@ public class EnginePreparePayloadDebug extends ExecutionEngineJsonRpcMethod { Optional.empty(), Optional.empty(), Optional.empty())); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid engine prepare payload parameter (index 0)", RpcErrorType.INVALID_ENGINE_PREPARE_PAYLOAD_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerChangeTargetGasLimit.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerChangeTargetGasLimit.java index f1b949ad63..cd1b033dc4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerChangeTargetGasLimit.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerChangeTargetGasLimit.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -49,7 +50,7 @@ public class MinerChangeTargetGasLimit implements JsonRpcMethod { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.TARGET_GAS_LIMIT_MODIFICATION_UNSUPPORTED); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid target gas limit parameter (index 0)", RpcErrorType.INVALID_TARGET_GAS_LIMIT_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java index d6676a6074..f30db35e77 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java @@ -19,6 +19,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -47,7 +48,7 @@ public class MinerSetCoinbase implements JsonRpcMethod { } catch (final UnsupportedOperationException ex) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.INVALID_REQUEST); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java index 5b9bc581db..51395e24f7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java @@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner; 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.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -60,12 +61,10 @@ public class MinerSetExtraData implements JsonRpcMethod { .addArgument(() -> new String(extraData.toArray(), StandardCharsets.UTF_8)) .log(); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); - } catch (Exception invalidJsonRpcParameters) { // TODO:replace with "IllegalArgumentException | - // JsonRpcParameter.JsonRpcParameterException" + } catch (IllegalArgumentException | JsonRpcParameterException e) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), - new JsonRpcError( - RpcErrorType.INVALID_EXTRA_DATA_PARAMS, invalidJsonRpcParameters.getMessage())); + new JsonRpcError(RpcErrorType.INVALID_EXTRA_DATA_PARAMS, e.getMessage())); } } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java index 59c18b80db..733ed3a8f3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java @@ -19,6 +19,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -56,7 +57,7 @@ public class MinerSetMinGasPrice implements JsonRpcMethod { requestContext.getRequest().getId(), new JsonRpcError( RpcErrorType.INVALID_MIN_GAS_PRICE_PARAMS, invalidJsonRpcParameters.getMessage())); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid min gas price parameter (index 0)", RpcErrorType.INVALID_MIN_GAS_PRICE_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java index 9c217b0c23..b1bf4338f7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Wei; 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.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -51,11 +52,10 @@ public class MinerSetMinPriorityFee implements JsonRpcMethod { LOG.debug( "min priority fee per gas changed to {}", minPriorityFeePerGas.toHumanReadableString()); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); - } catch (final IllegalArgumentException invalidJsonRpcParameters) { + } catch (final IllegalArgumentException | JsonRpcParameterException e) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), - new JsonRpcError( - RpcErrorType.INVALID_MIN_PRIORITY_FEE_PARAMS, invalidJsonRpcParameters.getMessage())); + new JsonRpcError(RpcErrorType.INVALID_MIN_PRIORITY_FEE_PARAMS, e.getMessage())); } } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java index f3407ba10d..32459b3b4c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -48,7 +49,7 @@ public class PermAddAccountsToAllowlist implements JsonRpcMethod { final List accountsList; try { accountsList = requestContext.getRequiredParameter(0, List.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid accounts list parameter (index 0)", RpcErrorType.INVALID_ACCOUNT_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToAllowlist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToAllowlist.java index 2aec3b6f95..5f8374a884 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToAllowlist.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToAllowlist.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.StringListParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -50,7 +51,7 @@ public class PermAddNodesToAllowlist implements JsonRpcMethod { final StringListParameter enodeListParam; try { enodeListParam = requestContext.getRequiredParameter(0, StringListParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid enode list parameter (index 0)", RpcErrorType.INVALID_ENODE_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java index a39acd5e9c..ac7bffdf57 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -48,7 +49,7 @@ public class PermRemoveAccountsFromAllowlist implements JsonRpcMethod { final List accountsList; try { accountsList = requestContext.getRequiredParameter(0, List.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid accounts list parameter (index 0)", RpcErrorType.INVALID_ACCOUNT_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromAllowlist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromAllowlist.java index 862b694f4f..16e3bc234a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromAllowlist.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromAllowlist.java @@ -18,6 +18,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.StringListParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -50,7 +51,7 @@ public class PermRemoveNodesFromAllowlist implements JsonRpcMethod { final StringListParameter enodeListParam; try { enodeListParam = requestContext.getRequiredParameter(0, StringListParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid enode list parameter (index 0)", RpcErrorType.INVALID_ENODE_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java index a8b5fb7dc8..22fb511ef4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java @@ -14,8 +14,6 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; - import java.util.List; import java.util.Optional; @@ -40,13 +38,12 @@ public class JsonRpcParameter { * @param The type of parameter. * @return Returns the parameter cast as T if available, otherwise throws exception. */ - // TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to - // handle it to supply appropriate context - public T required(final Object[] params, final int index, final Class paramClass) { + public T required(final Object[] params, final int index, final Class paramClass) + throws JsonRpcParameterException { return optional(params, index, paramClass) .orElseThrow( () -> - new InvalidJsonRpcParameters( + new JsonRpcParameterException( "Missing required json rpc parameter at index " + index)); } @@ -60,11 +57,8 @@ public class JsonRpcParameter { * @param The type of parameter. * @return Returns the parameter cast as T if available. */ - // TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to - // handle it to supply appropriate context - @SuppressWarnings("unchecked") - public Optional optional( - final Object[] params, final int index, final Class paramClass) { + public Optional optional(final Object[] params, final int index, final Class paramClass) + throws JsonRpcParameterException { if (params == null || params.length <= index || params[index] == null) { return Optional.empty(); } @@ -73,14 +67,14 @@ public class JsonRpcParameter { final Object rawParam = params[index]; if (paramClass.isAssignableFrom(rawParam.getClass())) { // If we're dealing with a simple type, just cast the value - param = (T) rawParam; + param = paramClass.cast(rawParam); } else { // Otherwise, serialize param back to json and then deserialize to the paramClass type try { final String json = mapper.writeValueAsString(rawParam); param = mapper.readValue(json, paramClass); } catch (final JsonProcessingException e) { - throw new InvalidJsonRpcParameters( + throw new JsonRpcParameterException( String.format( "Invalid json rpc parameter at index %d. Supplied value was: '%s' of type: '%s' - expected type: '%s'", index, rawParam, rawParam.getClass().getName(), paramClass.getName()), @@ -91,10 +85,9 @@ public class JsonRpcParameter { return Optional.of(param); } - // TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to - // handle it to supply appropriate context public Optional> optionalList( - final Object[] params, final int index, final Class listClass) { + final Object[] params, final int index, final Class listClass) + throws JsonRpcParameterException { if (params == null || params.length <= index || params[index] == null) { return Optional.empty(); } @@ -105,7 +98,7 @@ public class JsonRpcParameter { List returnedList = mapper.readValue(listJson, new TypeReference>() {}); return Optional.of(returnedList); } catch (JsonProcessingException e) { - throw new InvalidJsonRpcParameters( + throw new JsonRpcParameterException( String.format( "Invalid json rpc parameter at index %d. Supplied value was: '%s' of type: '%s' - expected type: '%s'", index, rawParam, rawParam.getClass().getName(), listClass.getName()), diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java index bbd7189ffa..4ef7e0aa1c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java @@ -19,6 +19,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -55,7 +56,7 @@ public class PrivGetFilterChanges implements JsonRpcMethod { final String privacyGroupId; try { privacyGroupId = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 0)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, @@ -64,7 +65,7 @@ public class PrivGetFilterChanges implements JsonRpcMethod { final String filterId; try { filterId = requestContext.getRequiredParameter(1, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter ID parameter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java index 4436c33b50..ea6a5894a3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java @@ -19,6 +19,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -55,7 +56,7 @@ public class PrivGetFilterLogs implements JsonRpcMethod { final String privacyGroupId; try { privacyGroupId = request.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 0)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, @@ -64,7 +65,7 @@ public class PrivGetFilterLogs implements JsonRpcMethod { final String filterId; try { filterId = request.getRequiredParameter(1, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter ID parameter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java index c1e122578a..eb41a1dad4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java @@ -19,6 +19,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -50,7 +51,7 @@ public class PrivUninstallFilter implements JsonRpcMethod { final String privacyGroupId; try { privacyGroupId = request.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 0)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, @@ -59,7 +60,7 @@ public class PrivUninstallFilter implements JsonRpcMethod { final String filterId; try { filterId = request.getRequiredParameter(1, String.class); - } catch (Exception e) { + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter ID parameter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java index 12c496b639..e96a08eb7d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java @@ -25,6 +25,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -77,7 +78,7 @@ public abstract class AbstractEeaSendRawTransaction implements JsonRpcMethod { final String rawPrivateTransaction; try { rawPrivateTransaction = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java index e09d5966cf..5d9edc63b9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonR import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -55,7 +56,7 @@ public class PrivCall extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(2, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -68,7 +69,7 @@ public class PrivCall extends AbstractBlockParameterMethod { final String privacyGroupId; try { privacyGroupId = request.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 0)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, @@ -115,7 +116,7 @@ public class PrivCall extends AbstractBlockParameterMethod { final JsonCallParameter callParams; try { callParams = request.getRequiredParameter(1, JsonCallParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid call parameters (index 1)", RpcErrorType.INVALID_CALL_PARAMS); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java index ae35506298..568125a276 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java @@ -20,6 +20,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -55,7 +56,7 @@ public class PrivCreatePrivacyGroup implements JsonRpcMethod { final CreatePrivacyGroupParameter parameter; try { parameter = requestContext.getRequiredParameter(0, CreatePrivacyGroupParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid create privacy group parameter (index 0)", RpcErrorType.INVALID_CREATE_PRIVACY_GROUP_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java index 9ee5d57b3b..dc0fc90f66 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java @@ -23,6 +23,7 @@ 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.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -63,7 +64,7 @@ public class PrivDebugGetStateRoot extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(1, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -75,7 +76,7 @@ public class PrivDebugGetStateRoot extends AbstractBlockParameterMethod { final String privacyGroupId; try { privacyGroupId = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 0)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java index 5c6f929c5c..61b7791b3c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java @@ -20,6 +20,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -55,7 +56,7 @@ public class PrivDeletePrivacyGroup implements JsonRpcMethod { final String privacyGroupId; try { privacyGroupId = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 0)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java index 39003358ed..aac4df3d2c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java @@ -25,6 +25,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -74,7 +75,7 @@ public class PrivDistributeRawTransaction implements JsonRpcMethod { final String rawPrivateTransaction; try { rawPrivateTransaction = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid private transaction parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java index 8f0e829084..7e82323223 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java @@ -21,6 +21,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -60,7 +61,7 @@ public class PrivFindPrivacyGroup implements JsonRpcMethod { final String[] addresses; try { addresses = requestContext.getRequiredParameter(0, String[].class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameters (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java index 5d9498f3bd..7042d357f1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java @@ -20,6 +20,7 @@ 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.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -50,7 +51,7 @@ public class PrivGetCode extends AbstractBlockParameterMethod { protected BlockParameter blockParameter(final JsonRpcRequestContext request) { try { return request.getRequiredParameter(2, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } @@ -62,7 +63,7 @@ public class PrivGetCode extends AbstractBlockParameterMethod { final String privacyGroupId; try { privacyGroupId = request.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 0)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, @@ -71,7 +72,7 @@ public class PrivGetCode extends AbstractBlockParameterMethod { final Address address; try { address = request.getRequiredParameter(1, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 1)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java index 31bfc52c80..9f231f41c0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java @@ -22,6 +22,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -69,21 +70,21 @@ public class PrivGetEeaTransactionCount implements JsonRpcMethod { final Address address; try { address = requestContext.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final String privateFrom; try { privateFrom = requestContext.getRequiredParameter(1, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { 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 + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid private for parameters (index 2)", RpcErrorType.INVALID_PRIVATE_FOR_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java index d0c75da33f..6947ea5e54 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java @@ -20,6 +20,7 @@ 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.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -74,7 +75,7 @@ public class PrivGetLogs implements JsonRpcMethod { final FilterParameter filter; try { filter = requestContext.getRequiredParameter(1, FilterParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter parameter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java index 0629b2d55d..8779181599 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java @@ -21,6 +21,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -62,7 +63,7 @@ public class PrivGetPrivateTransaction implements JsonRpcMethod { final Hash hash; try { hash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction hash parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java index 2cbcc65535..d8757dc2fb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java @@ -21,6 +21,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -60,14 +61,14 @@ public class PrivGetTransactionCount implements JsonRpcMethod { final Address address; try { address = requestContext.getRequiredParameter(0, Address.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final String privacyGroupId; try { privacyGroupId = requestContext.getRequiredParameter(1, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 1)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java index a1844841f0..287793ddc0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java @@ -22,6 +22,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; @@ -70,7 +71,7 @@ public class PrivGetTransactionReceipt implements JsonRpcMethod { final Hash pmtTransactionHash; try { pmtTransactionHash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction hash parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java index e73b0c141c..49fc11f4b8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonR 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; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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; @@ -51,9 +52,9 @@ public class PrivNewFilter implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext request) { final String privacyGroupId; - try { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + try { privacyGroupId = request.getRequiredParameter(0, String.class); - } catch (Exception e) { + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 0)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, @@ -62,7 +63,7 @@ public class PrivNewFilter implements JsonRpcMethod { final FilterParameter filter; try { filter = request.getRequiredParameter(1, FilterParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter parameter (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java index b1802b07eb..07d663bef5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java @@ -17,8 +17,10 @@ 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.methods.TraceTransaction; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.privateProcessor.PrivateBlockTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -69,8 +71,24 @@ public class PrivTraceTransaction extends AbstractPrivateTraceByHash implements @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final String privacyGroupId = requestContext.getRequiredParameter(0, String.class); - final Hash transactionHash = requestContext.getRequiredParameter(1, Hash.class); + final String privacyGroupId; + try { + privacyGroupId = requestContext.getRequiredParameter(0, String.class); + } catch (JsonRpcParameterException e) { + throw new InvalidJsonRpcParameters( + "Invalid privacy group ID parameter (index 0)", + RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, + e); + } + final Hash transactionHash; + try { + transactionHash = requestContext.getRequiredParameter(1, Hash.class); + } catch (JsonRpcParameterException e) { + throw new InvalidJsonRpcParameters( + "Invalid transaction hash parameter (index 1)", + RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, + e); + } LOG.trace("Received RPC rpcName={} txHash={}", getName(), transactionHash); if (privacyGroupId.isEmpty() || transactionHash.isEmpty()) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java index e6cf056989..0a66d1aa73 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java @@ -21,6 +21,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -59,7 +60,7 @@ public class PrivxFindFlexiblePrivacyGroup implements JsonRpcMethod { final String[] addresses; try { addresses = requestContext.getRequiredParameter(0, String[].class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid address parameters (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/request/SubscriptionRequestMapper.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/request/SubscriptionRequestMapper.java index 7235a81987..8bc3579849 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/request/SubscriptionRequestMapper.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/request/SubscriptionRequestMapper.java @@ -17,6 +17,7 @@ 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -35,7 +36,7 @@ public class SubscriptionRequestMapper { final SubscriptionType subscriptionType; try { subscriptionType = webSocketRpcRequestBody.getRequiredParameter(0, SubscriptionType.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid subscription type parameter (index 0)", RpcErrorType.INVALID_SUBSCRIPTION_PARAMS, @@ -70,7 +71,7 @@ public class SubscriptionRequestMapper { final Optional params; try { params = webSocketRpcRequestBody.getOptionalParameter(1, SubscriptionParam.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid subscription parameter (index 1)", RpcErrorType.INVALID_SUBSCRIPTION_PARAMS, e); } @@ -87,7 +88,7 @@ public class SubscriptionRequestMapper { final FilterParameter filterParameter; try { filterParameter = request.getRequiredParameter(1, FilterParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter parameters (index 1)", RpcErrorType.INVALID_FILTER_PARAMS, e); } @@ -104,7 +105,7 @@ public class SubscriptionRequestMapper { try { subscriptionId = webSocketRpcRequestBody.getRequiredParameter(0, UnsignedLongParameter.class).getValue(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid subscription ID parameter (index 0)", RpcErrorType.INVALID_SUBSCRIPTION_PARAMS, @@ -125,7 +126,7 @@ public class SubscriptionRequestMapper { final String privacyGroupId; try { privacyGroupId = webSocketRpcRequestBody.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 0)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, @@ -134,7 +135,7 @@ public class SubscriptionRequestMapper { final SubscriptionType subscriptionType; try { subscriptionType = webSocketRpcRequestBody.getRequiredParameter(1, SubscriptionType.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid subscription type parameter (index 1)", RpcErrorType.INVALID_SUBSCRIPTION_PARAMS, @@ -148,7 +149,7 @@ public class SubscriptionRequestMapper { try { filterParameter = jsonRpcRequestContext.getRequiredParameter(2, FilterParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid filter parameter (index 2)", RpcErrorType.INVALID_FILTER_PARAMS, e); } @@ -180,7 +181,7 @@ public class SubscriptionRequestMapper { final String privacyGroupId; try { privacyGroupId = webSocketRpcRequestBody.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid privacy group ID parameter (index 0)", RpcErrorType.INVALID_PRIVACY_GROUP_PARAMS, @@ -190,7 +191,7 @@ public class SubscriptionRequestMapper { try { subscriptionId = webSocketRpcRequestBody.getRequiredParameter(1, UnsignedLongParameter.class).getValue(); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid subscription ID parameter (index 1)", RpcErrorType.INVALID_SUBSCRIPTION_PARAMS, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java index 9cc6947b26..1eef04fb93 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java @@ -201,7 +201,7 @@ public class TxPoolBesuPendingTransactionsTest { assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid pending transactions parameter (index 1)"); + .hasMessageContaining("Unknown field expected one of `eq`, `gt`, `lt`, `action`"); } @Test @@ -229,7 +229,7 @@ public class TxPoolBesuPendingTransactionsTest { assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid pending transactions parameter (index 1)"); + .hasMessageContaining("Only one operator per filter type allowed"); } @Test @@ -256,7 +256,7 @@ public class TxPoolBesuPendingTransactionsTest { assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid pending transactions parameter (index 1)"); + .hasMessageContaining("The `from` filter only supports the `eq` operator"); } @Test @@ -283,7 +283,7 @@ public class TxPoolBesuPendingTransactionsTest { assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid pending transactions parameter (index 1)"); + .hasMessageContaining("The `to` filter only supports the `eq` or `action` operator"); } private Set getTransactionPool() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebugTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebugTest.java index 4de9f8bb56..9c5067f7a8 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebugTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebugTest.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.consensus.merge.blockcreation.PayloadIdentifier; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePreparePayloadParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePreparePayloadResult; @@ -56,7 +57,7 @@ public class EnginePreparePayloadDebugTest { @Mock private EnginePreparePayloadParameter param; @BeforeEach - public void setUp() { + public void setUp() throws JsonRpcParameterException { when(protocolContext.safeConsensusContext(MergeContext.class)) .thenReturn(Optional.of(mergeContext)); when(requestContext.getOptionalParameter(0, EnginePreparePayloadParameter.class)) @@ -84,7 +85,7 @@ public class EnginePreparePayloadDebugTest { } @Test - public void shouldReturnPayloadIdWhenNoParams() { + public void shouldReturnPayloadIdWhenNoParams() throws JsonRpcParameterException { when(requestContext.getOptionalParameter(0, EnginePreparePayloadParameter.class)) .thenReturn(Optional.empty()); checkForPayloadId(); diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java index e4fd7bcff2..398d72d665 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Hash; 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -45,7 +46,7 @@ public class TestGetLogHash implements JsonRpcMethod { final Hash txHash; try { txHash = requestContext.getRequiredParameter(0, Hash.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid transaction hash parameter (index 0)", RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java index 516dc2f55f..580b107a8b 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -56,7 +57,7 @@ public class TestImportRawBlock implements JsonRpcMethod { final String input; try { input = requestContext.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java index 7907cee3f7..80a4872442 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -49,7 +50,7 @@ public class TestMineBlocks implements JsonRpcMethod { long blocksToMine = 0; try { blocksToMine = requestContext.getRequiredParameter(0, Long.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid blocks to mine (index 0)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java index d9cfafbaea..717cf41b45 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java @@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.retesteth.methods; 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -40,7 +41,7 @@ public class TestModifyTimestamp implements JsonRpcMethod { final long epochSeconds; try { epochSeconds = requestContext.getRequiredParameter(0, Long.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid timestamp parameter (index 0)", RpcErrorType.INVALID_TIMESTAMP_PARAMS, e); } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java index d5adb36a24..d9b847af42 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java @@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.retesteth.methods; 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.JsonRpcParameter.JsonRpcParameterException; 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; @@ -41,7 +42,7 @@ public class TestRewindToBlock implements JsonRpcMethod { final long blockNumber; try { blockNumber = requestContext.getRequiredParameter(0, Long.TYPE); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } diff --git a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1Protocol.java b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1Protocol.java index 308d15f6f1..4311647948 100644 --- a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1Protocol.java +++ b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1Protocol.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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.blockcreation.MiningCoordinator; @@ -175,18 +176,24 @@ public class Stratum1Protocol implements StratumProtocol { long nonce; try { nonce = Bytes.fromHexString(message.getRequiredParameter(2, String.class)).getLong(0); - } catch (Exception e) { + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid nonce parameter (index 2)", RpcErrorType.INVALID_NONCE_PARAMS, e); } - Hash mixHash = null; + Hash mixHash; try { mixHash = Hash.fromHexString(message.getRequiredParameter(4, String.class)); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid mix hash parameter (index 4)", RpcErrorType.INVALID_MIX_HASH_PARAMS, e); } - Bytes powHash = Bytes.fromHexString(message.getRequiredParameter(3, String.class)); + Bytes powHash; + try { + powHash = Bytes.fromHexString(message.getRequiredParameter(3, String.class)); + } catch (JsonRpcParameterException e) { + throw new InvalidJsonRpcParameters( + "Invalid PoW hash parameter (index 3)", RpcErrorType.INVALID_POW_HASH_PARAMS, e); + } boolean result = false; final PoWSolution solution = new PoWSolution(nonce, mixHash, null, powHash); if (currentInput.getPrePowHash().equals(solution.getPowHash())) { diff --git a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumProtocol.java b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumProtocol.java index 3f13a56880..a6a8ac8807 100644 --- a/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumProtocol.java +++ b/ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/StratumProtocol.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.stratum; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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.blockcreation.MiningCoordinator; @@ -83,14 +84,14 @@ public interface StratumProtocol { final String hashRate; try { hashRate = message.getRequiredParameter(0, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid hash rate parameter (index 0)", RpcErrorType.INVALID_HASH_RATE_PARAMS, e); } final String id; try { id = message.getRequiredParameter(1, String.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( "Invalid sealer ID parameter (index 1)", RpcErrorType.INVALID_SEALER_ID_PARAMS, e); }