use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult 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.results.DebugTraceTransactionResult in project besu by hyperledger.
the class DebugTraceTransaction method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Hash hash = requestContext.getRequiredParameter(0, Hash.class);
final Optional<TransactionWithMetadata> transactionWithMetadata = blockchain.transactionByHash(hash);
if (transactionWithMetadata.isPresent()) {
final TraceOptions traceOptions = requestContext.getOptionalParameter(1, TransactionTraceParams.class).map(TransactionTraceParams::traceOptions).orElse(TraceOptions.DEFAULT);
final DebugTraceTransactionResult debugTraceTransactionResult = debugTraceTransactionResult(hash, transactionWithMetadata.get(), traceOptions);
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), debugTraceTransactionResult);
} else {
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), null);
}
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult 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.results.DebugTraceTransactionResult in project besu by hyperledger.
the class DebugTraceTransactionIntegrationTest method debugTraceTransactionSuccessTest.
@Test
public void debugTraceTransactionSuccessTest() {
final Map<String, Boolean> map = Map.of("disableStorage", true);
final Object[] params = new Object[] { Hash.fromHexString("0xcef53f2311d7c80e9086d661e69ac11a5f3d081e28e02a9ba9b66749407ac310"), map };
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", DEBUG_TRACE_TRANSACTION, params));
final JsonRpcResponse response = method.response(request);
assertThat(response.getType()).isEqualTo(JsonRpcResponseType.SUCCESS);
DebugTraceTransactionResult debugTraceTransactionResult = (DebugTraceTransactionResult) ((JsonRpcSuccessResponse) response).getResult();
assertThat(debugTraceTransactionResult.getGas()).isEqualTo(23705L);
assertThat(debugTraceTransactionResult.getReturnValue()).isEmpty();
assertThat(debugTraceTransactionResult.failed()).isFalse();
assertThat(debugTraceTransactionResult.getStructLogs()).hasSize(106);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult in project besu by hyperledger.
the class DebugTraceBlock method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final String input = requestContext.getRequiredParameter(0, String.class);
final Block block;
try {
block = Block.readFrom(RLP.input(Bytes.fromHexString(input)), this.blockHeaderFunctions);
} catch (final RLPException e) {
LOG.debug("Failed to parse block RLP", e);
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
}
final TraceOptions traceOptions = requestContext.getOptionalParameter(1, TransactionTraceParams.class).map(TransactionTraceParams::traceOptions).orElse(TraceOptions.DEFAULT);
if (this.blockchain.blockByHash(block.getHeader().getParentHash()).isPresent()) {
final Collection<DebugTraceTransactionResult> results = blockTracerSupplier.get().trace(block, new DebugOperationTracer(traceOptions)).map(BlockTrace::getTransactionTraces).map(DebugTraceTransactionResult::of).orElse(null);
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), results);
} else {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.PARENT_BLOCK_NOT_FOUND);
}
}
Aggregations