| 1058 | } |
| 1059 | |
| 1060 | CPubKey LegacyScriptPubKeyMan::GenerateNewKey(WalletBatch &batch, CHDChain& hd_chain, bool internal) |
| 1061 | { |
| 1062 | assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); |
| 1063 | assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET)); |
| 1064 | AssertLockHeld(cs_KeyStore); |
| 1065 | bool fCompressed = m_storage.CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets |
| 1066 | |
| 1067 | CKey secret; |
| 1068 | |
| 1069 | // Create new metadata |
| 1070 | int64_t nCreationTime = GetTime(); |
| 1071 | CKeyMetadata metadata(nCreationTime); |
| 1072 | |
| 1073 | // use HD key derivation if HD was enabled during wallet creation and a seed is present |
| 1074 | if (IsHDEnabled()) { |
| 1075 | DeriveNewChildKey(batch, metadata, secret, hd_chain, (m_storage.CanSupportFeature(FEATURE_HD_SPLIT) ? internal : false)); |
| 1076 | } else { |
| 1077 | secret.MakeNewKey(fCompressed); |
| 1078 | } |
| 1079 | |
| 1080 | // Compressed public keys were introduced in version 0.6.0 |
| 1081 | if (fCompressed) { |
| 1082 | m_storage.SetMinVersion(FEATURE_COMPRPUBKEY); |
| 1083 | } |
| 1084 | |
| 1085 | CPubKey pubkey = secret.GetPubKey(); |
| 1086 | assert(secret.VerifyPubKey(pubkey)); |
| 1087 | |
| 1088 | mapKeyMetadata[pubkey.GetID()] = metadata; |
| 1089 | UpdateTimeFirstKey(nCreationTime); |
| 1090 | |
| 1091 | if (!AddKeyPubKeyWithDB(batch, secret, pubkey)) { |
| 1092 | throw std::runtime_error(std::string(__func__) + ": AddKey failed"); |
| 1093 | } |
| 1094 | return pubkey; |
| 1095 | } |
| 1096 | |
| 1097 | void LegacyScriptPubKeyMan::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata& metadata, CKey& secret, CHDChain& hd_chain, bool internal) |
| 1098 | { |
nothing calls this directly
no test coverage detected