Fabcoin Core  0.16.2
P2P Digital Currency
Transaction.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #include <libdevcore/vector_ref.h>
23 #include <libdevcore/Log.h>
24 #include <libdevcore/CommonIO.h>
25 #include <libdevcrypto/Common.h>
26 #include <libethcore/Exceptions.h>
27 #include <libevm/VMFace.h>
28 #include "Interface.h"
29 #include "Transaction.h"
30 using namespace std;
31 using namespace dev;
32 using namespace dev::eth;
33 
34 #define ETH_ADDRESS_DEBUG 0
35 
36 std::ostream& dev::eth::operator<<(std::ostream& _out, ExecutionResult const& _er)
37 {
38  _out << "{" << _er.gasUsed << ", " << _er.newAddress << ", " << toHex(_er.output) << "}";
39  return _out;
40 }
41 
43 {
44  // Basic Transaction exceptions
45  if (!!dynamic_cast<RLPException const*>(&_e))
46  return TransactionException::BadRLP;
47  if (!!dynamic_cast<OutOfGasIntrinsic const*>(&_e))
48  return TransactionException::OutOfGasIntrinsic;
49  if (!!dynamic_cast<InvalidSignature const*>(&_e))
50  return TransactionException::InvalidSignature;
51  // Executive exceptions
52  if (!!dynamic_cast<OutOfGasBase const*>(&_e))
53  return TransactionException::OutOfGasBase;
54  if (!!dynamic_cast<InvalidNonce const*>(&_e))
55  return TransactionException::InvalidNonce;
56  if (!!dynamic_cast<NotEnoughCash const*>(&_e))
57  return TransactionException::NotEnoughCash;
58  if (!!dynamic_cast<BlockGasLimitReached const*>(&_e))
59  return TransactionException::BlockGasLimitReached;
60  // VM execution exceptions
61  if (!!dynamic_cast<BadInstruction const*>(&_e))
62  return TransactionException::BadInstruction;
63  if (!!dynamic_cast<BadJumpDestination const*>(&_e))
64  return TransactionException::BadJumpDestination;
65  if (!!dynamic_cast<OutOfGas const*>(&_e))
66  return TransactionException::OutOfGas;
67  if (!!dynamic_cast<OutOfStack const*>(&_e))
68  return TransactionException::OutOfStack;
69  if (!!dynamic_cast<StackUnderflow const*>(&_e))
70  return TransactionException::StackUnderflow;
71  if (!!dynamic_cast<CreateWithValue const*>(&_e))
72  return TransactionException::CreateWithValue;
73  return TransactionException::Unknown;
74 }
75 
76 std::ostream& dev::eth::operator<<(std::ostream& _out, TransactionException const& _er)
77 {
78  switch (_er)
79  {
80  case TransactionException::None: _out << "None"; break;
81  case TransactionException::BadRLP: _out << "BadRLP"; break;
82  case TransactionException::InvalidFormat: _out << "InvalidFormat"; break;
83  case TransactionException::OutOfGasIntrinsic: _out << "OutOfGasIntrinsic"; break;
84  case TransactionException::InvalidSignature: _out << "InvalidSignature"; break;
85  case TransactionException::InvalidNonce: _out << "InvalidNonce"; break;
86  case TransactionException::NotEnoughCash: _out << "NotEnoughCash"; break;
87  case TransactionException::OutOfGasBase: _out << "OutOfGasBase"; break;
88  case TransactionException::BlockGasLimitReached: _out << "BlockGasLimitReached"; break;
89  case TransactionException::BadInstruction: _out << "BadInstruction"; break;
90  case TransactionException::BadJumpDestination: _out << "BadJumpDestination"; break;
91  case TransactionException::OutOfGas: _out << "OutOfGas"; break;
92  case TransactionException::OutOfStack: _out << "OutOfStack"; break;
93  case TransactionException::StackUnderflow: _out << "StackUnderflow"; break;
94  case TransactionException::CreateWithValue: _out << "CreateWithValue"; break;
95  case TransactionException::NoInformation: _out << "NoInformation"; break;
96  default: _out << "Unknown"; break;
97  }
98  return _out;
99 }
100 
101 Transaction::Transaction(bytesConstRef _rlpData, CheckTransaction _checkSig):
102  TransactionBase(_rlpData, _checkSig)
103 {
104 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
Definition: CommonData.h:54
std::ostream & operator<<(std::ostream &_out, BlockHeader const &_bi)
Definition: BlockHeader.h:194
std::hash for asio::adress
Definition: Common.h:323
Description of the result of executing a transaction.
Definition: Transaction.h:69
Base class for all exceptions.
Definition: Exceptions.h:39
CheckTransaction
Definition: Transaction.h:42
TransactionException
Definition: Transaction.h:35
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Definition: Transaction.h:50
TransactionException toTransactionException(Exception const &_e)
Definition: Transaction.cpp:42