TransactionReceipt.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. This file is part of cpp-ethereum.
  3. cpp-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. cpp-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** @file TransactionReceipt.cpp
  15. * @author Gav Wood <i@gavwood.com>
  16. * @date 2014
  17. */
  18. #include "TransactionReceipt.h"
  19. using namespace std;
  20. using namespace dev;
  21. using namespace dev::eth;
  22. TransactionReceipt::TransactionReceipt(bytesConstRef _rlp)
  23. {
  24. RLP r(_rlp);
  25. m_stateRoot = (h256)r[0];
  26. m_gasUsed = (u256)r[1];
  27. m_bloom = (LogBloom)r[2];
  28. for (auto const& i: r[3])
  29. m_log.emplace_back(i);
  30. }
  31. TransactionReceipt::TransactionReceipt(h256 _root, u256 _gasUsed, LogEntries const& _log):
  32. m_stateRoot(_root),
  33. m_gasUsed(_gasUsed),
  34. m_bloom(eth::bloom(_log)),
  35. m_log(_log)
  36. {}
  37. void TransactionReceipt::streamRLP(RLPStream& _s) const
  38. {
  39. _s.appendList(4) << m_stateRoot << m_gasUsed << m_bloom;
  40. _s.appendList(m_log.size());
  41. for (LogEntry const& l: m_log)
  42. l.streamRLP(_s);
  43. }
  44. std::ostream& dev::eth::operator<<(std::ostream& _out, TransactionReceipt const& _r)
  45. {
  46. _out << "Root: " << _r.stateRoot() << std::endl;
  47. _out << "Gas used: " << _r.gasUsed() << std::endl;
  48. _out << "Logs: " << _r.log().size() << " entries:" << std::endl;
  49. for (LogEntry const& i: _r.log())
  50. {
  51. _out << "Address " << i.address << ". Topics:" << std::endl;
  52. for (auto const& j: i.topics)
  53. _out << " " << j << std::endl;
  54. _out << " Data: " << toHex(i.data) << std::endl;
  55. }
  56. _out << "Bloom: " << _r.bloom() << std::endl;
  57. return _out;
  58. }