| 474 | } |
| 475 | |
| 476 | bool LegacyScriptPubKeyMan::Upgrade(int prev_version, int new_version, bilingual_str& error) |
| 477 | { |
| 478 | LOCK(cs_KeyStore); |
| 479 | |
| 480 | if (m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { |
| 481 | // Nothing to do here if private keys are not enabled |
| 482 | return true; |
| 483 | } |
| 484 | |
| 485 | bool hd_upgrade = false; |
| 486 | bool split_upgrade = false; |
| 487 | if (IsFeatureSupported(new_version, FEATURE_HD) && !IsHDEnabled()) { |
| 488 | WalletLogPrintf("Upgrading wallet to HD\n"); |
| 489 | m_storage.SetMinVersion(FEATURE_HD); |
| 490 | |
| 491 | // generate a new master key |
| 492 | CPubKey masterPubKey = GenerateNewSeed(); |
| 493 | SetHDSeed(masterPubKey); |
| 494 | hd_upgrade = true; |
| 495 | } |
| 496 | // Upgrade to HD chain split if necessary |
| 497 | if (!IsFeatureSupported(prev_version, FEATURE_HD_SPLIT) && IsFeatureSupported(new_version, FEATURE_HD_SPLIT)) { |
| 498 | WalletLogPrintf("Upgrading wallet to use HD chain split\n"); |
| 499 | m_storage.SetMinVersion(FEATURE_PRE_SPLIT_KEYPOOL); |
| 500 | split_upgrade = FEATURE_HD_SPLIT > prev_version; |
| 501 | // Upgrade the HDChain |
| 502 | if (m_hd_chain.nVersion < CHDChain::VERSION_HD_CHAIN_SPLIT) { |
| 503 | m_hd_chain.nVersion = CHDChain::VERSION_HD_CHAIN_SPLIT; |
| 504 | if (!WalletBatch(m_storage.GetDatabase()).WriteHDChain(m_hd_chain)) { |
| 505 | throw std::runtime_error(std::string(__func__) + ": writing chain failed"); |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | // Mark all keys currently in the keypool as pre-split |
| 510 | if (split_upgrade) { |
| 511 | MarkPreSplitKeys(); |
| 512 | } |
| 513 | // Regenerate the keypool if upgraded to HD |
| 514 | if (hd_upgrade) { |
| 515 | if (!NewKeyPool()) { |
| 516 | error = _("Unable to generate keys"); |
| 517 | return false; |
| 518 | } |
| 519 | } |
| 520 | return true; |
| 521 | } |
| 522 | |
| 523 | bool LegacyScriptPubKeyMan::HavePrivateKeys() const |
| 524 | { |
no test coverage detected