This repository was archived by the owner on Oct 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathTransactionReceipt.cpp
More file actions
119 lines (101 loc) · 3.2 KB
/
TransactionReceipt.cpp
File metadata and controls
119 lines (101 loc) · 3.2 KB
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
/*
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.cpp
* @author Gav Wood <i@gavwood.com>
* @date 2014
*/
#include "TransactionReceipt.h"
#include <libethcore/Exceptions.h>
#include <boost/variant/get.hpp>
using namespace std;
using namespace dev;
using namespace dev::eth;
TransactionReceipt::TransactionReceipt(bytesConstRef _rlp)
{
RLP r(_rlp);
if (!r.isList() || r.itemCount() != 4)
BOOST_THROW_EXCEPTION(InvalidTransactionReceiptFormat());
if (!r[0].isData())
BOOST_THROW_EXCEPTION(InvalidTransactionReceiptFormat());
if (r[0].size() == 32)
m_statusCodeOrStateRoot = (h256)r[0];
else if (r[0].isInt())
m_statusCodeOrStateRoot = (uint8_t)r[0];
else
BOOST_THROW_EXCEPTION(InvalidTransactionReceiptFormat());
m_gasUsed = (u256)r[1];
m_bloom = (LogBloom)r[2];
for (auto const& i : r[3])
m_log.emplace_back(i);
}
TransactionReceipt::TransactionReceipt(h256 const& _root, u256 const& _gasUsed, LogEntries const& _log):
m_statusCodeOrStateRoot(_root),
m_gasUsed(_gasUsed),
m_bloom(eth::bloom(_log)),
m_log(_log)
{}
TransactionReceipt::TransactionReceipt(uint8_t _status, u256 const& _gasUsed, LogEntries const& _log):
m_statusCodeOrStateRoot(_status),
m_gasUsed(_gasUsed),
m_bloom(eth::bloom(_log)),
m_log(_log)
{}
void TransactionReceipt::streamRLP(RLPStream& _s) const
{
_s.appendList(4);
if (hasStatusCode())
_s << statusCode();
else
_s << stateRoot();
_s << m_gasUsed << m_bloom;
_s.appendList(m_log.size());
for (LogEntry const& l: m_log)
l.streamRLP(_s);
}
bool TransactionReceipt::hasStatusCode() const
{
return m_statusCodeOrStateRoot.which() == 0;
}
uint8_t TransactionReceipt::statusCode() const
{
if (hasStatusCode())
return boost::get<uint8_t>(m_statusCodeOrStateRoot);
else
BOOST_THROW_EXCEPTION(TransactionReceiptVersionError());
}
h256 const& TransactionReceipt::stateRoot() const
{
if (hasStatusCode())
BOOST_THROW_EXCEPTION(TransactionReceiptVersionError());
else
return boost::get<h256>(m_statusCodeOrStateRoot);
}
std::ostream& dev::eth::operator<<(std::ostream& _out, TransactionReceipt const& _r)
{
if (_r.hasStatusCode())
_out << "Status: " << _r.statusCode() << std::endl;
else
_out << "Root: " << _r.stateRoot() << std::endl;
_out << "Gas used: " << _r.gasUsed() << std::endl;
_out << "Logs: " << _r.log().size() << " entries:" << std::endl;
for (LogEntry const& i: _r.log())
{
_out << "Address " << i.address << ". Topics:" << std::endl;
for (auto const& j: i.topics)
_out << " " << j << std::endl;
_out << " Data: " << toHex(i.data) << std::endl;
}
_out << "Bloom: " << _r.bloom() << std::endl;
return _out;
}