forked from ethereum/aleth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTransactionReceipt.h
124 lines (106 loc) · 3.74 KB
/
TransactionReceipt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file TransactionReceipt.h
* @author Gav Wood <[email protected]>
* @date 2014
*/
#pragma once
#include <libethcore/Common.h>
#include <libethcore/LogEntry.h>
#include <libdevcore/RLP.h>
#include <boost/variant/variant.hpp>
#include <array>
namespace dev
{
namespace eth
{
/// Transaction receipt, constructed either from RLP representation or from individual values.
/// Either a state root or a status code is contained. m_hasStatusCode is true when it contains a status code.
/// Empty state root is not included into RLP-encoding.
class TransactionReceipt
{
public:
TransactionReceipt(bytesConstRef _rlp);
TransactionReceipt(h256 const& _root, u256 const& _gasUsed, LogEntries const& _log);
TransactionReceipt(uint8_t _status, u256 const& _gasUsed, LogEntries const& _log);
/// @returns true if the receipt has a status code. Otherwise the receipt has a state root (pre-EIP658).
bool hasStatusCode() const;
/// @returns the state root.
/// @throw TransactionReceiptVersionError when the receipt has a status code instead of a state root.
h256 const& stateRoot() const;
/// @returns the status code.
/// @throw TransactionReceiptVersionError when the receipt has a state root instead of a status code.
uint8_t statusCode() const;
u256 const& cumulativeGasUsed() const { return m_gasUsed; }
LogBloom const& bloom() const { return m_bloom; }
LogEntries const& log() const { return m_log; }
void streamRLP(RLPStream& _s) const;
bytes rlp() const { RLPStream s; streamRLP(s); return s.out(); }
private:
boost::variant<uint8_t,h256> m_statusCodeOrStateRoot;
u256 m_gasUsed;
LogBloom m_bloom;
LogEntries m_log;
};
using TransactionReceipts = std::vector<TransactionReceipt>;
std::ostream& operator<<(std::ostream& _out, eth::TransactionReceipt const& _r);
class LocalisedTransactionReceipt: public TransactionReceipt
{
public:
LocalisedTransactionReceipt(
TransactionReceipt const& _t,
h256 const& _hash,
h256 const& _blockHash,
BlockNumber _blockNumber,
unsigned _transactionIndex,
u256 const& _gasUsed,
Address const& _contractAddress = Address()
):
TransactionReceipt(_t),
m_hash(_hash),
m_blockHash(_blockHash),
m_blockNumber(_blockNumber),
m_transactionIndex(_transactionIndex),
m_gasUsed(_gasUsed),
m_contractAddress(_contractAddress)
{
LogEntries entries = log();
for (unsigned i = 0; i < entries.size(); i++)
m_localisedLogs.push_back(LocalisedLogEntry(
entries[i],
m_blockHash,
m_blockNumber,
m_hash,
m_transactionIndex,
i
));
}
h256 const& hash() const { return m_hash; }
h256 const& blockHash() const { return m_blockHash; }
BlockNumber blockNumber() const { return m_blockNumber; }
unsigned transactionIndex() const { return m_transactionIndex; }
u256 const& gasUsed() const { return m_gasUsed; }
Address const& contractAddress() const { return m_contractAddress; }
LocalisedLogEntries const& localisedLogs() const { return m_localisedLogs; };
private:
h256 m_hash;
h256 m_blockHash;
BlockNumber m_blockNumber;
unsigned m_transactionIndex = 0;
u256 m_gasUsed;
Address m_contractAddress;
LocalisedLogEntries m_localisedLogs;
};
}
}