MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / AddDescriptorKeyWithDB

Method AddDescriptorKeyWithDB

src/wallet/scriptpubkeyman.cpp:1153–1183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1151}
1152
1153bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const CKey& key, const CPubKey &pubkey)
1154{
1155 AssertLockHeld(cs_desc_man);
1156 assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
1157
1158 // Check if provided key already exists
1159 if (m_map_keys.contains(pubkey.GetID()) ||
1160 m_map_crypted_keys.contains(pubkey.GetID())) {
1161 return true;
1162 }
1163
1164 if (m_storage.HasEncryptionKeys()) {
1165 if (m_storage.IsLocked()) {
1166 return false;
1167 }
1168
1169 std::vector<unsigned char> crypted_secret;
1170 CKeyingMaterial secret{UCharCast(key.begin()), UCharCast(key.end())};
1171 if (!m_storage.WithEncryptionKey([&](const CKeyingMaterial& encryption_key) {
1172 return EncryptSecret(encryption_key, secret, pubkey.GetHash(), crypted_secret);
1173 })) {
1174 return false;
1175 }
1176
1177 m_map_crypted_keys[pubkey.GetID()] = make_pair(pubkey, crypted_secret);
1178 return batch.WriteCryptedDescriptorKey(GetID(), pubkey, crypted_secret);
1179 } else {
1180 m_map_keys[pubkey.GetID()] = key;
1181 return batch.WriteDescriptorKey(GetID(), pubkey, key.GetPrivKey());
1182 }
1183}
1184
1185void DescriptorScriptPubKeyMan::SetupDescriptorGeneration(WalletBatch& batch, const CExtKey& master_key, OutputType addr_type, bool internal)
1186{

Callers

nothing calls this directly

Calls 14

UCharCastFunction · 0.85
EncryptSecretFunction · 0.85
IsWalletFlagSetMethod · 0.80
HasEncryptionKeysMethod · 0.80
IsLockedMethod · 0.80
WithEncryptionKeyMethod · 0.80
WriteDescriptorKeyMethod · 0.80
containsMethod · 0.45
GetIDMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected