Coverage Summary for Class: TransactionInfo (org.ethereum.db)

Class Class, % Method, % Line, %
TransactionInfo 100% (1/1) 100% (7/7) 96.3% (26/27)


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.db; 21  22 import org.ethereum.core.Transaction; 23 import org.ethereum.core.TransactionReceipt; 24 import org.ethereum.util.RLP; 25 import org.ethereum.util.RLPElement; 26 import org.ethereum.util.RLPItem; 27 import org.ethereum.util.RLPList; 28 import org.bouncycastle.util.BigIntegers; 29  30 import java.math.BigInteger; 31 import java.util.ArrayList; 32  33 /** 34  * Created by Ruben on 8/1/2016. 35  */ 36 public class TransactionInfo { 37  38  TransactionReceipt receipt; 39  byte[] blockHash; 40  int index; 41  42  public TransactionInfo(TransactionReceipt receipt, byte[] blockHash, int index) { 43  this.receipt = receipt; 44  this.blockHash = blockHash; 45  this.index = index; 46  } 47  48  public TransactionInfo(byte[] rlp) { 49  ArrayList<RLPElement> params = RLP.decode2(rlp); 50  RLPList txInfo = (RLPList) params.get(0); 51  RLPList receiptRLP = (RLPList) txInfo.get(0); 52  RLPItem blockHashRLP = (RLPItem) txInfo.get(1); 53  RLPItem indexRLP = (RLPItem) txInfo.get(2); 54  55  receipt = new TransactionReceipt(receiptRLP.getRLPData()); 56  blockHash = blockHashRLP.getRLPData(); 57  if (indexRLP.getRLPData() == null) { 58  index = 0; 59  } else { 60  index = BigIntegers.fromUnsignedByteArray(indexRLP.getRLPData()).intValue(); 61  } 62  } 63  64  public void setTransaction(Transaction tx){ 65  receipt.setTransaction(tx); 66  } 67  68  /* [receipt, blockHash, index] */ 69  public byte[] getEncoded() { 70  71  byte[] receiptRLP = this.receipt.getEncoded(); 72  byte[] blockHashRLP = RLP.encodeElement(blockHash); 73  byte[] indexRLP = RLP.encodeInt(index); 74  75  byte[] rlpEncoded = RLP.encodeList(receiptRLP, blockHashRLP, indexRLP); 76  77  return rlpEncoded; 78  } 79  80  public TransactionReceipt getReceipt(){ 81  return receipt; 82  } 83  84  public byte[] getBlockHash() { return blockHash; } 85  86  public int getIndex() { return index; } 87 }