Line data Source code
1 : /*
2 : * Package : Ethereum
3 : * Author : S. Hamblett <steve.hamblett@linux.com>
4 : * Date : 08/01/2017
5 : * Copyright : S.Hamblett
6 : *
7 : * A JSON RPC 2.0 client for Ethereum
8 : */
9 :
10 : part of ethereum;
11 :
12 : /// An ethereum transaction message
13 : class EthereumTransaction {
14 1 : EthereumTransaction();
15 :
16 2 : EthereumTransaction.fromMap(Map result) {
17 2 : construct(result);
18 : }
19 :
20 : /// Hash. hash of the transaction.
21 : BigInteger _hash;
22 :
23 2 : BigInteger get hash => _hash;
24 :
25 : /// Nonce. The number of transactions made by the sender prior to this one.
26 : int _nonce;
27 :
28 1 : int get nonce => _nonce;
29 :
30 : /// Block hash. Hash of the block where this transaction was in.
31 : /// Null when the transaction is pending.
32 : BigInteger _blockHash;
33 :
34 2 : BigInteger get blockHash => _blockHash;
35 :
36 : /// Block number. Block number of this transaction.
37 : /// Null when the transaction is pending.
38 : int _blockNumber;
39 :
40 2 : int get blockNumber => _blockNumber;
41 :
42 : /// Transaction index. The transactions index position in the block.
43 : /// Null when the transaction is pending.
44 : int _transactionIndex;
45 :
46 2 : int get transactionIndex => _transactionIndex;
47 :
48 : /// From. Address of the sender.
49 : BigInteger _from;
50 :
51 2 : BigInteger get from => _from;
52 :
53 : /// To. Address of the receiver. Null when a contract creation transaction.
54 : BigInteger _to;
55 :
56 2 : BigInteger get to => _to;
57 :
58 : /// Value. Value transferred in Wei.
59 : int _value;
60 :
61 2 : int get value => _value;
62 :
63 : /// Gas price. Gas price provided by the sender in Wei.
64 : int _gasPrice;
65 :
66 1 : int get gasPrice => _gasPrice;
67 :
68 : /// Gas. Gas provided by the sender.
69 : int _gas;
70 :
71 2 : int get gas => _gas;
72 :
73 : /// Input. Data sent with the transaction.
74 : BigInteger _input;
75 :
76 1 : BigInteger get input => _input;
77 :
78 : /// Construct from the supplied Map, only check for the keys we need.
79 : void construct(Map data) {
80 1 : if ((data == null) || (data[ethResultKey] == null)) {
81 : return;
82 : }
83 2 : if (data[ethResultKey].containsKey('hash')) {
84 4 : _hash = new BigInteger(data[ethResultKey]['hash']);
85 : }
86 2 : if (data[ethResultKey].containsKey('nonce')) {
87 4 : _nonce = EthereumUtilities.hexToInt(data[ethResultKey]['nonce']);
88 : }
89 2 : if (data[ethResultKey].containsKey('blockHash')) {
90 4 : _blockHash = new BigInteger(data[ethResultKey]['blockHash']);
91 : }
92 2 : if (data[ethResultKey].containsKey('blockNumber')) {
93 1 : _blockNumber =
94 3 : EthereumUtilities.hexToInt(data[ethResultKey]['blockNumber']);
95 : }
96 2 : if (data[ethResultKey].containsKey('transactionIndex')) {
97 1 : _transactionIndex =
98 3 : EthereumUtilities.hexToInt(data[ethResultKey]['transactionIndex']);
99 : }
100 2 : if (data[ethResultKey].containsKey('from')) {
101 4 : _from = new BigInteger(data[ethResultKey]['from']);
102 : }
103 2 : if (data[ethResultKey].containsKey('to')) {
104 4 : _to = new BigInteger(data[ethResultKey]['to']);
105 : }
106 2 : if (data[ethResultKey].containsKey('value')) {
107 4 : _value = EthereumUtilities.hexToInt(data[ethResultKey]['value']);
108 : }
109 2 : if (data[ethResultKey].containsKey('gasPrice')) {
110 4 : _gasPrice = EthereumUtilities.hexToInt(data[ethResultKey]['gasPrice']);
111 : }
112 2 : if (data[ethResultKey].containsKey('gas')) {
113 4 : _gas = EthereumUtilities.hexToInt(data[ethResultKey]['gas']);
114 : }
115 2 : if (data[ethResultKey].containsKey('input')) {
116 4 : _input = new BigInteger(data[ethResultKey]['input']);
117 : }
118 : }
119 :
120 : // To string
121 : String toString() {
122 2 : final String ret = "Ethereum Transaction :" +
123 2 : "\n" +
124 4 : " Hash : $hash" +
125 2 : "\n" +
126 4 : " Block Number: $blockNumber" +
127 2 : "\n" +
128 4 : " Block Hash : $blockHash" +
129 2 : "\n" +
130 4 : " Transaction Index : $transactionIndex" +
131 2 : "\n" +
132 4 : " From : $from" +
133 2 : "\n" +
134 4 : " To : $to " +
135 2 : "\n" +
136 4 : " Value : $value" +
137 2 : "\n" +
138 4 : " Gas : $gas" +
139 : "\n";
140 :
141 : return ret;
142 : }
143 : }
|