mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 11:13:23 -03:00
Change SetType to SetInternal and remove m_address_type
m_address_type was used for two things: 1. Determine the type of descriptor to generate during SetupDescriptorGeneration 2. Sanity check during GetNewDestination. There is no need to have this variable to accomplish those things. 1. Add a argument to SetupDescriptorGeneration indicating the address type to use 2. Use Descriptor::GetOutputType for the sanity check.
This commit is contained in:
parent
89b1ce1140
commit
ca2a09640f
3 changed files with 16 additions and 16 deletions
|
@ -1497,7 +1497,7 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
|
||||||
return set_address;
|
return set_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LegacyScriptPubKeyMan::SetType(OutputType type, bool internal) {}
|
void LegacyScriptPubKeyMan::SetInternal(bool internal) {}
|
||||||
|
|
||||||
bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
|
bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
|
||||||
{
|
{
|
||||||
|
@ -1509,7 +1509,9 @@ bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDest
|
||||||
{
|
{
|
||||||
LOCK(cs_desc_man);
|
LOCK(cs_desc_man);
|
||||||
assert(m_wallet_descriptor.descriptor->IsSingleType()); // This is a combo descriptor which should not be an active descriptor
|
assert(m_wallet_descriptor.descriptor->IsSingleType()); // This is a combo descriptor which should not be an active descriptor
|
||||||
if (type != m_address_type) {
|
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__) + ": Types are inconsistent");
|
throw std::runtime_error(std::string(__func__) + ": Types are inconsistent");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1777,7 +1779,7 @@ bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key)
|
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(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));
|
||||||
|
@ -1794,7 +1796,7 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
|
||||||
// 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;
|
||||||
|
@ -2076,9 +2078,8 @@ uint256 DescriptorScriptPubKeyMan::GetID() const
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,7 @@ public:
|
||||||
|
|
||||||
virtual uint256 GetID() const { return uint256(); }
|
virtual uint256 GetID() const { return uint256(); }
|
||||||
|
|
||||||
virtual void SetType(OutputType type, bool internal) {}
|
virtual void SetInternal(bool internal) {}
|
||||||
|
|
||||||
/** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */
|
/** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */
|
||||||
template<typename... Params>
|
template<typename... Params>
|
||||||
|
@ -370,7 +370,7 @@ public:
|
||||||
|
|
||||||
uint256 GetID() const override;
|
uint256 GetID() const override;
|
||||||
|
|
||||||
void SetType(OutputType type, bool internal) override;
|
void SetInternal(bool internal) override;
|
||||||
|
|
||||||
// Map from Key ID to key metadata.
|
// Map from Key ID to key metadata.
|
||||||
std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_KeyStore);
|
std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_KeyStore);
|
||||||
|
@ -497,7 +497,6 @@ private:
|
||||||
PubKeyMap m_map_pubkeys GUARDED_BY(cs_desc_man);
|
PubKeyMap m_map_pubkeys GUARDED_BY(cs_desc_man);
|
||||||
int32_t m_max_cached_index = -1;
|
int32_t m_max_cached_index = -1;
|
||||||
|
|
||||||
OutputType m_address_type;
|
|
||||||
bool m_internal = false;
|
bool m_internal = false;
|
||||||
|
|
||||||
KeyMap m_map_keys GUARDED_BY(cs_desc_man);
|
KeyMap m_map_keys GUARDED_BY(cs_desc_man);
|
||||||
|
@ -522,9 +521,9 @@ public:
|
||||||
: ScriptPubKeyMan(storage),
|
: ScriptPubKeyMan(storage),
|
||||||
m_wallet_descriptor(descriptor)
|
m_wallet_descriptor(descriptor)
|
||||||
{}
|
{}
|
||||||
DescriptorScriptPubKeyMan(WalletStorage& storage, OutputType address_type, bool internal)
|
DescriptorScriptPubKeyMan(WalletStorage& storage, bool internal)
|
||||||
: ScriptPubKeyMan(storage),
|
: ScriptPubKeyMan(storage),
|
||||||
m_address_type(address_type), m_internal(internal)
|
m_internal(internal)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
mutable RecursiveMutex cs_desc_man;
|
mutable RecursiveMutex cs_desc_man;
|
||||||
|
@ -549,7 +548,7 @@ public:
|
||||||
bool IsHDEnabled() const override;
|
bool IsHDEnabled() const override;
|
||||||
|
|
||||||
//! Setup descriptors based on the given CExtkey
|
//! Setup descriptors based on the given CExtkey
|
||||||
bool SetupDescriptorGeneration(const CExtKey& master_key);
|
bool SetupDescriptorGeneration(const CExtKey& master_key, OutputType addr_type);
|
||||||
|
|
||||||
bool HavePrivateKeys() const override;
|
bool HavePrivateKeys() const override;
|
||||||
|
|
||||||
|
@ -573,7 +572,7 @@ public:
|
||||||
|
|
||||||
uint256 GetID() const override;
|
uint256 GetID() const override;
|
||||||
|
|
||||||
void SetType(OutputType type, bool internal) override;
|
void SetInternal(bool internal) override;
|
||||||
|
|
||||||
void SetCache(const DescriptorCache& cache);
|
void SetCache(const DescriptorCache& cache);
|
||||||
|
|
||||||
|
|
|
@ -4369,7 +4369,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
|
||||||
|
|
||||||
for (bool internal : {false, true}) {
|
for (bool internal : {false, true}) {
|
||||||
for (OutputType t : OUTPUT_TYPES) {
|
for (OutputType t : OUTPUT_TYPES) {
|
||||||
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, t, internal));
|
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, internal));
|
||||||
if (IsCrypted()) {
|
if (IsCrypted()) {
|
||||||
if (IsLocked()) {
|
if (IsLocked()) {
|
||||||
throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors");
|
throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors");
|
||||||
|
@ -4378,7 +4378,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
|
||||||
throw std::runtime_error(std::string(__func__) + ": Could not encrypt new descriptors");
|
throw std::runtime_error(std::string(__func__) + ": 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);
|
||||||
|
@ -4391,7 +4391,7 @@ void CWallet::SetActiveScriptPubKeyMan(uint256 id, OutputType type, bool interna
|
||||||
WalletLogPrintf("Setting spkMan to active: id = %s, type = %d, internal = %d\n", id.ToString(), static_cast<int>(type), static_cast<int>(internal));
|
WalletLogPrintf("Setting spkMan to active: id = %s, type = %d, internal = %d\n", id.ToString(), static_cast<int>(type), static_cast<int>(internal));
|
||||||
auto& spk_mans = internal ? m_internal_spk_managers : m_external_spk_managers;
|
auto& spk_mans = 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) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue