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