Coverage Summary for Class: InternalTransaction (org.ethereum.vm.program)
Class |
Class, %
|
Method, %
|
Line, %
|
InternalTransaction |
0%
(0/1)
|
0%
(0/14)
|
0%
(0/39)
|
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.program;
21
22 import org.ethereum.core.Transaction;
23 import org.ethereum.crypto.ECKey;
24 import org.ethereum.util.ByteUtil;
25 import org.ethereum.util.RLP;
26 import org.ethereum.vm.DataWord;
27
28 import static co.rsk.util.ListArrayUtil.*;
29
30 public class InternalTransaction extends Transaction {
31
32 private final byte[] originHash;
33 private final byte[] parentHash;
34 private final int deep;
35 private final int index;
36 private final String note;
37 private boolean rejected = false;
38
39 public InternalTransaction(byte[] originHash, byte[] parentHash, int deep, int index, byte[] nonce, DataWord gasPrice, DataWord gasLimit,
40 byte[] sendAddress, byte[] receiveAddress, byte[] value, byte[] data, String note) {
41
42 super(nonce, getData(gasPrice), getData(gasLimit), receiveAddress, nullToEmpty(value), nullToEmpty(data));
43
44 this.originHash = originHash.clone();
45 this.parentHash = parentHash;
46 this.deep = deep;
47 this.index = index;
48 this.sender = RLP.parseRskAddress(sendAddress);
49 this.note = note;
50 }
51
52 public InternalTransaction(byte[] parentHash, int deep, int index, byte[] nonce, DataWord gasPrice, DataWord gasLimit,
53 byte[] sendAddress, byte[] receiveAddress, byte[] value, byte[] data, String note) {
54 this(parentHash, parentHash, deep, index, nonce, gasPrice, gasLimit, sendAddress, receiveAddress, value, data, note);
55 }
56
57 private static byte[] getData(DataWord gasPrice) {
58 return (gasPrice == null) ? ByteUtil.EMPTY_BYTE_ARRAY : gasPrice.getData();
59 }
60
61 public void reject() {
62 this.rejected = true;
63 }
64
65 public int getDeep() {
66 return deep;
67 }
68
69 public int getIndex() {
70 return index;
71 }
72
73 public boolean isRejected() {
74 return rejected;
75 }
76
77 public String getNote() {
78 return note;
79 }
80
81 public byte[] getParentHash() {
82 return parentHash.clone();
83 }
84
85 public byte[] getOriginHash() {
86 return originHash.clone();
87 }
88
89 @Override
90 public byte[] getEncoded() {
91 byte[] nonce = getNonce();
92 if (isEmpty(nonce) || getLength(nonce) == 1 && nonce[0] == 0) {
93 nonce = RLP.encodeElement((byte[]) null);
94 } else {
95 nonce = RLP.encodeElement(nonce);
96 }
97 byte[] senderAddress = RLP.encodeElement(getSender().getBytes());
98 byte[] receiveAddress = RLP.encodeElement(getReceiveAddress().getBytes());
99 byte[] value = RLP.encodeCoin(getValue());
100 byte[] gasPrice = RLP.encodeCoin(getGasPrice());
101 byte[] gasLimit = RLP.encodeElement(getGasLimit());
102 byte[] data = RLP.encodeElement(getData());
103 byte[] parentHash = RLP.encodeElement(this.parentHash);
104 byte[] type = RLP.encodeString(this.note);
105 byte[] deep = RLP.encodeInt(this.deep);
106 byte[] index = RLP.encodeInt(this.index);
107 byte[] rejected = RLP.encodeInt(this.rejected ? 1 : 0);
108
109 return RLP.encodeList(nonce, parentHash, senderAddress, receiveAddress, value,
110 gasPrice, gasLimit, data, type, deep, index, rejected);
111 }
112
113 @Override
114 public byte[] getEncodedRaw() {
115 return getEncoded();
116 }
117
118 @Override
119 public ECKey getKey() {
120 throw new UnsupportedOperationException("Cannot sign internal transaction.");
121 }
122
123 @Override
124 public void sign(byte[] privKeyBytes) throws ECKey.MissingPrivateKeyException {
125 throw new UnsupportedOperationException("Cannot sign internal transaction.");
126 }
127 }