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

Class Class, % Method, % Line, %
ProgramTraceListener 100% (1/1) 11.1% (1/9) 13.3% (4/30)


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.config.VmConfig; 23 import org.ethereum.vm.DataWord; 24 import org.ethereum.vm.program.listener.ProgramListenerAdaptor; 25  26 public class ProgramTraceListener extends ProgramListenerAdaptor { 27  28  private final boolean enabled; 29  private OpActions actions = new OpActions(); 30  31  public ProgramTraceListener(VmConfig config) { 32  enabled = config.vmTrace(); 33  } 34  35  @Override 36  public void onMemoryExtend(int delta) { 37  if (enabled) { 38  actions.addMemoryExtend(delta); 39  } 40  } 41  42  @Override 43  public void onMemoryWrite(int address, byte[] data, int size) { 44  if (enabled) { 45  actions.addMemoryWrite(address, data, size); 46  } 47  } 48  49  @Override 50  public void onStackPop() { 51  if (enabled) { 52  actions.addStackPop(); 53  } 54  } 55  56  @Override 57  public void onStackPush(DataWord value) { 58  if (enabled) { 59  actions.addStackPush(value); 60  } 61  } 62  63  @Override 64  public void onStackSwap(int from, int to) { 65  if (enabled) { 66  actions.addStackSwap(from, to); 67  } 68  } 69  70  @Override 71  public void onStoragePut(DataWord key, DataWord value) { 72  if (enabled) { 73  if (value.equals(DataWord.ZERO)) { 74  actions.addStorageRemove(key); 75  } else { 76  actions.addStoragePut(key, value); 77  } 78  } 79  } 80  81  @Override 82  public void onStorageClear() { 83  if (enabled) { 84  actions.addStorageClear(); 85  } 86  } 87  88  public OpActions resetActions() { 89  OpActions actions = this.actions; 90  this.actions = new OpActions(); 91  return actions; 92  } 93 }