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 receipt message
13 : class EthereumTransactionReceipt {
14 1 : EthereumTransactionReceipt();
15 :
16 2 : EthereumTransactionReceipt.fromMap(Map result) {
17 2 : construct(result);
18 : }
19 :
20 : /// Transaction hash. Hash of the transaction.
21 : BigInteger _transactionHash;
22 :
23 2 : BigInteger get transactionHash => _transactionHash;
24 :
25 : /// Transaction index. Ihe transactions index position in the block.
26 : int _transactionIndex;
27 :
28 2 : int get transactionIndex => _transactionIndex;
29 :
30 : /// Block hash. Hash of the block this transaction was in.
31 : BigInteger _blockHash;
32 :
33 2 : BigInteger get blockHash => _blockHash;
34 :
35 : /// Block number. Block number of this transaction.
36 : int _blockNumber;
37 :
38 2 : int get blockNumber => _blockNumber;
39 :
40 : /// Cumulative gas used. The total amount of gas used when this transaction was executed in the block.
41 : int _cumulativeGasUsed;
42 :
43 1 : int get cumulativeGasUsed => _cumulativeGasUsed;
44 :
45 : /// Gas used. The amount of gas used by this transaction.
46 : int _gasUsed;
47 :
48 2 : int get gasUsed => _gasUsed;
49 :
50 : /// Contract address. The contract address created, if the transaction was a contract creation, otherwise null.
51 : BigInteger _contractAddress;
52 :
53 2 : BigInteger get contractAddress => _contractAddress;
54 :
55 : /// Logs. List of log objects, which this transaction generated.
56 : List<EthereumLog> _logs;
57 :
58 1 : List<EthereumLog> get logs => _logs;
59 :
60 : /// Logs bloom. Bloom filter for light clients to quickly retrieve related logs.
61 : BigInteger _logsBloom;
62 :
63 1 : BigInteger get logsBloom => _logsBloom;
64 :
65 : /// Root. Post-transaction stateroot (pre Byzantium)
66 : /// Null if status is present.
67 : BigInteger _root;
68 :
69 1 : BigInteger get root => _root;
70 :
71 : /// Status. Either 1 (success) or 0 (failure)
72 : /// Null if root is present
73 : int _status;
74 :
75 1 : int get status => _status;
76 :
77 : /// Construct from the supplied Map, only check for the keys we need.
78 : void construct(Map data) {
79 1 : if ((data == null) || (data[ethResultKey] == null)) {
80 : return;
81 : }
82 2 : if (data[ethResultKey].containsKey('transactionHash')) {
83 4 : _transactionHash = new BigInteger(data[ethResultKey]['transactionHash']);
84 : }
85 2 : if (data[ethResultKey].containsKey('transactionIndex')) {
86 1 : _transactionIndex =
87 3 : EthereumUtilities.hexToInt(data[ethResultKey]['transactionIndex']);
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('cumulativeGasUsed')) {
97 1 : _cumulativeGasUsed =
98 3 : EthereumUtilities.hexToInt(data[ethResultKey]['cumulativeGasUsed']);
99 : }
100 2 : if (data[ethResultKey].containsKey('gasUsed')) {
101 4 : _gasUsed = EthereumUtilities.hexToInt(data[ethResultKey]['gasUsed']);
102 : }
103 2 : if (data[ethResultKey].containsKey('contractAddress')) {
104 4 : _contractAddress = new BigInteger(data[ethResultKey]['contractAddress']);
105 : }
106 2 : if (data[ethResultKey].containsKey('logsBloom')) {
107 4 : _logsBloom = new BigInteger(data[ethResultKey]['logsBloom']);
108 : }
109 2 : if (data[ethResultKey].containsKey('root')) {
110 4 : _root = new BigInteger(data[ethResultKey]['root']);
111 : }
112 2 : if (data[ethResultKey].containsKey('status')) {
113 4 : _status = EthereumUtilities.hexToInt(data[ethResultKey]['status']);
114 : }
115 2 : if (data[ethResultKey].containsKey('logs')) {
116 2 : if ((data[ethResultKey]['logs'] != null) &&
117 3 : (data[ethResultKey]['logs'].isNotEmpty)) {
118 2 : _logs = new List<EthereumLog>();
119 4 : for (Map log in data[ethResultKey]['logs']) {
120 1 : final Map buildLog = {ethResultKey: log};
121 1 : final EthereumLog entry = new EthereumLog.fromMap(buildLog);
122 2 : _logs.add(entry);
123 : }
124 : }
125 : }
126 : }
127 :
128 : // To string
129 : String toString() {
130 2 : final String ret = "Ethereum Transaction Receipt:" +
131 2 : "\n" +
132 4 : " Transaction Hash : $transactionHash" +
133 2 : "\n" +
134 4 : " Block Number: $blockNumber" +
135 2 : "\n" +
136 4 : " Block Hash : $blockHash" +
137 2 : "\n" +
138 4 : " Transaction Index : $transactionIndex" +
139 2 : "\n" +
140 4 : " Contract Address : $contractAddress" +
141 2 : "\n" +
142 4 : " Gas used : $gasUsed" +
143 : "\n";
144 :
145 : return ret;
146 : }
147 : }
|