use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter in project besu by hyperledger.
the class SubscriptionRequestMapper method mapPrivateSubscribeRequest.
public PrivateSubscribeRequest mapPrivateSubscribeRequest(final JsonRpcRequestContext jsonRpcRequestContext, final String privacyUserId) throws InvalidSubscriptionRequestException {
try {
final WebSocketRpcRequest webSocketRpcRequestBody = validateRequest(jsonRpcRequestContext);
final String privacyGroupId = webSocketRpcRequestBody.getRequiredParameter(0, String.class);
final SubscriptionType subscriptionType = webSocketRpcRequestBody.getRequiredParameter(1, SubscriptionType.class);
switch(subscriptionType) {
case LOGS:
{
final FilterParameter filterParameter = jsonRpcRequestContext.getRequiredParameter(2, FilterParameter.class);
return new PrivateSubscribeRequest(SubscriptionType.LOGS, filterParameter, null, webSocketRpcRequestBody.getConnectionId(), privacyGroupId, privacyUserId);
}
default:
throw new InvalidSubscriptionRequestException("Invalid subscribe request. Invalid private subscription type.");
}
} catch (final InvalidSubscriptionRequestException e) {
throw e;
} catch (final Exception e) {
throw new InvalidSubscriptionRequestException("Error parsing subscribe request", e);
}
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter in project besu by hyperledger.
the class EthGetLogs method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final FilterParameter filter = requestContext.getRequiredParameter(0, FilterParameter.class);
if (!filter.isValid()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
}
final List<LogWithMetadata> matchingLogs = filter.getBlockHash().map(blockHash -> blockchain.matchingLogs(blockHash, filter.getLogsQuery(), requestContext::isAlive)).orElseGet(() -> {
final long fromBlockNumber = filter.getFromBlock().getNumber().orElse(0L);
final long toBlockNumber = filter.getToBlock().getNumber().orElse(blockchain.headBlockNumber());
return blockchain.matchingLogs(fromBlockNumber, toBlockNumber, filter.getLogsQuery(), requestContext::isAlive);
});
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), new LogsResult(matchingLogs));
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter in project besu by hyperledger.
the class EthNewFilter method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final FilterParameter filter = requestContext.getRequiredParameter(0, FilterParameter.class);
if (!filter.isValid()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
}
final String logFilterId = filterManager.installLogFilter(filter.getFromBlock(), filter.getToBlock(), filter.getLogsQuery());
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), logFilterId);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter in project besu by hyperledger.
the class EthNewFilterTest method newFilterWithAddressOnlyParamInstallsExpectedLogFilter.
@Test
public void newFilterWithAddressOnlyParamInstallsExpectedLogFilter() {
final Address address = Address.fromHexString("0x0");
final FilterParameter filterParameter = filterParamWithAddressAndTopics(address, null);
final JsonRpcRequestContext request = ethNewFilter(filterParameter);
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), "0x1");
final LogsQuery expectedLogsQuery = new LogsQuery.Builder().address(address).build();
when(filterManager.installLogFilter(any(), any(), eq(expectedLogsQuery))).thenReturn("0x1");
final JsonRpcResponse actualResponse = method.response(request);
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse);
verify(filterManager).installLogFilter(refEq(BlockParameter.LATEST), refEq(BlockParameter.LATEST), eq(expectedLogsQuery));
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter in project besu by hyperledger.
the class TraceFilter method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final FilterParameter filterParameter = requestContext.getRequiredParameter(0, FilterParameter.class);
final long fromBlock = resolveBlockNumber(filterParameter.getFromBlock());
final long toBlock = resolveBlockNumber(filterParameter.getToBlock());
LOG.trace("Received RPC rpcName={} fromBlock={} toBlock={}", getName(), fromBlock, toBlock);
final ObjectMapper mapper = new ObjectMapper();
final ArrayNodeWrapper resultArrayNode = new ArrayNodeWrapper(mapper.createArrayNode(), filterParameter.getAfter(), filterParameter.getCount());
long currentBlockNumber = fromBlock;
while (currentBlockNumber <= toBlock && !resultArrayNode.isFull()) {
Optional<Block> blockByNumber = blockchainQueriesSupplier.get().getBlockchain().getBlockByNumber(currentBlockNumber);
blockByNumber.ifPresent(block -> resultArrayNode.addAll(traceBlock(block, Optional.of(filterParameter))));
currentBlockNumber++;
}
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), resultArrayNode.getArrayNode());
}
Aggregations