Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/scriptpubkeyman.cpp
Show First 20 Lines • Show All 1,613 Lines • ▼ Show 20 Lines | std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const { | ||||
} | } | ||||
std::set<CKeyID> set_address; | std::set<CKeyID> set_address; | ||||
for (const auto &mi : mapCryptedKeys) { | for (const auto &mi : mapCryptedKeys) { | ||||
set_address.insert(mi.first); | set_address.insert(mi.first); | ||||
} | } | ||||
return set_address; | return set_address; | ||||
} | } | ||||
void LegacyScriptPubKeyMan::SetType(OutputType type, bool internal) {} | void LegacyScriptPubKeyMan::SetInternal(bool internal) {} | ||||
bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, | bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, | ||||
CTxDestination &dest, | CTxDestination &dest, | ||||
std::string &error) { | std::string &error) { | ||||
// Returns true if this descriptor supports getting new addresses. | // Returns true if this descriptor supports getting new addresses. | ||||
// Conditions where we may be unable to fetch them (e.g. locked) are caught | // Conditions where we may be unable to fetch them (e.g. locked) are caught | ||||
// later | // later | ||||
if (!CanGetAddresses(m_internal)) { | if (!CanGetAddresses(m_internal)) { | ||||
error = "No addresses available"; | error = "No addresses available"; | ||||
return false; | return false; | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_desc_man); | LOCK(cs_desc_man); | ||||
// This is a combo descriptor which should not be an active descriptor | // This is a combo descriptor which should not be an active descriptor | ||||
assert(m_wallet_descriptor.descriptor->IsSingleType()); | assert(m_wallet_descriptor.descriptor->IsSingleType()); | ||||
if (type != m_address_type) { | std::optional<OutputType> desc_addr_type = | ||||
m_wallet_descriptor.descriptor->GetOutputType(); | |||||
assert(desc_addr_type); | |||||
if (type != *desc_addr_type) { | |||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
": Types are inconsistent"); | ": Types are inconsistent"); | ||||
} | } | ||||
TopUp(); | TopUp(); | ||||
// Get the scriptPubKey from the descriptor | // Get the scriptPubKey from the descriptor | ||||
FlatSigningProvider out_keys; | FlatSigningProvider out_keys; | ||||
▲ Show 20 Lines • Show All 301 Lines • ▼ Show 20 Lines | if (m_storage.HasEncryptionKeys()) { | ||||
return batch.WriteCryptedDescriptorKey(GetID(), pubkey, crypted_secret); | return batch.WriteCryptedDescriptorKey(GetID(), pubkey, crypted_secret); | ||||
} else { | } else { | ||||
m_map_keys[pubkey.GetID()] = key; | m_map_keys[pubkey.GetID()] = key; | ||||
return batch.WriteDescriptorKey(GetID(), pubkey, key.GetPrivKey()); | return batch.WriteDescriptorKey(GetID(), pubkey, key.GetPrivKey()); | ||||
} | } | ||||
} | } | ||||
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration( | bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration( | ||||
const CExtKey &master_key) { | const CExtKey &master_key, OutputType addr_type) { | ||||
LOCK(cs_desc_man); | LOCK(cs_desc_man); | ||||
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)); | assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)); | ||||
// Ignore when there is already a descriptor | // Ignore when there is already a descriptor | ||||
if (m_wallet_descriptor.descriptor) { | if (m_wallet_descriptor.descriptor) { | ||||
return false; | return false; | ||||
} | } | ||||
int64_t creation_time = GetTime(); | int64_t creation_time = GetTime(); | ||||
std::string xpub = EncodeExtPubKey(master_key.Neuter()); | std::string xpub = EncodeExtPubKey(master_key.Neuter()); | ||||
// Build descriptor string | // Build descriptor string | ||||
std::string desc_prefix; | std::string desc_prefix; | ||||
std::string desc_suffix = "/*)"; | std::string desc_suffix = "/*)"; | ||||
switch (m_address_type) { | switch (addr_type) { | ||||
case OutputType::LEGACY: { | case OutputType::LEGACY: { | ||||
desc_prefix = "pkh(" + xpub + "/44'"; | desc_prefix = "pkh(" + xpub + "/44'"; | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
assert(false); | assert(false); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | uint256 DescriptorScriptPubKeyMan::GetID() const { | ||||
std::string desc_str = m_wallet_descriptor.descriptor->ToString(); | std::string desc_str = m_wallet_descriptor.descriptor->ToString(); | ||||
uint256 id; | uint256 id; | ||||
CSHA256() | CSHA256() | ||||
.Write((uint8_t *)desc_str.data(), desc_str.size()) | .Write((uint8_t *)desc_str.data(), desc_str.size()) | ||||
.Finalize(id.begin()); | .Finalize(id.begin()); | ||||
return id; | return id; | ||||
} | } | ||||
void DescriptorScriptPubKeyMan::SetType(OutputType type, bool internal) { | void DescriptorScriptPubKeyMan::SetInternal(bool internal) { | ||||
this->m_address_type = type; | |||||
this->m_internal = internal; | this->m_internal = internal; | ||||
} | } | ||||
void DescriptorScriptPubKeyMan::SetCache(const DescriptorCache &cache) { | void DescriptorScriptPubKeyMan::SetCache(const DescriptorCache &cache) { | ||||
LOCK(cs_desc_man); | LOCK(cs_desc_man); | ||||
m_wallet_descriptor.cache = cache; | m_wallet_descriptor.cache = cache; | ||||
for (int32_t i = m_wallet_descriptor.range_start; | for (int32_t i = m_wallet_descriptor.range_start; | ||||
i < m_wallet_descriptor.range_end; ++i) { | i < m_wallet_descriptor.range_end; ++i) { | ||||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |