Browse Source

Make Defaults a singleton.

cl-refactor
Gav Wood 11 years ago
parent
commit
f0943872fc
  1. 7
      eth/main.cpp
  2. 11
      libethereum/BlockChain.cpp
  3. 10
      libethereum/BlockChain.h
  4. 3
      libethereum/BlockInfo.cpp
  5. 3
      libethereum/FileSystem.cpp
  6. 2
      libethereum/State.cpp

7
eth/main.cpp

@ -73,6 +73,9 @@ int main(int argc, char** argv)
string publicIP;
bool upnp = true;
// Init defaults
Defaults::get();
// Our address.
KeyPair us = KeyPair::create();
Address coinbase = us.address();
@ -217,6 +220,10 @@ int main(int argc, char** argv)
Address dest = h160(fromUserHex(rechex));
c.transact(us.secret(), dest, amount, fee);
}
else if (cmd == "exit")
{
break;
}
}
}
else

11
libethereum/BlockChain.cpp

@ -31,8 +31,6 @@
using namespace std;
using namespace eth;
std::string Defaults::s_dbPath = getDataDir();
namespace eth
{
std::ostream& operator<<(std::ostream& _out, BlockChain const& _bc)
@ -50,6 +48,13 @@ std::ostream& operator<<(std::ostream& _out, BlockChain const& _bc)
}
}
Defaults* Defaults::s_this = nullptr;
Defaults::Defaults()
{
m_dbPath = getDataDir();
}
BlockDetails::BlockDetails(RLP const& _r)
{
number = _r[0].toInt<uint>();
@ -66,7 +71,7 @@ bytes BlockDetails::rlp() const
BlockChain::BlockChain(std::string _path, bool _killExisting)
{
if (_path.empty())
_path = Defaults::s_dbPath;
_path = Defaults::get()->m_dbPath;
boost::filesystem::create_directory(_path);
if (_killExisting)
{

10
libethereum/BlockChain.h

@ -31,11 +31,17 @@ struct Defaults
{
friend class BlockChain;
friend class State;
public:
static void setDBPath(std::string _dbPath) { s_dbPath = _dbPath; }
Defaults();
static Defaults* get() { if (!s_this) s_this = new Defaults; return s_this; }
static void setDBPath(std::string const& _dbPath) { get()->m_dbPath = _dbPath; }
private:
static std::string s_dbPath;
std::string m_dbPath;
static Defaults* s_this;
};
class RLP;

3
libethereum/BlockInfo.cpp

@ -51,9 +51,6 @@ bytes BlockInfo::createGenesisBlock()
state.init();
eth::commit(genesisState(), db, state);
stateRoot = state.root();
cout << "--- Genesis state_root=" << stateRoot << endl;
clog << state;
clog << db;
}
block.appendList(9) << h256() << sha3EmptyList << h160() << stateRoot << sha3EmptyList << c_genesisDifficulty << (uint)0 << string() << (uint)42;

3
libethereum/FileSystem.cpp

@ -21,11 +21,12 @@
* @date 2014
*/
#include "FileSystem.h"
#ifdef _WIN32
#include <shlobj.h>
#endif
#include <boost/filesystem.hpp>
#include "FileSystem.h"
using namespace std;
using namespace eth;

2
libethereum/State.cpp

@ -76,7 +76,7 @@ std::map<Address, AddressState> const& eth::genesisState()
Overlay State::openDB(std::string _path, bool _killExisting)
{
if (_path.empty())
_path = Defaults::s_dbPath;
_path = Defaults::get()->m_dbPath;
boost::filesystem::create_directory(_path);
if (_killExisting)
boost::filesystem::remove_all(_path + "/state");

Loading…
Cancel
Save