Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/scriptpubkeyman.cpp
Show First 20 Lines • Show All 1,516 Lines • ▼ Show 20 Lines | std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const { | ||||
return set_address; | return set_address; | ||||
} | } | ||||
void LegacyScriptPubKeyMan::SetType(OutputType type, bool internal) {} | void LegacyScriptPubKeyMan::SetType(OutputType type, 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. | |||||
// Conditions where we may be unable to fetch them (e.g. locked) are caught | |||||
// later | |||||
if (!CanGetAddresses(m_internal)) { | |||||
error = "No addresses available"; | |||||
return false; | return false; | ||||
} | } | ||||
{ | |||||
LOCK(cs_desc_man); | |||||
// This is a combo descriptor which should not be an active descriptor | |||||
assert(m_wallet_descriptor.descriptor->IsSingleType()); | |||||
if (type != m_address_type) { | |||||
throw std::runtime_error(std::string(__func__) + | |||||
": Types are inconsistent"); | |||||
} | |||||
TopUp(); | |||||
// Get the scriptPubKey from the descriptor | |||||
FlatSigningProvider out_keys; | |||||
std::vector<CScript> scripts_temp; | |||||
if (m_wallet_descriptor.range_end <= m_max_cached_index && !TopUp(1)) { | |||||
// We can't generate anymore keys | |||||
error = "Error: Keypool ran out, please call keypoolrefill first"; | |||||
return false; | |||||
} | |||||
if (!m_wallet_descriptor.descriptor->ExpandFromCache( | |||||
m_wallet_descriptor.next_index, m_wallet_descriptor.cache, | |||||
scripts_temp, out_keys)) { | |||||
// We can't generate anymore keys | |||||
error = "Error: Keypool ran out, please call keypoolrefill first"; | |||||
return false; | |||||
} | |||||
Optional<OutputType> out_script_type = | |||||
m_wallet_descriptor.descriptor->GetOutputType(); | |||||
if (out_script_type && out_script_type == type) { | |||||
ExtractDestination(scripts_temp[0], dest); | |||||
} else { | |||||
throw std::runtime_error( | |||||
std::string(__func__) + | |||||
": Types are inconsistent. Stored type does not match type of " | |||||
"newly generated address"); | |||||
} | |||||
m_wallet_descriptor.next_index++; | |||||
WalletBatch(m_storage.GetDatabase()) | |||||
.WriteDescriptor(GetID(), m_wallet_descriptor); | |||||
return true; | |||||
} | |||||
} | |||||
isminetype DescriptorScriptPubKeyMan::IsMine(const CScript &script) const { | isminetype DescriptorScriptPubKeyMan::IsMine(const CScript &script) const { | ||||
LOCK(cs_desc_man); | LOCK(cs_desc_man); | ||||
if (m_map_script_pub_keys.count(script) > 0) { | if (m_map_script_pub_keys.count(script) > 0) { | ||||
return ISMINE_SPENDABLE; | return ISMINE_SPENDABLE; | ||||
} | } | ||||
return ISMINE_NO; | return ISMINE_NO; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 384 Lines • Show Last 20 Lines |