use of org.ethereum.vm.trace.SummarizedProgramTrace in project rskj by rsksmart.
the class TraceModuleImpl method traceTransaction.
@Override
public JsonNode traceTransaction(String transactionHash) throws Exception {
logger.trace("trace_transaction({})", transactionHash);
byte[] hash = stringHexToByteArray(transactionHash);
TransactionInfo txInfo = this.receiptStore.getInMainChain(hash, this.blockStore).orElse(null);
if (txInfo == null) {
logger.trace("No transaction info for {}", transactionHash);
return null;
}
Block block = this.blockchain.getBlockByHash(txInfo.getBlockHash());
Block parent = this.blockchain.getBlockByHash(block.getParentHash().getBytes());
Transaction tx = block.getTransactionsList().get(txInfo.getIndex());
txInfo.setTransaction(tx);
ProgramTraceProcessor programTraceProcessor = new ProgramTraceProcessor();
this.blockExecutor.traceBlock(programTraceProcessor, VmConfig.LIGHT_TRACE, block, parent.getHeader(), false, false);
SummarizedProgramTrace programTrace = (SummarizedProgramTrace) programTraceProcessor.getProgramTrace(tx.getHash());
if (programTrace == null) {
return null;
}
List<TransactionTrace> traces = TraceTransformer.toTraces(programTrace, txInfo, block.getNumber());
return OBJECT_MAPPER.valueToTree(traces);
}
use of org.ethereum.vm.trace.SummarizedProgramTrace in project rskj by rsksmart.
the class TransactionExecutor method extractTrace.
/**
* This extracts the trace to an object in memory.
* Refer to {@link org.ethereum.vm.VMUtils#saveProgramTraceFile} for a way to saving the trace to a file.
*/
public void extractTrace(ProgramTraceProcessor programTraceProcessor) {
if (program != null) {
// TODO improve this settings; the trace should already have the values
ProgramTrace trace = program.getTrace().result(result.getHReturn()).error(result.getException()).revert(result.isRevert());
programTraceProcessor.processProgramTrace(trace, tx.getHash());
} else {
TransferInvoke invoke = new TransferInvoke(DataWord.valueOf(tx.getSender().getBytes()), DataWord.valueOf(tx.getReceiveAddress().getBytes()), 0L, DataWord.valueOf(tx.getValue().getBytes()));
SummarizedProgramTrace trace = new SummarizedProgramTrace(invoke);
if (this.subtraces != null) {
for (ProgramSubtrace subtrace : this.subtraces) {
trace.addSubTrace(subtrace);
}
}
programTraceProcessor.processProgramTrace(trace, tx.getHash());
}
}
use of org.ethereum.vm.trace.SummarizedProgramTrace in project rskj by rsksmart.
the class TraceModuleImpl method traceBlock.
@Override
public JsonNode traceBlock(String blockArgument) throws Exception {
logger.trace("trace_block({})", blockArgument);
Block block = this.getByJsonArgument(blockArgument);
if (block == null) {
logger.trace("No block for {}", blockArgument);
return null;
}
Block parent = this.blockchain.getBlockByHash(block.getParentHash().getBytes());
List<TransactionTrace> blockTraces = new ArrayList<>();
if (block.getNumber() != 0) {
ProgramTraceProcessor programTraceProcessor = new ProgramTraceProcessor();
this.blockExecutor.traceBlock(programTraceProcessor, VmConfig.LIGHT_TRACE, block, parent.getHeader(), false, false);
for (Transaction tx : block.getTransactionsList()) {
TransactionInfo txInfo = receiptStore.getInMainChain(tx.getHash().getBytes(), this.blockStore).orElse(null);
Objects.requireNonNull(txInfo);
txInfo.setTransaction(tx);
SummarizedProgramTrace programTrace = (SummarizedProgramTrace) programTraceProcessor.getProgramTrace(tx.getHash());
if (programTrace == null) {
return null;
}
List<TransactionTrace> traces = TraceTransformer.toTraces(programTrace, txInfo, block.getNumber());
blockTraces.addAll(traces);
}
}
return OBJECT_MAPPER.valueToTree(blockTraces);
}
Aggregations