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

Class Class, % Method, % Line, %
SummarizedProgramTrace 0% (0/1) 0% (0/16) 0% (0/26)


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.rpc.modules.trace.ProgramSubtrace; 23 import org.ethereum.vm.program.Memory; 24 import org.ethereum.vm.program.Stack; 25 import org.ethereum.vm.program.Storage; 26 import org.ethereum.vm.program.invoke.InvokeData; 27 import org.ethereum.vm.program.invoke.ProgramInvoke; 28 import org.ethereum.vm.program.invoke.TransferInvoke; 29  30 import java.util.ArrayList; 31 import java.util.Collections; 32 import java.util.List; 33  34 import static java.lang.String.format; 35 import static org.ethereum.util.ByteUtil.toHexStringOrEmpty; 36  37 public class SummarizedProgramTrace implements ProgramTrace { 38  private final ProgramInvoke programInvoke; 39  private final TransferInvoke transferInvoke; 40  private final List<ProgramSubtrace> subtraces = new ArrayList<>(); 41  42  private String result; 43  private String error; 44  private boolean reverted; 45  46  public SummarizedProgramTrace(ProgramInvoke programInvoke) { 47  this.programInvoke = programInvoke; 48  this.transferInvoke = null; 49  } 50  51  // TODO refactor to have two implementations 52  // one for program invocations 53  // another for simple transfers 54  public SummarizedProgramTrace(TransferInvoke transferInvoke) { 55  this.programInvoke = null; 56  this.transferInvoke = transferInvoke; 57  } 58  59  @Override 60  public ProgramInvoke getProgramInvoke() { 61  return this.programInvoke; 62  } 63  64  public InvokeData getInvokeData() { 65  if (this.programInvoke != null) { 66  return this.programInvoke; 67  } else { 68  return this.transferInvoke; 69  } 70  } 71  72  @Override 73  public void saveGasCost(long gasCost) { 74  75  } 76  77  @Override 78  public Op addOp(byte code, int pc, int deep, long gas, Memory memory, Stack stack, Storage storage) { 79  return null; 80  } 81  82  @Override 83  public void addSubTrace(ProgramSubtrace programSubTrace) { 84  this.subtraces.add(programSubTrace); 85  } 86  87  @Override 88  public List<ProgramSubtrace> getSubtraces() { 89  return Collections.unmodifiableList(this.subtraces); 90  } 91  92  @Override 93  public void merge(ProgramTrace programTrace) { 94  95  } 96  97  @Override 98  public ProgramTrace result(byte[] result) { 99  setResult(toHexStringOrEmpty(result)); 100  return this; 101  } 102  103  @Override 104  public ProgramTrace revert(boolean reverted) { 105  this.reverted = reverted; 106  return this; 107  } 108  109  public boolean getReverted() { return this.reverted; } 110  111  public void setResult(String result) { 112  this.result = result; 113  } 114  115  public String getResult() { 116  return result; 117  } 118  119  @Override 120  public ProgramTrace error(Exception error) { 121  setError(error == null ? "" : format("%s: %s", error.getClass(), error.getMessage())); 122  return this; 123  } 124  125  public void setError(String error) { 126  this.error = error; 127  } 128  129  public String getError() { 130  return error; 131  } 132  133  @Override 134  public boolean isEmpty() { 135  return false; 136  } 137 }