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 
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 }
dev::OverlayDB::operator=
OverlayDB & operator=(OverlayDB const &)=default
dev::OverlayDB::rollback
void rollback()
Definition: OverlayDB.cpp:117
dev::OverlayDB::~OverlayDB
~OverlayDB()
dev::OverlayDB::exists
bool exists(h256 const &_h) const
Definition: OverlayDB.cpp:134
db.h
dev::FixedHash< 32 >
StateCacheDB.h
dev::OverlayDB::commit
void commit()
Definition: OverlayDB.cpp:48
dev::OverlayDB::lookupAux
bytes lookupAux(h256 const &_h) const
Definition: OverlayDB.cpp:102
Common.h
dev::OverlayDB::lookup
std::string lookup(h256 const &_h) const
Definition: OverlayDB.cpp:125
dev::bytes
std::vector< byte > bytes
Definition: Common.h:72
dev::OverlayDB::OverlayDB
OverlayDB(std::unique_ptr< db::DatabaseFace > _db=nullptr)
Definition: OverlayDB.h:36
dev::OverlayDB::OverlayDB
OverlayDB(OverlayDB const &)=default
dev::OverlayDB
Definition: OverlayDB.h:34
dev::OverlayDB::kill
void kill(h256 const &_h)
Definition: OverlayDB.cpp:141
dev::OverlayDB::operator=
OverlayDB & operator=(OverlayDB &&)=default
dev::VerbosityDebug
@ VerbosityDebug
Definition: Log.h:71
dev::StateCacheDB::clear
void clear()
Definition: StateCacheDB.h:38
dev::StateCacheDB
Definition: StateCacheDB.h:27
dev
Definition: Address.cpp:21
clog
#define clog(SEVERITY, CHANNEL)
dev::OverlayDB::OverlayDB
OverlayDB(OverlayDB &&)=default
Log.h