Coverage Summary for Class: ProgramTraceProcessor (org.ethereum.vm.trace)

Class Class, % Method, % Line, %
ProgramTraceProcessor 0% (0/1) 0% (0/5) 0% (0/14)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package org.ethereum.vm.trace; 21  22 import co.rsk.crypto.Keccak256; 23 import com.fasterxml.jackson.annotation.JsonAutoDetect; 24 import com.fasterxml.jackson.databind.JsonNode; 25 import com.fasterxml.jackson.databind.ObjectMapper; 26 import com.fasterxml.jackson.databind.introspect.VisibilityChecker; 27  28 import java.util.HashMap; 29 import java.util.Map; 30  31 /** 32  * Provides tracing and exporting to JSON 33  */ 34 public class ProgramTraceProcessor { 35  private final Map<Keccak256, ProgramTrace> traces = new HashMap<>(); 36  37  public void processProgramTrace(ProgramTrace programTrace, Keccak256 txHash) { 38  this.traces.put(txHash, programTrace); 39  } 40  41  public ProgramTrace getProgramTrace(Keccak256 txHash) { 42  return traces.get(txHash); 43  } 44  45  public JsonNode getProgramTraceAsJsonNode(Keccak256 txHash) { 46  ProgramTrace trace = traces.get(txHash); 47  48  if (trace == null) { 49  return null; 50  } 51  52  ObjectMapper mapper = Serializers.createMapper(true); 53  mapper.setVisibility(fieldsOnlyVisibilityChecker(mapper)); 54  55  return mapper.valueToTree(trace); 56  } 57  58  private static VisibilityChecker<?> fieldsOnlyVisibilityChecker(ObjectMapper mapper) { 59  return mapper.getSerializationConfig().getDefaultVisibilityChecker() 60  .withFieldVisibility(JsonAutoDetect.Visibility.ANY) 61  .withGetterVisibility(JsonAutoDetect.Visibility.NONE) 62  .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE); 63  } 64 }