Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 4,890 Lines • ▼ Show 20 Lines | void CWallet::SetupDescriptorScriptPubKeyMans() { | ||||
// Get the extended key | // Get the extended key | ||||
CExtKey master_key; | CExtKey master_key; | ||||
master_key.SetSeed(seed_key.begin(), seed_key.size()); | master_key.SetSeed(seed_key.begin(), seed_key.size()); | ||||
for (bool internal : {false, true}) { | for (bool internal : {false, true}) { | ||||
for (OutputType t : OUTPUT_TYPES) { | for (OutputType t : OUTPUT_TYPES) { | ||||
auto spk_manager = | auto spk_manager = | ||||
std::make_unique<DescriptorScriptPubKeyMan>(*this, t, internal); | std::make_unique<DescriptorScriptPubKeyMan>(*this, internal); | ||||
if (IsCrypted()) { | if (IsCrypted()) { | ||||
if (IsLocked()) { | if (IsLocked()) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
std::string(__func__) + | std::string(__func__) + | ||||
": Wallet is locked, cannot setup new descriptors"); | ": Wallet is locked, cannot setup new descriptors"); | ||||
} | } | ||||
if (!spk_manager->CheckDecryptionKey(vMasterKey) && | if (!spk_manager->CheckDecryptionKey(vMasterKey) && | ||||
!spk_manager->Encrypt(vMasterKey, nullptr)) { | !spk_manager->Encrypt(vMasterKey, nullptr)) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
std::string(__func__) + | std::string(__func__) + | ||||
": Could not encrypt new descriptors"); | ": Could not encrypt new descriptors"); | ||||
} | } | ||||
} | } | ||||
spk_manager->SetupDescriptorGeneration(master_key); | spk_manager->SetupDescriptorGeneration(master_key, t); | ||||
uint256 id = spk_manager->GetID(); | uint256 id = spk_manager->GetID(); | ||||
m_spk_managers[id] = std::move(spk_manager); | m_spk_managers[id] = std::move(spk_manager); | ||||
SetActiveScriptPubKeyMan(id, t, internal); | SetActiveScriptPubKeyMan(id, t, internal); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void CWallet::SetActiveScriptPubKeyMan(uint256 id, OutputType type, | void CWallet::SetActiveScriptPubKeyMan(uint256 id, OutputType type, | ||||
bool internal, bool memonly) { | bool internal, bool memonly) { | ||||
WalletLogPrintf( | WalletLogPrintf( | ||||
"Setting spkMan to active: id = %s, type = %d, internal = %d\n", | "Setting spkMan to active: id = %s, type = %d, internal = %d\n", | ||||
id.ToString(), static_cast<int>(type), static_cast<int>(internal)); | id.ToString(), static_cast<int>(type), static_cast<int>(internal)); | ||||
auto &spk_mans = | auto &spk_mans = | ||||
internal ? m_internal_spk_managers : m_external_spk_managers; | internal ? m_internal_spk_managers : m_external_spk_managers; | ||||
auto spk_man = m_spk_managers.at(id).get(); | auto spk_man = m_spk_managers.at(id).get(); | ||||
spk_man->SetType(type, internal); | spk_man->SetInternal(internal); | ||||
spk_mans[type] = spk_man; | spk_mans[type] = spk_man; | ||||
if (!memonly) { | if (!memonly) { | ||||
WalletBatch batch(*database); | WalletBatch batch(*database); | ||||
if (!batch.WriteActiveScriptPubKeyMan(static_cast<uint8_t>(type), id, | if (!batch.WriteActiveScriptPubKeyMan(static_cast<uint8_t>(type), id, | ||||
internal)) { | internal)) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
std::string(__func__) + | std::string(__func__) + | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |