diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2010-10-09 17:59:38 -0400 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2010-10-09 17:59:38 -0400 |
commit | 687c5ef7949a7f0c388ad633b40d243ed6786c4e (patch) | |
tree | 2316e4497185d0ad9dc6065cf58faf9d7b551363 /db.h | |
parent | 7d5d89856d6ba9a0a25dc5cd42897814cf124c11 (diff) | |
parent | 103849419a9c014a69c76b6f96e48b66cbc838ca (diff) | |
download | bitcoin-687c5ef7949a7f0c388ad633b40d243ed6786c4e.tar.xz |
Merge remote branch 'refs/remotes/svn/trunk' into svn
Diffstat (limited to 'db.h')
-rw-r--r-- | db.h | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -308,6 +308,35 @@ bool LoadAddresses(); +class CKeyPool +{ +public: + int64 nTime; + vector<unsigned char> vchPubKey; + + CKeyPool() + { + nTime = GetTime(); + } + + CKeyPool(const vector<unsigned char>& vchPubKeyIn) + { + nTime = GetTime(); + vchPubKey = vchPubKeyIn; + } + + IMPLEMENT_SERIALIZE + ( + if (!(nType & SER_GETHASH)) + READWRITE(nVersion); + READWRITE(nTime); + READWRITE(vchPubKey); + ) +}; + + + + class CWalletDB : public CDB { public: @@ -396,6 +425,13 @@ public: } bool LoadWallet(); +protected: + void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool); + void KeepKey(int64 nIndex); + static void ReturnKey(int64 nIndex); + friend class CReserveKey; +public: + vector<unsigned char> GetKeyFromKeyPool(); }; bool LoadWallet(bool& fFirstRunRet); @@ -405,3 +441,48 @@ inline bool SetAddressBookName(const string& strAddress, const string& strName) { return CWalletDB().WriteName(strAddress, strName); } + +class CReserveKey +{ +protected: + int64 nIndex; + vector<unsigned char> vchPubKey; +public: + CReserveKey() + { + nIndex = -1; + } + + ~CReserveKey() + { + ReturnKey(); + } + + vector<unsigned char> GetReservedKey() + { + if (nIndex == -1) + { + CKeyPool keypool; + CWalletDB().ReserveKeyFromKeyPool(nIndex, keypool); + vchPubKey = keypool.vchPubKey; + } + assert(!vchPubKey.empty()); + return vchPubKey; + } + + void KeepKey() + { + if (nIndex != -1) + CWalletDB().KeepKey(nIndex); + nIndex = -1; + vchPubKey.clear(); + } + + void ReturnKey() + { + if (nIndex != -1) + CWalletDB::ReturnKey(nIndex); + nIndex = -1; + vchPubKey.clear(); + } +}; |