Coverage Summary for Class: TransactionResultDTO (org.ethereum.rpc.dto)
Class |
Class, %
|
Method, %
|
Line, %
|
TransactionResultDTO |
100%
(1/1)
|
100%
(1/1)
|
100%
(20/20)
|
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.Coin;
22 import co.rsk.remasc.RemascTransaction;
23 import org.ethereum.core.Block;
24 import org.ethereum.core.Transaction;
25 import org.ethereum.crypto.signature.ECDSASignature;
26 import org.ethereum.rpc.TypeConverter;
27
28 /**
29 * Created by Ruben on 8/1/2016.
30 */
31 public class TransactionResultDTO {
32
33 public String hash;
34 public String nonce;
35 public String blockHash;
36 public String blockNumber;
37 public String transactionIndex;
38
39 public String from;
40 public String to;
41 public String gas;
42 public String gasPrice;
43 public String value;
44 public String input;
45
46 public String v;
47 public String r;
48 public String s;
49
50 public TransactionResultDTO(Block b, Integer index, Transaction tx) {
51 hash = tx.getHash().toJsonString();
52
53 nonce = TypeConverter.toQuantityJsonHex(tx.getNonce());
54
55 blockHash = b != null ? b.getHashJsonString() : null;
56 blockNumber = b != null ? TypeConverter.toQuantityJsonHex(b.getNumber()) : null;
57 transactionIndex = index != null ? TypeConverter.toQuantityJsonHex(index) : null;
58
59 from = tx.getSender().toJsonString();
60 to = tx.getReceiveAddress().toJsonString();
61 gas = TypeConverter.toQuantityJsonHex(tx.getGasLimit());
62
63 gasPrice = TypeConverter.toQuantityJsonHex(tx.getGasPrice().getBytes());
64
65 if (Coin.ZERO.equals(tx.getValue())) {
66 value = "0x0";
67 } else {
68 value = TypeConverter.toQuantityJsonHex(tx.getValue().getBytes());
69 }
70
71 input = TypeConverter.toUnformattedJsonHex(tx.getData());
72
73 if (!(tx instanceof RemascTransaction)) {
74 ECDSASignature signature = tx.getSignature();
75
76 v = String.format("0x%02x", tx.getEncodedV());
77
78 r = TypeConverter.toQuantityJsonHex(signature.getR());
79 s = TypeConverter.toQuantityJsonHex(signature.getS());
80 }
81 }
82 }