Coverage Summary for Class: LogsNotification (co.rsk.rpc.modules.eth.subscribe)

Class Class, % Method, % Line, %
LogsNotification 0% (0/1) 0% (0/12) 0% (0/35)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * 5  * This program is free software: you can redistribute it and/or modify 6  * it under the terms of the GNU Lesser General Public License as published by 7  * the Free Software Foundation, either version 3 of the License, or 8  * (at your option) any later version. 9  * 10  * This program is distributed in the hope that it will be useful, 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13  * GNU Lesser General Public License for more details. 14  * 15  * You should have received a copy of the GNU Lesser General Public License 16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 17  */ 18  19 package co.rsk.rpc.modules.eth.subscribe; 20  21 import com.fasterxml.jackson.annotation.JsonIgnore; 22 import com.fasterxml.jackson.annotation.JsonInclude; 23 import org.ethereum.core.Block; 24 import org.ethereum.core.Transaction; 25 import org.ethereum.vm.LogInfo; 26  27 import java.util.Collections; 28 import java.util.List; 29 import java.util.stream.Collectors; 30  31 import static org.ethereum.rpc.TypeConverter.toJsonHex; 32 import static org.ethereum.rpc.TypeConverter.toQuantityJsonHex; 33  34 /** 35  * The logs DTO for JSON serialization purposes. 36  */ 37 public class LogsNotification implements EthSubscriptionNotificationDTO { 38  39  private final LogInfo logInfo; 40  private final Block block; 41  private final Transaction transaction; 42  private final int logInfoIndex; 43  private final int transactionIndex; 44  private final boolean removed; 45  46  private String lazyLogIndex; 47  private String lazyBlockNumber; 48  private String lazyBlockHash; 49  private String lazyTransactionHash; 50  private String lazyTransactionIndex; 51  private String lazyAddress; 52  private String lazyData; 53  private List<String> lazyTopics; 54  55  public LogsNotification(LogInfo logInfo, Block b, int txIndex, Transaction tx, int logIdx, boolean r) { 56  this.logInfo = logInfo; 57  this.block = b; 58  this.transaction = tx; 59  this.logInfoIndex = logIdx; 60  this.removed = r; 61  this.transactionIndex = txIndex; 62  } 63  64  public String getLogIndex() { 65  if (lazyLogIndex == null) { 66  lazyLogIndex = toQuantityJsonHex(logInfoIndex); 67  } 68  return lazyLogIndex; 69  } 70  71  public String getBlockNumber() { 72  if (lazyBlockNumber == null) { 73  lazyBlockNumber = toQuantityJsonHex(block.getNumber()); 74  } 75  return lazyBlockNumber; 76  } 77  78  public String getBlockHash() { 79  if (lazyBlockHash == null) { 80  lazyBlockHash = block.getHashJsonString(); 81  } 82  return lazyBlockHash; 83  } 84  85  public String getTransactionHash() { 86  if (lazyTransactionHash == null) { 87  lazyTransactionHash = transaction.getHash().toJsonString(); 88  } 89  return lazyTransactionHash; 90  } 91  92  public String getTransactionIndex() { 93  if (lazyTransactionIndex == null) { 94  lazyTransactionIndex = toQuantityJsonHex(transactionIndex); 95  } 96  return lazyTransactionIndex; 97  } 98  99  public String getAddress() { 100  if (lazyAddress == null) { 101  lazyAddress = toJsonHex(logInfo.getAddress()); 102  } 103  return lazyAddress; 104  } 105  106  public String getData() { 107  if (lazyData == null) { 108  lazyData = toJsonHex(logInfo.getData()); 109  } 110  return lazyData; 111  } 112  113  public List<String> getTopics() { 114  if (lazyTopics == null) { 115  lazyTopics = logInfo.getTopics().stream() 116  .map(t -> toJsonHex(t.getData())) 117  .collect(Collectors.toList()); 118  } 119  return Collections.unmodifiableList(lazyTopics); 120  } 121  122  @JsonInclude(JsonInclude.Include.NON_EMPTY) 123  public boolean getRemoved() { 124  return removed; 125  } 126  127  @JsonIgnore 128  public LogInfo getLogInfo() { 129  return logInfo; 130  } 131 }