From 0bcbb5bd75580e9f862af61c4bceeb448b708169 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 26 Jun 2012 03:39:15 -0700 Subject: [PATCH] Move RPC data_* commands data to db/rpc.db. --- src/Application.cpp | 19 ++++++++++--------- src/Application.h | 3 ++- src/DBInit.cpp | 30 +++++++++++++++++++----------- src/Wallet.cpp | 12 ++++++------ 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 6b7ff795a2..cc68d9cc39 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -38,15 +38,15 @@ DatabaseCon::~DatabaseCon() Application::Application() : mUNL(mIOService), mNetOps(mIOService, &mMasterLedger), mTempNodeCache(16384, 90), mHashedObjectStore(16384, 300), - mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL), + mRpcDB(NULL), mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL), mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL) { RAND_bytes(mNonce256.begin(), mNonce256.size()); RAND_bytes(reinterpret_cast(&mNonceST), sizeof(mNonceST)); } -extern const char *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], *NetNodeDBInit[]; -extern int TxnDBCount, LedgerDBCount, WalletDBCount, HashNodeDBCount, NetNodeDBCount; +extern const char *RpcDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], *NetNodeDBInit[]; +extern int RpcDBCount, TxnDBCount, LedgerDBCount, WalletDBCount, HashNodeDBCount, NetNodeDBCount; void Application::stop() { @@ -70,12 +70,13 @@ void Application::run() // // Construct databases. // - boost::thread t1(boost::bind(&InitDB, &mTxnDB, "transaction.db", TxnDBInit, TxnDBCount)); - boost::thread t2(boost::bind(&InitDB, &mLedgerDB, "ledger.db", LedgerDBInit, LedgerDBCount)); - boost::thread t3(boost::bind(&InitDB, &mWalletDB, "wallet.db", WalletDBInit, WalletDBCount)); - boost::thread t4(boost::bind(&InitDB, &mHashNodeDB, "hashnode.db", HashNodeDBInit, HashNodeDBCount)); - boost::thread t5(boost::bind(&InitDB, &mNetNodeDB, "netnode.db", NetNodeDBInit, NetNodeDBCount)); - t1.join(); t2.join(); t3.join(); t4.join(); t5.join(); + boost::thread t1(boost::bind(&InitDB, &mRpcDB, "rpc.db", RpcDBInit, RpcDBCount)); + boost::thread t2(boost::bind(&InitDB, &mTxnDB, "transaction.db", TxnDBInit, TxnDBCount)); + boost::thread t3(boost::bind(&InitDB, &mLedgerDB, "ledger.db", LedgerDBInit, LedgerDBCount)); + boost::thread t4(boost::bind(&InitDB, &mWalletDB, "wallet.db", WalletDBInit, WalletDBCount)); + boost::thread t5(boost::bind(&InitDB, &mHashNodeDB, "hashnode.db", HashNodeDBInit, HashNodeDBCount)); + boost::thread t6(boost::bind(&InitDB, &mNetNodeDB, "netnode.db", NetNodeDBInit, NetNodeDBCount)); + t1.join(); t2.join(); t3.join(); t4.join(); t5.join(); t6.join(); // // Begin validation and ip maintenance. diff --git a/src/Application.h b/src/Application.h index 5dac2be6cc..14281abbff 100644 --- a/src/Application.h +++ b/src/Application.h @@ -51,7 +51,7 @@ class Application SuppressionTable mSuppressions; HashedObjectStore mHashedObjectStore; - DatabaseCon *mTxnDB, *mLedgerDB, *mWalletDB, *mHashNodeDB, *mNetNodeDB; + DatabaseCon *mRpcDB, *mTxnDB, *mLedgerDB, *mWalletDB, *mHashNodeDB, *mNetNodeDB; ConnectionPool mConnectionPool; PeerDoor* mPeerDoor; @@ -87,6 +87,7 @@ public: bool isNew(const uint160& s) { return mSuppressions.addSuppression(s); } bool running() { return mTxnDB != NULL; } + DatabaseCon* getRpcDB() { return mRpcDB; } DatabaseCon* getTxnDB() { return mTxnDB; } DatabaseCon* getLedgerDB() { return mLedgerDB; } DatabaseCon* getWalletDB() { return mWalletDB; } diff --git a/src/DBInit.cpp b/src/DBInit.cpp index 2d390564ed..4f11e12ec3 100644 --- a/src/DBInit.cpp +++ b/src/DBInit.cpp @@ -1,3 +1,5 @@ +#include "utils.h" + #include // Transaction database holds transactions and public keys @@ -30,7 +32,7 @@ const char *TxnDBInit[] = { "END TRANSACTION;" }; -int TxnDBCount = sizeof(TxnDBInit) / sizeof(const char *); +int TxnDBCount = NUMBER(TxnDBInit); // Ledger database holds ledgers and ledger confirmations const char *LedgerDBInit[] = { @@ -59,7 +61,19 @@ const char *LedgerDBInit[] = { "END TRANSACTION;" }; -int LedgerDBCount = sizeof(LedgerDBInit) / sizeof(const char *); +int LedgerDBCount = NUMBER(LedgerDBInit); + +// RPC database holds persistent data for RPC clients. +const char *RpcDBInit[] = { + + // Local persistence of the RPC client + "CREATE TABLE RPCData ( \ + Key TEXT PRIMARY Key, \ + Value TEXT \ + );", +}; + +int RpcDBCount = NUMBER(RpcDBInit); // Wallet database holds local accounts and trusted nodes const char *WalletDBInit[] = { @@ -73,12 +87,6 @@ const char *WalletDBInit[] = { Dh1024 TEXT \ );", - // Local persistence of the RPC client - "CREATE TABLE RPCData ( \ - Key TEXT PRIMARY Key, \ - Value TEXT \ - );", - // Miscellaneous persistent information // Integer: 1 : Used to simplify SQL. // ScoreUpdated: when scores was last updated. @@ -237,7 +245,7 @@ const char *WalletDBInit[] = { "END TRANSACTION;" }; -int WalletDBCount = sizeof(WalletDBInit) / sizeof(const char *); +int WalletDBCount = NUMBER(WalletDBInit); // Hash node database holds nodes indexed by hash const char *HashNodeDBInit[] = { @@ -256,7 +264,7 @@ const char *HashNodeDBInit[] = { "END TRANSACTION;" }; -int HashNodeDBCount = sizeof(HashNodeDBInit) / sizeof(const char *); +int HashNodeDBCount = NUMBER(HashNodeDBInit); // Net node database holds nodes seen on the network // XXX Not really used needs replacement. @@ -270,6 +278,6 @@ const char *NetNodeDBInit[] = { }; -int NetNodeDBCount = sizeof(NetNodeDBInit) / sizeof(const char *); +int NetNodeDBCount = NUMBER(NetNodeDBInit); // vim:ts=4 diff --git a/src/Wallet.cpp b/src/Wallet.cpp index 12dda320b6..5d1ef4e8a7 100644 --- a/src/Wallet.cpp +++ b/src/Wallet.cpp @@ -117,9 +117,9 @@ bool Wallet::nodeIdentityCreate() { bool Wallet::dataDelete(const std::string& strKey) { - Database* db = theApp->getWalletDB()->getDB(); + Database* db = theApp->getRpcDB()->getDB(); - ScopedLock sl(theApp->getWalletDB()->getDBLock()); + ScopedLock sl(theApp->getRpcDB()->getDBLock()); return db->executeSQL(str(boost::format("DELETE FROM RPCData WHERE Key=%s;") % db->escape(strKey))); @@ -127,9 +127,9 @@ bool Wallet::dataDelete(const std::string& strKey) bool Wallet::dataFetch(const std::string& strKey, std::string& strValue) { - Database* db = theApp->getWalletDB()->getDB(); + Database* db = theApp->getRpcDB()->getDB(); - ScopedLock sl(theApp->getWalletDB()->getDBLock()); + ScopedLock sl(theApp->getRpcDB()->getDBLock()); bool bSuccess = false; @@ -151,9 +151,9 @@ bool Wallet::dataFetch(const std::string& strKey, std::string& strValue) bool Wallet::dataStore(const std::string& strKey, const std::string& strValue) { - Database* db = theApp->getWalletDB()->getDB(); + Database* db = theApp->getRpcDB()->getDB(); - ScopedLock sl(theApp->getWalletDB()->getDBLock()); + ScopedLock sl(theApp->getRpcDB()->getDBLock()); bool bSuccess = false;