Search in sources :

Example 1 with ArrayNodeWrapper

use of org.hyperledger.besu.ethereum.api.util.ArrayNodeWrapper 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());
}
Also used : ArrayNodeWrapper(org.hyperledger.besu.ethereum.api.util.ArrayNodeWrapper) Block(org.hyperledger.besu.ethereum.core.Block) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) FilterParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with ArrayNodeWrapper

use of org.hyperledger.besu.ethereum.api.util.ArrayNodeWrapper in project besu by hyperledger.

the class TraceBlock method traceBlock.

protected ArrayNodeWrapper traceBlock(final Block block, final Optional<FilterParameter> filterParameter) {
    if (block == null) {
        return emptyResult();
    }
    final ArrayNodeWrapper resultArrayNode = new ArrayNodeWrapper(MAPPER.createArrayNode());
    blockTracerSupplier.get().trace(block, new DebugOperationTracer(new TraceOptions(false, false, true))).ifPresent(blockTrace -> generateTracesFromTransactionTraceAndBlock(filterParameter, blockTrace.getTransactionTraces(), block, resultArrayNode));
    generateRewardsFromBlock(filterParameter, block, resultArrayNode);
    return resultArrayNode;
}
Also used : ArrayNodeWrapper(org.hyperledger.besu.ethereum.api.util.ArrayNodeWrapper) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions)

Aggregations

ArrayNodeWrapper (org.hyperledger.besu.ethereum.api.util.ArrayNodeWrapper)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FilterParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter)1 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)1 Block (org.hyperledger.besu.ethereum.core.Block)1 TraceOptions (org.hyperledger.besu.ethereum.debug.TraceOptions)1 DebugOperationTracer (org.hyperledger.besu.ethereum.vm.DebugOperationTracer)1