forked from bcosorg/bcos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transaction.h
154 lines (128 loc) · 4.9 KB
/
Transaction.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
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 Transaction.h
* @author Gav Wood <i@gavwood.com>
* @date 2014
*/
#pragma once
#include <libdevcore/RLP.h>
#include <libdevcore/SHA3.h>
#include <libethcore/Common.h>
#include <libethcore/Transaction.h>
#include <libethcore/ChainOperationParams.h>
namespace dev
{
namespace eth
{
enum class TransactionException
{
None = 0,
Unknown,
BadRLP,
InvalidFormat,
OutOfGasIntrinsic, ///< Too little gas to pay for the base transaction cost.
InvalidSignature,
InvalidNonce,
NotEnoughCash,
OutOfGasBase, ///< Too little gas to pay for the base transaction cost.
BlockGasLimitReached,
BadInstruction,
BadJumpDestination,
OutOfGas, ///< Ran out of gas executing code of the transaction.
OutOfStack, ///< Ran out of stack executing code of the transaction.
StackUnderflow,
NonceCheckFail, // noncecheck ok() == false
BlockLimitCheckFail,
FilterCheckFail,
NoDeployPermission,
NoCallPermission,
NoTxPermission
};
enum class CodeDeposit
{
None = 0,
Failed,
Success
};
struct VMException;
TransactionException toTransactionException(Exception const& _e);
std::ostream& operator<<(std::ostream& _out, TransactionException const& _er);
/// Description of the result of executing a transaction.
struct ExecutionResult
{
u256 gasUsed = 0;
TransactionException excepted = TransactionException::Unknown;
Address newAddress;
bytes output;
CodeDeposit codeDeposit = CodeDeposit::None; ///< Failed if an attempted deposit failed due to lack of gas.
u256 gasRefunded = 0;
unsigned depositSize = 0; ///< Amount of code of the creation's attempted deposit.
u256 gasForDeposit; ///< Amount of gas remaining for the code deposit phase.
};
std::ostream& operator<<(std::ostream& _out, ExecutionResult const& _er);
/// Encodes a transaction, ready to be exported to or freshly imported from RLP.
class Transaction: public TransactionBase
{
public:
/// Constructs a null transaction.
Transaction() {}
/// Constructs from a transaction skeleton & optional secret.
Transaction(TransactionSkeleton const& _ts, Secret const& _s = Secret()): TransactionBase(_ts, _s) {}
/// Constructs a signed message-call transaction.
Transaction(u256 const& _value, u256 const& _gasPrice, u256 const& _gas, Address const& _dest, bytes const& _data, u256 const& _randomid, Secret const& _secret):
TransactionBase(_value, _gasPrice, _gas, _dest, _data, _randomid, _secret)
{}
/// Constructs a signed contract-creation transaction.
Transaction(u256 const& _value, u256 const& _gasPrice, u256 const& _gas, bytes const& _data, u256 const& _randomid, Secret const& _secret):
TransactionBase(_value, _gasPrice, _gas, _data, _randomid, _secret)
{}
/// Constructs an unsigned message-call transaction.
Transaction(u256 const& _value, u256 const& _gasPrice, u256 const& _gas, Address const& _dest, bytes const& _data, u256 const& _randomid = Invalid256):
TransactionBase(_value, _gasPrice, _gas, _dest, _data, _randomid)
{}
/// Constructs an unsigned contract-creation transaction.
Transaction(u256 const& _value, u256 const& _gasPrice, u256 const& _gas, bytes const& _data, u256 const& _randomid = Invalid256):
TransactionBase(_value, _gasPrice, _gas, _data, _randomid)
{}
/// Constructs a transaction from the given RLP.
explicit Transaction(bytesConstRef _rlp, CheckTransaction _checkSig);
/// Constructs a transaction from the given RLP.
explicit Transaction(bytes const& _rlp, CheckTransaction _checkSig): Transaction(&_rlp, _checkSig) {}
};
/// Nice name for vector of Transaction.
using Transactions = std::vector<Transaction>;
class LocalisedTransaction: public Transaction
{
public:
LocalisedTransaction(
Transaction const& _t,
h256 const& _blockHash,
unsigned _transactionIndex,
BlockNumber _blockNumber = 0
):
Transaction(_t),
m_blockHash(_blockHash),
m_transactionIndex(_transactionIndex),
m_blockNumber(_blockNumber)
{}
h256 const& blockHash() const { return m_blockHash; }
unsigned transactionIndex() const { return m_transactionIndex; }
BlockNumber blockNumber() const { return m_blockNumber; }
private:
h256 m_blockHash;
unsigned m_transactionIndex;
BlockNumber m_blockNumber;
};
}
}