Search in sources :

Example 1 with LogsResult

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);
}
Also used : LogWithMetadata(org.hyperledger.besu.ethereum.core.LogWithMetadata) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) LogsResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 2 with LogsResult

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));
}
Also used : LogsResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult) List(java.util.List) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) JsonRpcError(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError) FilterParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse) LogWithMetadata(org.hyperledger.besu.ethereum.core.LogWithMetadata) LogWithMetadata(org.hyperledger.besu.ethereum.core.LogWithMetadata) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) FilterParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter) LogsResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 3 with LogsResult

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);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) LogsResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult) Test(org.junit.Test)

Example 4 with LogsResult

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);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) LogsResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult) Test(org.junit.Test)

Example 5 with LogsResult

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);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) LogsResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult) Test(org.junit.Test)

Aggregations

JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)16 LogsResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult)16 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)12 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)10 LogWithMetadata (org.hyperledger.besu.ethereum.core.LogWithMetadata)10 Test (org.junit.Test)10 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)6 FilterParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter)4 Hash (org.hyperledger.besu.datatypes.Hash)3 MultiTenancyPrivacyController (org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController)3 List (java.util.List)2 RpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod)2 JsonRpcError (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError)2 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)2 LogsQuery (org.hyperledger.besu.ethereum.api.query.LogsQuery)2 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 JsonRpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod)1