forked from ethereum/aleth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClientBase.h
192 lines (159 loc) · 7.67 KB
/
ClientBase.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
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 ClientBase.h
* @author Gav Wood <[email protected]>
* @author Marek Kotewicz <[email protected]>
* @date 2015
*/
#pragma once
#include <chrono>
#include "Interface.h"
#include "LogFilter.h"
#include "TransactionQueue.h"
#include "Block.h"
#include "CommonNet.h"
namespace dev
{
namespace eth
{
struct InstalledFilter
{
InstalledFilter(LogFilter const& _f): filter(_f) {}
LogFilter filter;
unsigned refCount = 1;
LocalisedLogEntries changes;
};
static const h256 PendingChangedFilter = u256(0);
static const h256 ChainChangedFilter = u256(1);
static const LogEntry SpecialLogEntry = LogEntry(Address(), h256s(), bytes());
static const LocalisedLogEntry InitialChange(SpecialLogEntry);
struct ClientWatch
{
ClientWatch(): lastPoll(std::chrono::system_clock::now()) {}
explicit ClientWatch(h256 _id, Reaping _r): id(_id), lastPoll(_r == Reaping::Automatic ? std::chrono::system_clock::now() : std::chrono::system_clock::time_point::max()) {}
h256 id;
#if INITIAL_STATE_AS_CHANGES
LocalisedLogEntries changes = LocalisedLogEntries{ InitialChange };
#else
LocalisedLogEntries changes;
#endif
mutable std::chrono::system_clock::time_point lastPoll = std::chrono::system_clock::now();
};
class ClientBase: public Interface
{
public:
ClientBase() {}
virtual ~ClientBase() {}
/// Estimate gas usage for call/create.
/// @param _maxGas An upper bound value for estimation, if not provided default value of c_maxGasEstimate will be used.
/// @param _callback Optional callback function for progress reporting
std::pair<u256, ExecutionResult> estimateGas(Address const& _from, u256 _value, Address _dest, bytes const& _data, int64_t _maxGas, u256 _gasPrice, BlockNumber _blockNumber, GasEstimationCallback const& _callback) override;
using Interface::balanceAt;
using Interface::countAt;
using Interface::stateAt;
using Interface::codeAt;
using Interface::codeHashAt;
using Interface::storageAt;
u256 balanceAt(Address _a, BlockNumber _block) const override;
u256 countAt(Address _a, BlockNumber _block) const override;
u256 stateAt(Address _a, u256 _l, BlockNumber _block) const override;
h256 stateRootAt(Address _a, BlockNumber _block) const override;
bytes codeAt(Address _a, BlockNumber _block) const override;
h256 codeHashAt(Address _a, BlockNumber _block) const override;
std::map<h256, std::pair<u256, u256>> storageAt(Address _a, BlockNumber _block) const override;
LocalisedLogEntries logs(unsigned _watchId) const override;
LocalisedLogEntries logs(LogFilter const& _filter) const override;
virtual void prependLogsFromBlock(LogFilter const& _filter, h256 const& _blockHash, BlockPolarity _polarity, LocalisedLogEntries& io_logs) const;
/// Install, uninstall and query watches.
unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) override;
unsigned installWatch(h256 _filterId, Reaping _r = Reaping::Automatic) override;
bool uninstallWatch(unsigned _watchId) override;
LocalisedLogEntries peekWatch(unsigned _watchId) const override;
LocalisedLogEntries checkWatch(unsigned _watchId) override;
h256 hashFromNumber(BlockNumber _number) const override;
BlockNumber numberFromHash(h256 _blockHash) const override;
int compareBlockHashes(h256 _h1, h256 _h2) const override;
BlockHeader blockInfo(h256 _hash) const override;
BlockDetails blockDetails(h256 _hash) const override;
Transaction transaction(h256 _transactionHash) const override;
LocalisedTransaction localisedTransaction(h256 const& _transactionHash) const override;
Transaction transaction(h256 _blockHash, unsigned _i) const override;
LocalisedTransaction localisedTransaction(h256 const& _blockHash, unsigned _i) const override;
TransactionReceipt transactionReceipt(h256 const& _transactionHash) const override;
LocalisedTransactionReceipt localisedTransactionReceipt(h256 const& _transactionHash) const override;
std::pair<h256, unsigned> transactionLocation(h256 const& _transactionHash) const override;
Transactions transactions(h256 _blockHash) const override;
TransactionHashes transactionHashes(h256 _blockHash) const override;
BlockHeader uncle(h256 _blockHash, unsigned _i) const override;
UncleHashes uncleHashes(h256 _blockHash) const override;
unsigned transactionCount(h256 _blockHash) const override;
unsigned uncleCount(h256 _blockHash) const override;
unsigned number() const override;
Transactions pending() const override;
h256s pendingHashes() const override;
BlockHeader pendingInfo() const override;
BlockDetails pendingDetails() const override;
EVMSchedule evmSchedule() const override { return sealEngine()->evmSchedule(pendingInfo().number()); }
ImportResult injectBlock(bytes const& _block) override;
using Interface::addresses;
Addresses addresses(BlockNumber _block) const override;
u256 gasLimitRemaining() const override;
u256 gasBidPrice() const override { return DefaultGasPrice; }
/// Get the block author
Address author() const override;
bool isKnown(h256 const& _hash) const override;
bool isKnown(BlockNumber _block) const override;
bool isKnownTransaction(h256 const& _transactionHash) const override;
bool isKnownTransaction(h256 const& _blockHash, unsigned _i) const override;
void startSealing() override
{
BOOST_THROW_EXCEPTION(
InterfaceNotSupported() << errinfo_interface("ClientBase::startSealing"));
}
void stopSealing() override
{
BOOST_THROW_EXCEPTION(
InterfaceNotSupported() << errinfo_interface("ClientBase::stopSealing"));
}
bool wouldSeal() const override
{
BOOST_THROW_EXCEPTION(
InterfaceNotSupported() << errinfo_interface("ClientBase::wouldSeal"));
}
SyncStatus syncStatus() const override
{
BOOST_THROW_EXCEPTION(
InterfaceNotSupported() << errinfo_interface("ClientBase::syncStatus"));
}
Block block(BlockNumber _h) const;
int chainId() const override;
protected:
/// The interface that must be implemented in any class deriving this.
/// {
virtual BlockChain& bc() = 0;
virtual BlockChain const& bc() const = 0;
virtual Block block(h256 const& _h) const = 0;
virtual Block preSeal() const = 0;
virtual Block postSeal() const = 0;
virtual void prepareForTransaction() = 0;
/// }
// filters
mutable Mutex x_filtersWatches; ///< Our lock.
std::unordered_map<h256, InstalledFilter> m_filters; ///< The dictionary of filters that are active.
std::unordered_map<h256, h256s> m_specialFilters = std::unordered_map<h256, std::vector<h256>>{{PendingChangedFilter, {}}, {ChainChangedFilter, {}}};
///< The dictionary of special filters and their additional data
std::map<unsigned, ClientWatch> m_watches; ///< Each and every watch - these reference a filter.
Logger m_loggerWatch{createLogger(7, "watch")};
};
}}