Coverage Summary for Class: TransactionReceiptDTO (org.ethereum.rpc.dto)

Class Class, % Method, % Line, %
TransactionReceiptDTO 100% (1/1) 46.2% (6/13) 66.7% (22/33)


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 org.ethereum.rpc.dto; 20  21 import co.rsk.core.RskAddress; 22 import org.ethereum.core.Block; 23 import org.ethereum.core.TransactionReceipt; 24 import org.ethereum.db.TransactionInfo; 25 import org.ethereum.rpc.LogFilterElement; 26 import org.ethereum.vm.LogInfo; 27  28 import static org.ethereum.rpc.TypeConverter.*; 29  30 /** 31  * Created by Ruben on 5/1/2016. 32  */ 33 public class TransactionReceiptDTO { 34  private String transactionHash; // hash of the transaction. 35  private String transactionIndex; // integer of the transactions index position in the block. 36  private String blockHash; // hash of the block where this transaction was in. 37  private String blockNumber; // block number where this transaction was in. 38  private String cumulativeGasUsed; // The total amount of gas used when this transaction was executed in the block. 39  private String gasUsed; // The amount of gas used by this specific transaction alone. 40  private String contractAddress; // The contract address created, if the transaction was a contract creation, otherwise null . 41  private LogFilterElement[] logs; // Array of log objects, which this transaction generated. 42  private String from; // address of the sender. 43  private String to; // address of the receiver. null when it's a contract creation transaction. 44  private String status; // either 1 (success) or 0 (failure) 45  private String logsBloom; // Bloom filter for light clients to quickly retrieve related logs. 46  47  public TransactionReceiptDTO(Block block, TransactionInfo txInfo) { 48  TransactionReceipt receipt = txInfo.getReceipt(); 49  50  status = toQuantityJsonHex(txInfo.getReceipt().getStatus()); 51  blockHash = toUnformattedJsonHex(txInfo.getBlockHash()); 52  blockNumber = toQuantityJsonHex(block.getNumber()); 53  54  RskAddress contractAddress = receipt.getTransaction().getContractAddress(); 55  if (contractAddress != null) { 56  this.contractAddress = contractAddress.toJsonString(); 57  } 58  59  cumulativeGasUsed = toQuantityJsonHex(receipt.getCumulativeGas()); 60  from = receipt.getTransaction().getSender().toJsonString(); 61  gasUsed = toQuantityJsonHex(receipt.getGasUsed()); 62  63  logs = new LogFilterElement[receipt.getLogInfoList().size()]; 64  for (int i = 0; i < logs.length; i++) { 65  LogInfo logInfo = receipt.getLogInfoList().get(i); 66  logs[i] = new LogFilterElement(logInfo, block, txInfo.getIndex(), 67  txInfo.getReceipt().getTransaction(), i); 68  } 69  70  to = receipt.getTransaction().getReceiveAddress().toJsonString(); 71  transactionHash = receipt.getTransaction().getHash().toJsonString(); 72  transactionIndex = toQuantityJsonHex(txInfo.getIndex()); 73  logsBloom = toUnformattedJsonHex(txInfo.getReceipt().getBloomFilter().getData()); 74  } 75  76  public String getTransactionHash() { 77  return transactionHash; 78  } 79  80  public String getTransactionIndex() { 81  return transactionIndex; 82  } 83  84  public String getBlockHash() { 85  return blockHash; 86  } 87  88  public String getBlockNumber() { 89  return blockNumber; 90  } 91  92  public String getCumulativeGasUsed() { 93  return cumulativeGasUsed; 94  } 95  96  public String getGasUsed() { 97  return gasUsed; 98  } 99  100  public String getContractAddress() { 101  return contractAddress; 102  } 103  104  public LogFilterElement[] getLogs() { 105  return logs.clone(); 106  } 107  108  public String getFrom() { 109  return from; 110  } 111  112  public String getTo() { 113  return to; 114  } 115  116  public String getStatus() { 117  return status; 118  } 119  120  public String getLogsBloom() { 121  return logsBloom; 122  } 123 }