use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult in project besu by hyperledger.
the class EthGetFilterLogs method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final String filterId = requestContext.getRequiredParameter(0, String.class);
final List<LogWithMetadata> logs = filterManager.logs(filterId);
if (logs != null) {
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), new LogsResult(logs));
}
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.LOGS_FILTER_NOT_FOUND);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult 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.results.LogsResult in project besu by hyperledger.
the class EthGetFilterChangesTest method shouldReturnEmptyLogsWhenFilterManagerFindsLogFilterWithNoChanges.
@Test
public void shouldReturnEmptyLogsWhenFilterManagerFindsLogFilterWithNoChanges() {
final JsonRpcRequestContext request = requestWithParams("0x1");
when(filterManager.blockChanges(anyString())).thenReturn(null);
when(filterManager.pendingTransactionChanges(anyString())).thenReturn(null);
when(filterManager.logsChanges("0x1")).thenReturn(Lists.newArrayList());
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, new LogsResult(Lists.newArrayList()));
final JsonRpcResponse response = method.response(request);
assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult in project besu by hyperledger.
the class EthGetFilterChangesTest method shouldReturnLogsWhenFilterManagerFindsLogFilterWithLogs.
@Test
public void shouldReturnLogsWhenFilterManagerFindsLogFilterWithLogs() {
final JsonRpcRequestContext request = requestWithParams("0x1");
when(filterManager.blockChanges(anyString())).thenReturn(null);
when(filterManager.pendingTransactionChanges(anyString())).thenReturn(null);
when(filterManager.logsChanges("0x1")).thenReturn(Lists.newArrayList(logWithMetadata()));
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, new LogsResult(Lists.newArrayList(logWithMetadata())));
final JsonRpcResponse response = method.response(request);
assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult in project besu by hyperledger.
the class EthGetFilterLogsTest method shouldReturnExpectedLogsWhenFilterManagerReturnsLogs.
@Test
public void shouldReturnExpectedLogsWhenFilterManagerReturnsLogs() {
final JsonRpcRequestContext request = requestWithFilterId("0x1");
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, new LogsResult(logs()));
when(filterManager.logs(eq("0x1"))).thenReturn(logs());
final JsonRpcResponse response = method.response(request);
assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
}
Aggregations