Ethereum  PoC-8
The C++ Implementation of Ethereum
OverlayDB.h
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 #pragma once
23 
24 #include <memory>
25 #include <libdevcore/db.h>
26 #include <libdevcore/Common.h>
27 #include <libdevcore/Log.h>
29 
30 namespace dev
31 {
32 
33 class OverlayDB: public StateCacheDB
34 {
35 public:
36  explicit OverlayDB(std::unique_ptr<db::DatabaseFace> _db = nullptr)
37  : m_db(_db.release(), [](db::DatabaseFace* db) {
38  clog(VerbosityDebug, "overlaydb") << "Closing state DB";
39  delete db;
40  })
41  {}
42 
43  ~OverlayDB();
44 
45  // Copyable
46  OverlayDB(OverlayDB const&) = default;
47  OverlayDB& operator=(OverlayDB const&) = default;
48  // Movable
49  OverlayDB(OverlayDB&&) = default;
50  OverlayDB& operator=(OverlayDB&&) = default;
51 
52  void commit();
53  void rollback();
54 
55  std::string lookup(h256 const& _h) const;
56  bool exists(h256 const& _h) const;
57  void kill(h256 const& _h);
58 
59  bytes lookupAux(h256 const& _h) const;
60 
61 private:
62  using StateCacheDB::clear;
63 
64  std::shared_ptr<db::DatabaseFace> m_db;
65 };
66 
67 }
Definition: Address.cpp:20
bytes lookupAux(h256 const &_h) const
Definition: OverlayDB.cpp:102
OverlayDB & operator=(OverlayDB const &)=default
OverlayDB(std::unique_ptr< db::DatabaseFace > _db=nullptr)
Definition: OverlayDB.h:36
std::vector< byte > bytes
Definition: Common.h:72
FixedHash< 32 > h256
Definition: FixedHash.h:354
bool exists(h256 const &_h) const
Definition: OverlayDB.cpp:134
std::string lookup(h256 const &_h) const
Definition: OverlayDB.cpp:125
void kill(h256 const &_h)
Definition: OverlayDB.cpp:141
#define clog(SEVERITY, CHANNEL)