aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-02-19 18:21:19 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2012-02-19 18:21:19 -0800
commit3a4d81724e873f967b74759d539e05c73f95aeeb (patch)
tree64ccc448dbcaa00058538fd01e489a01a13cc41b /src/wallet.cpp
parent49355d999303cf93df68ee63ef6ee32bcf4890d2 (diff)
parent38067c18f8b54c7121643fa3291ffe81b6eefef1 (diff)
downloadbitcoin-3a4d81724e873f967b74759d539e05c73f95aeeb.tar.xz
Merge pull request #864 from sipa/fix_856
Make compressed pubkeys require client >=0.5.99
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 9d80f8afef..30590c80e6 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -15,6 +15,23 @@ using namespace std;
// mapWallet
//
+std::vector<unsigned char> CWallet::GenerateNewKey()
+{
+ bool fCompressed = true; // default to compressed public keys
+
+ RandAddSeedPerfmon();
+ CKey key;
+ key.MakeNewKey(fCompressed);
+
+ // Compressed public keys were introduced in version 0.6.0
+ if (fCompressed)
+ SetMinVersion(59900);
+
+ if (!AddKey(key))
+ throw std::runtime_error("CWallet::GenerateNewKey() : AddKey failed");
+ return key.GetPubKey();
+}
+
bool CWallet::AddKey(const CKey& key)
{
if (!CCryptoKeyStore::AddKey(key))
@@ -131,6 +148,32 @@ public:
)
};
+bool CWallet::SetMinVersion(int nVersion, CWalletDB* pwalletdbIn)
+{
+ if (nWalletVersion >= nVersion)
+ return true;
+
+ nWalletVersion = nVersion;
+
+ if (fFileBacked)
+ {
+ CWalletDB* pwalletdb = pwalletdbIn ? pwalletdbIn : new CWalletDB(strWalletFile);
+ if (nWalletVersion >= 40000)
+ {
+ // Versions prior to 0.4.0 did not support the "minversion" record.
+ // Use a CCorruptAddress to make them crash instead.
+ CCorruptAddress corruptAddress;
+ pwalletdb->WriteSetting("addrIncoming", corruptAddress);
+ }
+ if (nWalletVersion > 40000)
+ pwalletdb->WriteMinVersion(nWalletVersion);
+ if (!pwalletdbIn)
+ delete pwalletdb;
+ }
+
+ return true;
+}
+
bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
{
if (IsCrypted())
@@ -184,10 +227,11 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
exit(1); //We now probably have half of our keys encrypted in memory, and half not...die and let the user reload their unencrypted wallet.
}
+ // Encryption was introduced in version 0.4.0
+ SetMinVersion(40000, pwalletdbEncryption);
+
if (fFileBacked)
{
- CCorruptAddress corruptAddress;
- pwalletdbEncryption->WriteSetting("addrIncoming", corruptAddress);
if (!pwalletdbEncryption->TxnCommit())
exit(1); //We now have keys encrypted in memory, but no on disk...die to avoid confusion and let the user reload their unencrypted wallet.