aboutsummaryrefslogtreecommitdiff
path: root/db.h
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-10-09 19:33:35 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-10-09 19:33:35 +0000
commit103849419a9c014a69c76b6f96e48b66cbc838ca (patch)
tree73bce9b5c3d96304138b25d1e714222ea3d4a384 /db.h
parent0a27bd065e4803a35e436c610bedb06fe39123c6 (diff)
key pool for safer wallet backup
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@163 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'db.h')
-rw-r--r--db.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/db.h b/db.h
index 9b1f5e58be..dac277a016 100644
--- a/db.h
+++ b/db.h
@@ -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();
+ }
+};