use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace in project besu by hyperledger.
the class DebugTraceBlockByNumber method resultByBlockNumber.
@Override
protected Object resultByBlockNumber(final JsonRpcRequestContext request, final long blockNumber) {
final Optional<Hash> blockHash = getBlockchainQueries().getBlockHashByNumber(blockNumber);
final TraceOptions traceOptions = request.getOptionalParameter(1, TransactionTraceParams.class).map(TransactionTraceParams::traceOptions).orElse(TraceOptions.DEFAULT);
return blockHash.flatMap(hash -> blockTracerSupplier.get().trace(hash, new DebugOperationTracer(traceOptions)).map(BlockTrace::getTransactionTraces).map(DebugTraceTransactionResult::of)).orElse(null);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace in project besu by hyperledger.
the class DebugTraceBlockByHashTest method shouldReturnCorrectResponse.
@Test
public void shouldReturnCorrectResponse() {
final Object[] params = new Object[] { blockHash };
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_traceBlockByHash", params));
final TraceFrame traceFrame = new TraceFrame(12, Optional.of("NONE"), 45L, OptionalLong.of(56L), 0L, 2, Optional.empty(), null, Wei.ZERO, Bytes.EMPTY, Bytes.EMPTY, Optional.empty(), Optional.empty(), Optional.empty(), null, Optional.empty(), Optional.empty(), Optional.empty(), 0, Optional.empty(), false, Optional.empty(), Optional.empty());
final TransactionProcessingResult transaction1Result = mock(TransactionProcessingResult.class);
final TransactionProcessingResult transaction2Result = mock(TransactionProcessingResult.class);
final TransactionTrace transaction1Trace = mock(TransactionTrace.class);
final TransactionTrace transaction2Trace = mock(TransactionTrace.class);
BlockTrace blockTrace = new BlockTrace(Arrays.asList(transaction1Trace, transaction2Trace));
when(transaction1Trace.getTraceFrames()).thenReturn(Arrays.asList(traceFrame));
when(transaction2Trace.getTraceFrames()).thenReturn(Arrays.asList(traceFrame));
when(transaction1Trace.getResult()).thenReturn(transaction1Result);
when(transaction2Trace.getResult()).thenReturn(transaction2Result);
when(transaction1Result.getOutput()).thenReturn(Bytes.fromHexString("1234"));
when(transaction2Result.getOutput()).thenReturn(Bytes.fromHexString("1234"));
when(blockTracer.trace(eq(blockHash), any())).thenReturn(Optional.of(blockTrace));
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) debugTraceBlockByHash.response(request);
final Collection<?> result = (Collection<?>) response.getResult();
assertThat(result).hasSize(2);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace in project besu by hyperledger.
the class DebugTraceBlockByNumberTest method shouldReturnCorrectResponse.
@Test
public void shouldReturnCorrectResponse() {
final long blockNumber = 1L;
final Object[] params = new Object[] { Long.toHexString(blockNumber) };
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_traceBlockByNumber", params));
final TraceFrame traceFrame = new TraceFrame(12, Optional.of("NONE"), 45L, OptionalLong.of(56L), 0L, 2, Optional.empty(), null, Wei.ZERO, Bytes.EMPTY, Bytes.EMPTY, Optional.empty(), Optional.empty(), Optional.empty(), null, Optional.empty(), Optional.empty(), Optional.empty(), 0, Optional.empty(), false, Optional.empty(), Optional.empty());
final TransactionProcessingResult transaction1Result = mock(TransactionProcessingResult.class);
final TransactionProcessingResult transaction2Result = mock(TransactionProcessingResult.class);
final TransactionTrace transaction1Trace = mock(TransactionTrace.class);
final TransactionTrace transaction2Trace = mock(TransactionTrace.class);
final BlockTrace blockTrace = new BlockTrace(asList(transaction1Trace, transaction2Trace));
when(transaction1Trace.getTraceFrames()).thenReturn(singletonList(traceFrame));
when(transaction2Trace.getTraceFrames()).thenReturn(singletonList(traceFrame));
when(transaction1Trace.getResult()).thenReturn(transaction1Result);
when(transaction2Trace.getResult()).thenReturn(transaction2Result);
when(transaction1Result.getOutput()).thenReturn(Bytes.fromHexString("1234"));
when(transaction2Result.getOutput()).thenReturn(Bytes.fromHexString("1234"));
when(blockchain.getBlockHashByNumber(blockNumber)).thenReturn(Optional.of(blockHash));
when(blockTracer.trace(eq(blockHash), any())).thenReturn(Optional.of(blockTrace));
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) debugTraceBlockByNumber.response(request);
final Collection<DebugTraceTransactionResult> result = getResult(response);
assertThat(result).usingFieldByFieldElementComparator().isEqualTo(DebugTraceTransactionResult.of(blockTrace.getTransactionTraces()));
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace in project besu by hyperledger.
the class TraceReplayBlockTransactions method traceBlock.
private Object traceBlock(final Block block, final TraceTypeParameter traceTypeParameter) {
if (block == null || block.getBody().getTransactions().isEmpty()) {
return emptyResult();
}
final Set<TraceTypeParameter.TraceType> traceTypes = traceTypeParameter.getTraceTypes();
final TraceOptions traceOptions = new TraceOptions(false, false, traceTypes.contains(VM_TRACE) || traceTypes.contains(TRACE));
return blockTracerSupplier.get().trace(block, new DebugOperationTracer(traceOptions)).map(BlockTrace::getTransactionTraces).map((traces) -> generateTracesFromTransactionTrace(traces, block, traceTypes)).orElse(null);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace in project besu by hyperledger.
the class DebugAccountAt method resultByBlockHash.
@Override
protected Object resultByBlockHash(final JsonRpcRequestContext requestContext, final Hash blockHash) {
final Integer txIndex = requestContext.getRequiredParameter(1, Integer.class);
final Address address = requestContext.getRequiredParameter(2, Address.class);
Optional<BlockWithMetadata<TransactionWithMetadata, Hash>> block = blockchainQueries.get().blockByHash(blockHash);
if (block.isEmpty()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.BLOCK_NOT_FOUND);
}
List<TransactionWithMetadata> transactions = block.get().getTransactions();
if (transactions.isEmpty() || txIndex < 0 || txIndex > block.get().getTransactions().size()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
}
final Optional<TransactionTrace> transactionTrace = blockTracerSupplier.get().trace(blockHash, new DebugOperationTracer(new TraceOptions(false, true, true))).map(BlockTrace::getTransactionTraces).orElse(Collections.emptyList()).stream().filter(trxTrace -> trxTrace.getTransaction().getHash().equals(transactions.get(txIndex).getTransaction().getHash())).findFirst();
if (transactionTrace.isEmpty()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.TRANSACTION_NOT_FOUND);
}
Optional<Account> account = transactionTrace.get().getTraceFrames().stream().map(traceFrame -> traceFrame.getWorldUpdater().get(address)).filter(Objects::nonNull).filter(a -> a.getAddress().equals(address)).findFirst();
if (account.isEmpty()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.NO_ACCOUNT_FOUND);
}
return debugAccountAtResult(account.get().getCode(), Quantity.create(account.get().getNonce()), Quantity.create(account.get().getBalance()), Quantity.create(account.get().getCodeHash()));
}
Aggregations