@ -101,57 +101,57 @@ public class TraceReplayBlockTransactions extends AbstractBlockParameterMethod {
return blockTracer
return blockTracer
. trace ( block , new DebugOperationTracer ( traceOptions ) )
. trace ( block , new DebugOperationTracer ( traceOptions ) )
. map ( BlockTrace : : getTransactionTraces )
. map ( BlockTrace : : getTransactionTraces )
. map ( ( traces ) - > formatTraces ( traces , traceTypeParameter ) )
. map ( ( traces ) - > generateTracesFromTransactionTrace ( traces , traceTypeParameter ) )
. orElse ( null ) ;
. orElse ( null ) ;
}
}
private JsonNode formatTraces (
private JsonNode generateTracesFromTransactionTrace (
final List < TransactionTrace > traces , final TraceTypeParameter traceTypeParameter ) {
final List < TransactionTrace > transactionTra ces , final TraceTypeParameter traceTypeParameter ) {
final Set < TraceTypeParameter . TraceType > traceTypes = traceTypeParameter . getTraceTypes ( ) ;
final Set < TraceTypeParameter . TraceType > traceTypes = traceTypeParameter . getTraceTypes ( ) ;
final ObjectMapper mapper = new ObjectMapper ( ) ;
final ObjectMapper mapper = new ObjectMapper ( ) ;
final ArrayNode resultArrayNode = mapper . createArrayNode ( ) ;
final ArrayNode resultArrayNode = mapper . createArrayNode ( ) ;
final ObjectNode resultNode = mapper . createObjectNode ( ) ;
final AtomicInteger traceCounter = new AtomicInteger ( 0 ) ;
final AtomicInteger traceCounter = new AtomicInteger ( 0 ) ;
traces . stream ( )
transactionTraces . forEach (
. findFirst ( )
transactionTrace - >
. ifPresent (
handleTransactionTrace (
transactionTrace - > {
transactionTrace , traceTypes , mapper , resultArrayNode , traceCounter ) ) ;
resultNode . put (
return resultArrayNode ;
"transactionHash" , transactionTrace . getTransaction ( ) . getHash ( ) . toHexString ( ) ) ;
}
resultNode . put ( "output" , transactionTrace . getResult ( ) . getOutput ( ) . toString ( ) ) ;
} ) ;
private void handleTransactionTrace (
final TransactionTrace transactionTrace ,
final Set < TraceTypeParameter . TraceType > traceTypes ,
final ObjectMapper mapper ,
final ArrayNode resultArrayNode ,
final AtomicInteger traceCounter ) {
final ObjectNode resultNode = mapper . createObjectNode ( ) ;
resultNode . put ( "transactionHash" , transactionTrace . getTransaction ( ) . getHash ( ) . toHexString ( ) ) ;
resultNode . put ( "output" , transactionTrace . getResult ( ) . getOutput ( ) . toString ( ) ) ;
setEmptyArrayIfNotPresent ( resultNode , "trace" ) ;
setNullNodesIfNotPresent ( resultNode , "vmTrace" , "stateDiff" ) ;
if ( traceTypes . contains ( TraceTypeParameter . TraceType . TRACE ) ) {
if ( traceTypes . contains ( TraceTypeParameter . TraceType . TRACE ) ) {
formatTraces (
generateTracesFromTransactionTrace (
resultNode . putArray ( "trace" ) : : addPOJO ,
resultNode . putArray ( "trace" ) : : addPOJO ,
traces ,
transactionTra ce ,
FlatTraceGenerator : : generateFromTransactionTrace ,
FlatTraceGenerator : : generateFromTransactionTrace ,
traceCounter ) ;
traceCounter ) ;
}
}
if ( traceTypes . contains ( TraceTypeParameter . TraceType . VM_TRACE ) ) {
if ( traceTypes . contains ( TraceTypeParameter . TraceType . VM_TRACE ) ) {
formatTraces (
generateTracesFromTransactionTrace (
trace - > resultNode . putPOJO ( "vmTrace" , trace ) ,
trace - > resultNode . putPOJO ( "vmTrace" , trace ) ,
traces ,
transactionTrace ,
( transactionTrace , ignored ) - >
( __ , ignored ) - > new VmTraceGenerator ( transactionTrace ) . generateTraceStream ( ) ,
new VmTraceGenerator ( transactionTrace ) . generateTraceStream ( ) ,
traceCounter ) ;
traceCounter ) ;
}
}
setEmptyArrayIfNotPresent ( resultNode , "trace" ) ;
setNullNodesIfNotPresent ( resultNode , "vmTrace" , "stateDiff" ) ;
resultArrayNode . add ( resultNode ) ;
resultArrayNode . add ( resultNode ) ;
return resultArrayNode ;
}
}
private void formatTraces (
private void generateTracesFromTransactionTrace (
final TraceWriter writer ,
final TraceWriter writer ,
final List < TransactionTrace > traces ,
final TransactionTrace transactionTrace ,
final TraceFormatter formatter ,
final TraceFormatter formatter ,
final AtomicInteger traceCounter ) {
final AtomicInteger traceCounter ) {
traces . forEach (
formatter . format ( transactionTrace , traceCounter ) . forEachOrdered ( writer : : write ) ;
( transactionTrace ) - >
formatter . format ( transactionTrace , traceCounter ) . forEachOrdered ( writer : : write ) ) ;
}
}
private void setNullNodesIfNotPresent ( final ObjectNode parentNode , final String . . . keys ) {
private void setNullNodesIfNotPresent ( final ObjectNode parentNode , final String . . . keys ) {