MCPcopy Create free account
hub / github.com/ElementsProject/elements / AddDescriptorKeyWithDB

Method AddDescriptorKeyWithDB

src/wallet/scriptpubkeyman.cpp:1911–1939  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1909}
1910
1911bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const CKey& key, const CPubKey &pubkey)
1912{
1913 AssertLockHeld(cs_desc_man);
1914 assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
1915
1916 // Check if provided key already exists
1917 if (m_map_keys.find(pubkey.GetID()) != m_map_keys.end() ||
1918 m_map_crypted_keys.find(pubkey.GetID()) != m_map_crypted_keys.end()) {
1919 return true;
1920 }
1921
1922 if (m_storage.HasEncryptionKeys()) {
1923 if (m_storage.IsLocked()) {
1924 return false;
1925 }
1926
1927 std::vector<unsigned char> crypted_secret;
1928 CKeyingMaterial secret(key.begin(), key.end());
1929 if (!EncryptSecret(m_storage.GetEncryptionKey(), secret, pubkey.GetHash(), crypted_secret)) {
1930 return false;
1931 }
1932
1933 m_map_crypted_keys[pubkey.GetID()] = make_pair(pubkey, crypted_secret);
1934 return batch.WriteCryptedDescriptorKey(GetID(), pubkey, crypted_secret);
1935 } else {
1936 m_map_keys[pubkey.GetID()] = key;
1937 return batch.WriteDescriptorKey(GetID(), pubkey, key.GetPrivKey());
1938 }
1939}
1940
1941bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key, OutputType addr_type, bool internal)
1942{

Callers

nothing calls this directly

Calls 12

EncryptSecretFunction · 0.85
IsWalletFlagSetMethod · 0.80
findMethod · 0.80
HasEncryptionKeysMethod · 0.80
IsLockedMethod · 0.80
WriteDescriptorKeyMethod · 0.80
GetIDMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
GetHashMethod · 0.45
GetPrivKeyMethod · 0.45

Tested by

no test coverage detected