diff options
Diffstat (limited to 'src/db.h')
| -rw-r--r-- | src/db.h | 58 |
1 files changed, 58 insertions, 0 deletions
| @@ -16,9 +16,43 @@ class CWalletTx; | |||
| 16 | extern map<string, string> mapAddressBook; | 16 | extern map<string, string> mapAddressBook; |
| 17 | extern bool fClient; | 17 | extern bool fClient; |
| 18 | 18 | ||
| 19 | // Wallet file format guard. The current wallet stores private keys in plain | ||
| 20 | // records. The next format will encrypt them; builds that do not implement it | ||
| 21 | // must stop before they can show an empty-looking wallet. | ||
| 22 | static const int WALLET_FORMAT_PLAINTEXT = 1; | ||
| 23 | static const int WALLET_FORMAT_ENCRYPTED = 2; | ||
| 24 | static const int WALLET_FORMAT_SUPPORTED = WALLET_FORMAT_ENCRYPTED; | ||
| 25 | |||
| 26 | class CWalletMasterKey | ||
| 27 | { | ||
| 28 | public: | ||
| 29 | vector<unsigned char> vchCryptedKey; | ||
| 30 | vector<unsigned char> vchSalt; | ||
| 31 | unsigned int nDerivationMethod; | ||
| 32 | unsigned int nDeriveIterations; | ||
| 33 | |||
| 34 | CWalletMasterKey() | ||
| 35 | { | ||
| 36 | nDerivationMethod = 0; | ||
| 37 | nDeriveIterations = 25000; | ||
| 38 | vchSalt.resize(8); | ||
| 39 | } | ||
| 40 | |||
| 41 | IMPLEMENT_SERIALIZE | ||
| 42 | ( | ||
| 43 | READWRITE(vchCryptedKey); | ||
| 44 | READWRITE(vchSalt); | ||
| 45 | READWRITE(nDerivationMethod); | ||
| 46 | READWRITE(nDeriveIterations); | ||
| 47 | ) | ||
| 48 | }; | ||
| 49 | |||
| 19 | 50 | ||
| 20 | extern DbEnv dbenv; | 51 | extern DbEnv dbenv; |
| 21 | extern void DBFlush(bool fShutdown); | 52 | extern void DBFlush(bool fShutdown); |
| 53 | // Close the environment and delete its logs. Only the encryption command calls | ||
| 54 | // this: the logs hold the plaintext records the old wallet wrote. | ||
| 55 | extern void PurgeDbEnvironmentLogs(); | ||
| 22 | 56 | ||
| 23 | 57 | ||
| 24 | 58 | ||
| @@ -411,6 +445,29 @@ public: | |||
| 411 | && Write(string("hdchaincode"), vchChainCode); | 445 | && Write(string("hdchaincode"), vchChainCode); |
| 412 | } | 446 | } |
| 413 | 447 | ||
| 448 | bool WriteWalletMinVersion(int nVersion) | ||
| 449 | { | ||
| 450 | return Write(string("walletminversion"), nVersion); | ||
| 451 | } | ||
| 452 | |||
| 453 | bool WriteMasterKey(unsigned int nID, const CWalletMasterKey& kMasterKey) | ||
| 454 | { | ||
| 455 | return Write(make_pair(string("mkey"), nID), kMasterKey, true); | ||
| 456 | } | ||
| 457 | |||
| 458 | bool WriteCryptedKey(const vector<unsigned char>& vchPubKey, | ||
| 459 | const vector<unsigned char>& vchCryptedSecret) | ||
| 460 | { | ||
| 461 | return Write(make_pair(string("ckey"), vchPubKey), vchCryptedSecret, false); | ||
| 462 | } | ||
| 463 | |||
| 464 | bool WriteCryptedHDMaster(const vector<unsigned char>& vchCryptedMaster, | ||
| 465 | const vector<unsigned char>& vchCryptedChainCode) | ||
| 466 | { | ||
| 467 | return Write(string("cryptedhdmaster"), vchCryptedMaster) | ||
| 468 | && Write(string("cryptedhdchaincode"), vchCryptedChainCode); | ||
| 469 | } | ||
| 470 | |||
| 414 | bool WriteHDNext(unsigned int nNext) | 471 | bool WriteHDNext(unsigned int nNext) |
| 415 | { | 472 | { |
| 416 | return Write(string("hdnext"), nNext); | 473 | return Write(string("hdnext"), nNext); |
| @@ -478,6 +535,7 @@ bool BackupWallet(const string& strDest); | |||
| 478 | // POSIX -- the output holds private keys in the clear. | 535 | // POSIX -- the output holds private keys in the clear. |
| 479 | bool DumpWallet(const string& strDest); | 536 | bool DumpWallet(const string& strDest); |
| 480 | bool ImportWallet(const string& strSrc, int& nAddedRet, int& nSkippedRet); | 537 | bool ImportWallet(const string& strSrc, int& nAddedRet, int& nSkippedRet); |
| 538 | bool EncryptWallet(const string& strPassphrase, string& strBackupRet, string& strErrorRet); | ||
| 481 | 539 | ||
| 482 | inline bool SetAddressBookName(const string& strAddress, const string& strName) | 540 | inline bool SetAddressBookName(const string& strAddress, const string& strName) |
| 483 | { | 541 | { |