Transaction.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 Transaction.cpp
  15. * @author Gav Wood <i@gavwood.com>
  16. * @date 2014
  17. */
  18. #include <libdevcore/vector_ref.h>
  19. #include <libdevcore/Log.h>
  20. #include <libdevcore/CommonIO.h>
  21. #include <libdevcrypto/Common.h>
  22. #include <libethcore/Exceptions.h>
  23. #include <libevm/VMFace.h>
  24. #include "Interface.h"
  25. #include "Transaction.h"
  26. using namespace std;
  27. using namespace dev;
  28. using namespace dev::eth;
  29. #define ETH_ADDRESS_DEBUG 0
  30. std::ostream& dev::eth::operator<<(std::ostream& _out, ExecutionResult const& _er)
  31. {
  32. _out << "{" << _er.gasUsed << ", " << _er.newAddress << ", " << toHex(_er.output) << "}";
  33. return _out;
  34. }
  35. TransactionException dev::eth::toTransactionException(Exception const& _e)
  36. {
  37. // Basic Transaction exceptions
  38. if (!!dynamic_cast<RLPException const*>(&_e))
  39. return TransactionException::BadRLP;
  40. if (!!dynamic_cast<OutOfGasIntrinsic const*>(&_e))
  41. return TransactionException::OutOfGasIntrinsic;
  42. if (!!dynamic_cast<InvalidSignature const*>(&_e))
  43. return TransactionException::InvalidSignature;
  44. // Executive exceptions
  45. if (!!dynamic_cast<OutOfGasBase const*>(&_e))
  46. return TransactionException::OutOfGasBase;
  47. if (!!dynamic_cast<InvalidNonce const*>(&_e))
  48. return TransactionException::InvalidNonce;
  49. if (!!dynamic_cast<NotEnoughCash const*>(&_e))
  50. return TransactionException::NotEnoughCash;
  51. if (!!dynamic_cast<BlockGasLimitReached const*>(&_e))
  52. return TransactionException::BlockGasLimitReached;
  53. // VM execution exceptions
  54. if (!!dynamic_cast<BadInstruction const*>(&_e))
  55. return TransactionException::BadInstruction;
  56. if (!!dynamic_cast<BadJumpDestination const*>(&_e))
  57. return TransactionException::BadJumpDestination;
  58. if (!!dynamic_cast<OutOfGas const*>(&_e))
  59. return TransactionException::OutOfGas;
  60. if (!!dynamic_cast<OutOfStack const*>(&_e))
  61. return TransactionException::OutOfStack;
  62. if (!!dynamic_cast<StackUnderflow const*>(&_e))
  63. return TransactionException::StackUnderflow;
  64. return TransactionException::Unknown;
  65. }
  66. std::ostream& dev::eth::operator<<(std::ostream& _out, TransactionException const& _er)
  67. {
  68. switch (_er)
  69. {
  70. case TransactionException::None: _out << "None"; break;
  71. case TransactionException::BadRLP: _out << "BadRLP"; break;
  72. case TransactionException::InvalidFormat: _out << "InvalidFormat"; break;
  73. case TransactionException::OutOfGasIntrinsic: _out << "OutOfGasIntrinsic"; break;
  74. case TransactionException::InvalidSignature: _out << "InvalidSignature"; break;
  75. case TransactionException::InvalidNonce: _out << "InvalidNonce"; break;
  76. case TransactionException::NotEnoughCash: _out << "NotEnoughCash"; break;
  77. case TransactionException::OutOfGasBase: _out << "OutOfGasBase"; break;
  78. case TransactionException::BlockGasLimitReached: _out << "BlockGasLimitReached"; break;
  79. case TransactionException::BadInstruction: _out << "BadInstruction"; break;
  80. case TransactionException::BadJumpDestination: _out << "BadJumpDestination"; break;
  81. case TransactionException::OutOfGas: _out << "OutOfGas"; break;
  82. case TransactionException::OutOfStack: _out << "OutOfStack"; break;
  83. case TransactionException::StackUnderflow: _out << "StackUnderflow"; break;
  84. default: _out << "Unknown"; break;
  85. }
  86. return _out;
  87. }
  88. Transaction::Transaction(bytesConstRef _rlpData, CheckTransaction _checkSig):
  89. TransactionBase(_rlpData, _checkSig)
  90. {
  91. }