mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
wallet: Setup new autogenerated descriptors on construction
Instead of having a caller use SetupDescriptorGeneration, just have a constructor that takes those arguments and sets up the descriptor with the autogenerated key.
This commit is contained in:
parent
53caaec366
commit
92a5088a36
3 changed files with 18 additions and 9 deletions
|
@ -2080,6 +2080,13 @@ DescriptorScriptPubKeyMan::DescriptorScriptPubKeyMan(WalletStorage& storage, con
|
|||
SetCache(m_wallet_descriptor.cache);
|
||||
}
|
||||
|
||||
DescriptorScriptPubKeyMan::DescriptorScriptPubKeyMan(WalletStorage& storage, WalletBatch& batch, int64_t keypool_size, const CExtKey& master_key, OutputType addr_type, bool internal)
|
||||
: ScriptPubKeyMan(storage),
|
||||
m_keypool_size(keypool_size)
|
||||
{
|
||||
SetupDescriptorGeneration(batch, master_key, addr_type, internal);
|
||||
}
|
||||
|
||||
util::Result<CTxDestination> DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type)
|
||||
{
|
||||
// Returns true if this descriptor supports getting new addresses. Conditions where we may be unable to fetch them (e.g. locked) are caught later
|
||||
|
|
|
@ -617,7 +617,15 @@ private:
|
|||
void AddDescriptorKey(const CKey& key, const CPubKey &pubkey);
|
||||
void UpdateWithSigningProvider(WalletBatch& batch, const FlatSigningProvider& signing_provider) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
||||
|
||||
//! Setup descriptors based on the given CExtkey
|
||||
bool SetupDescriptorGeneration(WalletBatch& batch, const CExtKey& master_key, OutputType addr_type, bool internal);
|
||||
|
||||
protected:
|
||||
DescriptorScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size)
|
||||
: ScriptPubKeyMan(storage),
|
||||
m_keypool_size(keypool_size)
|
||||
{}
|
||||
|
||||
WalletDescriptor m_wallet_descriptor GUARDED_BY(cs_desc_man);
|
||||
|
||||
//! Same as 'TopUp' but designed for use within a batch transaction context
|
||||
|
@ -629,10 +637,8 @@ public:
|
|||
DescriptorScriptPubKeyMan(WalletBatch& batch, WalletStorage& storage, WalletDescriptor& descriptor, int64_t keypool_size, const FlatSigningProvider& provider);
|
||||
//! Create a DescriptorScriptPubKeyMan from existing data (i.e. during loading)
|
||||
DescriptorScriptPubKeyMan(WalletStorage& storage, const uint256& id, WalletDescriptor& descriptor, int64_t keypool_size, const KeyMap& keys, const CryptedKeyMap& ckeys);
|
||||
DescriptorScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size)
|
||||
: ScriptPubKeyMan(storage),
|
||||
m_keypool_size(keypool_size)
|
||||
{}
|
||||
//! Create an automatically generated DescriptorScriptPubKeyMan
|
||||
DescriptorScriptPubKeyMan(WalletStorage& storage, WalletBatch& batch, int64_t keypool_size, const CExtKey& master_key, OutputType addr_type, bool internal);
|
||||
|
||||
mutable RecursiveMutex cs_desc_man;
|
||||
|
||||
|
@ -655,9 +661,6 @@ public:
|
|||
|
||||
bool IsHDEnabled() const override;
|
||||
|
||||
//! Setup descriptors based on the given CExtkey
|
||||
bool SetupDescriptorGeneration(WalletBatch& batch, const CExtKey& master_key, OutputType addr_type, bool internal);
|
||||
|
||||
bool HavePrivateKeys() const override;
|
||||
bool HasPrivKey(const CKeyID& keyid) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
||||
//! Retrieve the particular key if it is available. Returns nullopt if the key is not in the wallet, or if the wallet is locked.
|
||||
|
|
|
@ -3684,7 +3684,7 @@ void CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc,
|
|||
DescriptorScriptPubKeyMan& CWallet::SetupDescriptorScriptPubKeyMan(WalletBatch& batch, const CExtKey& master_key, const OutputType& output_type, bool internal)
|
||||
{
|
||||
AssertLockHeld(cs_wallet);
|
||||
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, m_keypool_size));
|
||||
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, batch, m_keypool_size, master_key, output_type, internal));
|
||||
if (IsCrypted()) {
|
||||
if (IsLocked()) {
|
||||
throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors");
|
||||
|
@ -3693,7 +3693,6 @@ DescriptorScriptPubKeyMan& CWallet::SetupDescriptorScriptPubKeyMan(WalletBatch&
|
|||
throw std::runtime_error(std::string(__func__) + ": Could not encrypt new descriptors");
|
||||
}
|
||||
}
|
||||
spk_manager->SetupDescriptorGeneration(batch, master_key, output_type, internal);
|
||||
DescriptorScriptPubKeyMan* out = spk_manager.get();
|
||||
uint256 id = spk_manager->GetID();
|
||||
AddScriptPubKeyMan(id, std::move(spk_manager));
|
||||
|
|
Loading…
Reference in a new issue