diff --git a/Application.h b/Application.h index f1260050d..b8929e5cf 100644 --- a/Application.h +++ b/Application.h @@ -5,6 +5,7 @@ #include "ConnectionPool.h" #include "KnownNodeList.h" #include "TimingService.h" +#include "PubKeyCache.h" #include "ScopedLock.h" #include "Wallet.h" #include "database/database.h" @@ -21,6 +22,7 @@ class Application UniqueNodeList mUNL; KnownNodeList mKnownNodes; Wallet mWallet; + PubKeyCache mPKCache; Database* mDatabase; @@ -36,13 +38,14 @@ class Application public: Application(); - ConnectionPool& getConnectionPool(){ return(mConnectionPool); } - UniqueNodeList& getUNL(){ return(mUNL); } - Wallet& getWallet(){ return(mWallet); } - Database* getDB(){ return(mDatabase); } + ConnectionPool& getConnectionPool() { return(mConnectionPool); } + UniqueNodeList& getUNL() { return(mUNL); } + Wallet& getWallet() { return(mWallet); } + PubKeyCache& getPubKeyCache() { return mPKCache; } + Database* getDB() { return(mDatabase); } ScopedLock getDBLock() { return ScopedLock(dbLock); } - void setDB(Database* db){ mDatabase=db; } + void setDB(Database* db) { mDatabase=db; } //Serializer* getSerializer(){ return(mSerializer); } //void setSerializer(Serializer* ser){ mSerializer=ser; } diff --git a/PubKeyCache.cpp b/PubKeyCache.cpp index db9a6df9b..0350a2aac 100644 --- a/PubKeyCache.cpp +++ b/PubKeyCache.cpp @@ -43,12 +43,13 @@ CKey::pointer PubKeyCache::locate(const uint160& id) return ckp; } -void PubKeyCache::store(const uint160& id, CKey::pointer key) -{ +CKey::pointer PubKeyCache::store(const uint160& id, CKey::pointer key) +{ // stored if needed, returns cached copy (possibly the original) if(1) { boost::mutex::scoped_lock sl(mLock); - if(mCache[id]) return; + CKey::pointer cached(mCache[id]); + if(cached) return cached; mCache[id]=key; } std::string sql="INSERT INTO PubKeys (ID, PubKey) VALUES ('"; @@ -62,6 +63,7 @@ void PubKeyCache::store(const uint160& id, CKey::pointer key) sql.append(";"); ScopedLock sl(theApp->getDBLock()); theApp->getDB()->executeSQL(sql.c_str()); + return key; } void PubKeyCache::clear() diff --git a/PubKeyCache.h b/PubKeyCache.h index 79db370cb..c2ffd82af 100644 --- a/PubKeyCache.h +++ b/PubKeyCache.h @@ -18,7 +18,7 @@ public: PubKeyCache() { ; } CKey::pointer locate(const uint160& id); - void store(const uint160& id, CKey::pointer key); + CKey::pointer store(const uint160& id, CKey::pointer key); void clear(void); };