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

Class Method, % Line, %
OpActions 6.2% (1/16) 11.8% (4/34)
OpActions$Action 0% (0/6) 0% (0/10)
OpActions$Action$Name 0% (0/1) 0% (0/9)
Total 4.3% (1/23) 7.5% (4/53)


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 com.fasterxml.jackson.annotation.JsonInclude; 23 import org.ethereum.vm.DataWord; 24  25 import java.util.ArrayList; 26 import java.util.HashMap; 27 import java.util.List; 28 import java.util.Map; 29  30 import static org.ethereum.util.ByteUtil.toHexStringOrEmpty; 31  32 public class OpActions { 33  34  @JsonInclude(JsonInclude.Include.NON_NULL) 35  public static class Action { 36  37  public enum Name { 38  POP, 39  PUSH, 40  SWAP, 41  EXTEND, 42  WRITE, 43  PUT, 44  REMOVE, 45  CLEAR; 46  } 47  48  private Name name; 49  private Map<String, Object> params; 50  51  public Name getName() { 52  return name; 53  } 54  55  public void setName(Name name) { 56  this.name = name; 57  } 58  59  public Map<String, Object> getParams() { 60  return params; 61  } 62  63  public void setParams(Map<String, Object> params) { 64  this.params = params; 65  } 66  67  Action addParam(String name, Object value) { 68  if (value != null) { 69  if (params == null) { 70  params = new HashMap<>(); 71  } 72  params.put(name, value.toString()); 73  } 74  return this; 75  } 76  } 77  78  private List<Action> stack = new ArrayList<>(); 79  private List<Action> memory = new ArrayList<>(); 80  private List<Action> storage = new ArrayList<>(); 81  82  public List<Action> getStack() { 83  return stack; 84  } 85  86  public void setStack(List<Action> stack) { 87  this.stack = stack; 88  } 89  90  public List<Action> getMemory() { 91  return memory; 92  } 93  94  public void setMemory(List<Action> memory) { 95  this.memory = memory; 96  } 97  98  public List<Action> getStorage() { 99  return storage; 100  } 101  102  public void setStorage(List<Action> storage) { 103  this.storage = storage; 104  } 105  106  private static Action addAction(List<Action> container, Action.Name name) { 107  Action action = new Action(); 108  action.setName(name); 109  110  container.add(action); 111  112  return action; 113  } 114  115  public Action addStackPop() { 116  return addAction(stack, Action.Name.POP); 117  } 118  119  public Action addStackPush(DataWord value) { 120  return addAction(stack, Action.Name.PUSH) 121  .addParam("value", value); 122  } 123  124  public Action addStackSwap(int from, int to) { 125  return addAction(stack, Action.Name.SWAP) 126  .addParam("from", from) 127  .addParam("to", to); 128  } 129  130  public Action addMemoryExtend(long delta) { 131  return addAction(memory, Action.Name.EXTEND) 132  .addParam("delta", delta); 133  } 134  135  public Action addMemoryWrite(int address, byte[] data, int size) { 136  return addAction(memory, Action.Name.WRITE) 137  .addParam("address", address) 138  .addParam("data", toHexStringOrEmpty(data).substring(0, size)); 139  } 140  141  public Action addStoragePut(DataWord key, DataWord value) { 142  return addAction(storage, Action.Name.PUT) 143  .addParam("key", key) 144  .addParam("value", value); 145  } 146  147  public Action addStorageRemove(DataWord key) { 148  return addAction(storage, Action.Name.REMOVE) 149  .addParam("key", key); 150  } 151  152  public Action addStorageClear() { 153  return addAction(storage, Action.Name.CLEAR); 154  } 155 }