Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/scriptpubkeyman.cpp
Show First 20 Lines • Show All 1,808 Lines • ▼ Show 20 Lines | if (IsMine(script)) { | ||||
} | } | ||||
if (!TopUp()) { | if (!TopUp()) { | ||||
WalletLogPrintf("%s: Topping up keypool failed (locked wallet)\n", | WalletLogPrintf("%s: Topping up keypool failed (locked wallet)\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void DescriptorScriptPubKeyMan::AddDescriptorKey(const CKey &key, | |||||
const CPubKey &pubkey) { | |||||
LOCK(cs_desc_man); | |||||
WalletBatch batch(m_storage.GetDatabase()); | |||||
if (!AddDescriptorKeyWithDB(batch, key, pubkey)) { | |||||
throw std::runtime_error(std::string(__func__) + | |||||
": writing descriptor private key failed"); | |||||
} | |||||
} | |||||
bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch &batch, | bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch &batch, | ||||
const CKey &key, | const CKey &key, | ||||
const CPubKey &pubkey) { | const CPubKey &pubkey) { | ||||
AssertLockHeld(cs_desc_man); | AssertLockHeld(cs_desc_man); | ||||
assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | ||||
if (m_storage.HasEncryptionKeys()) { | if (m_storage.HasEncryptionKeys()) { | ||||
if (m_storage.IsLocked()) { | if (m_storage.IsLocked()) { | ||||
▲ Show 20 Lines • Show All 382 Lines • ▼ Show 20 Lines | bool DescriptorScriptPubKeyMan::AddCryptedKey( | ||||
LOCK(cs_desc_man); | LOCK(cs_desc_man); | ||||
if (!m_map_keys.empty()) { | if (!m_map_keys.empty()) { | ||||
return false; | return false; | ||||
} | } | ||||
m_map_crypted_keys[key_id] = make_pair(pubkey, crypted_key); | m_map_crypted_keys[key_id] = make_pair(pubkey, crypted_key); | ||||
return true; | return true; | ||||
} | } | ||||
bool DescriptorScriptPubKeyMan::HasWalletDescriptor( | |||||
const WalletDescriptor &desc) const { | |||||
LOCK(cs_desc_man); | |||||
return m_wallet_descriptor.descriptor != nullptr && | |||||
desc.descriptor != nullptr && | |||||
m_wallet_descriptor.descriptor->ToString() == | |||||
desc.descriptor->ToString(); | |||||
} | |||||
void DescriptorScriptPubKeyMan::WriteDescriptor() { | |||||
LOCK(cs_desc_man); | |||||
WalletBatch batch(m_storage.GetDatabase()); | |||||
if (!batch.WriteDescriptor(GetID(), m_wallet_descriptor)) { | |||||
throw std::runtime_error(std::string(__func__) + | |||||
": writing descriptor failed"); | |||||
} | |||||
} | |||||
const WalletDescriptor DescriptorScriptPubKeyMan::GetWalletDescriptor() const { | |||||
return m_wallet_descriptor; | |||||
} | |||||
const std::vector<CScript> DescriptorScriptPubKeyMan::GetScriptPubKeys() const { | |||||
LOCK(cs_desc_man); | |||||
std::vector<CScript> script_pub_keys; | |||||
script_pub_keys.reserve(m_map_script_pub_keys.size()); | |||||
for (auto const &script_pub_key : m_map_script_pub_keys) { | |||||
script_pub_keys.push_back(script_pub_key.first); | |||||
} | |||||
return script_pub_keys; | |||||
} |