Coverage Summary for Class: LogInfo (org.ethereum.vm)

Class Class, % Method, % Line, %
LogInfo 0% (0/1) 0% (0/11) 0% (0/58)


1 package org.ethereum.vm; 2 /* 3  * This file is part of RskJ 4  * Copyright (C) 2017 RSK Labs Ltd. 5  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 6  * 7  * This program is free software: you can redistribute it and/or modify 8  * it under the terms of the GNU Lesser General Public License as published by 9  * the Free Software Foundation, either version 3 of the License, or 10  * (at your option) any later version. 11  * 12  * This program is distributed in the hope that it will be useful, 13  * but WITHOUT ANY WARRANTY; without even the implied warranty of 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15  * GNU Lesser General Public License for more details. 16  * 17  * You should have received a copy of the GNU Lesser General Public License 18  * along with this program. If not, see <http://www.gnu.org/licenses/>. 19  */ 20  21  22 import org.ethereum.core.Bloom; 23 import org.ethereum.crypto.HashUtil; 24 import org.ethereum.util.*; 25  26 import java.util.ArrayList; 27 import java.util.Arrays; 28 import java.util.List; 29 import java.util.stream.Collectors; 30  31 /** 32  * @author Roman Mandeleil 33  * @since 19.11.2014 34  */ 35 public class LogInfo { 36  37  byte[] address = new byte[]{}; 38  List<DataWord> topics = new ArrayList<>(); 39  byte[] data = new byte[]{}; 40  private boolean rejected = false; 41  42  /* Log info in encoded form */ 43  private byte[] rlpEncoded; 44  45  public LogInfo(byte[] rlp) { 46  47  ArrayList<RLPElement> params = RLP.decode2(rlp); 48  RLPList logInfo = (RLPList) params.get(0); 49  50  RLPItem address = (RLPItem) logInfo.get(0); 51  RLPList topics = (RLPList) logInfo.get(1); 52  RLPItem data = (RLPItem) logInfo.get(2); 53  54  this.address = address.getRLPData() != null ? address.getRLPData() : new byte[]{}; 55  this.data = data.getRLPData() != null ? data.getRLPData() : new byte[]{}; 56  57  for (int k = 0; k < topics.size(); k++) { 58  RLPElement topic1 = topics.get(k); 59  byte[] topic = topic1.getRLPData(); 60  this.topics.add(DataWord.valueOf(topic)); 61  } 62  63  rlpEncoded = rlp; 64  } 65  66  public LogInfo(byte[] address, List<DataWord> topics, byte[] data) { 67  this.address = (address != null) ? address : new byte[]{}; 68  this.topics = (topics != null) ? topics : new ArrayList<DataWord>(); 69  this.data = (data != null) ? data : new byte[]{}; 70  } 71  72  public byte[] getAddress() { 73  return address; 74  } 75  76  public List<DataWord> getTopics() { 77  return topics; 78  } 79  80  public byte[] getData() { 81  return data; 82  } 83  84  /* [address, [topic, topic ...] data] */ 85  public byte[] getEncoded() { 86  87  byte[] addressEncoded = RLP.encodeElement(this.address); 88  89  byte[][] topicsEncoded = null; 90  if (topics != null) { 91  topicsEncoded = new byte[topics.size()][]; 92  int i = 0; 93  for (DataWord topic : topics) { 94  byte[] topicData = topic.getData(); 95  topicsEncoded[i] = RLP.encodeElement(topicData); 96  ++i; 97  } 98  } 99  100  byte[] dataEncoded = RLP.encodeElement(data); 101  return RLP.encodeList(addressEncoded, RLP.encodeList(topicsEncoded), dataEncoded); 102  } 103  104  public Bloom getBloom() { 105  Bloom ret = Bloom.create(HashUtil.keccak256(address)); 106  for (DataWord topic : topics) { 107  byte[] topicData = topic.getData(); 108  ret.or(Bloom.create(HashUtil.keccak256(topicData))); 109  } 110  return ret; 111  } 112  113  public boolean isRejected() { 114  return rejected; 115  } 116  117  public void reject() { 118  this.rejected = true; 119  } 120  121  public static List<DataWord> byteArrayToList(byte[][] data) { 122  return Arrays.stream(data).map(DataWord::valueOf).collect(Collectors.toList()); 123  } 124  125  @Override 126  public String toString() { 127  128  StringBuilder topicsStr = new StringBuilder(); 129  topicsStr.append("["); 130  131  for (DataWord topic : topics) { 132  String topicStr = ByteUtil.toHexString(topic.getData()); 133  topicsStr.append(topicStr).append(" "); 134  } 135  topicsStr.append("]"); 136  137  138  return "LogInfo{" + 139  "address=" + ByteUtil.toHexString(address) + 140  ", topics=" + topicsStr + 141  ", data=" + ByteUtil.toHexString(data) + 142  '}'; 143  } 144  145  146 }