wallet: Construct ExternalSignerSPKM with the new descriptor

Instead of constructing then setting the descriptor with
SetupDescriptor, just pass in that descriptor to the constructor.
This commit is contained in:
Ava Chow 2024-02-20 11:48:44 -05:00
parent dc4c61f7ec
commit 39db554fe0
3 changed files with 8 additions and 14 deletions

View file

@ -21,7 +21,8 @@
using common::PSBTError; using common::PSBTError;
namespace wallet { namespace wallet {
bool ExternalSignerScriptPubKeyMan::SetupDescriptor(WalletBatch& batch, std::unique_ptr<Descriptor> desc) ExternalSignerScriptPubKeyMan::ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletBatch& batch, int64_t keypool_size, std::unique_ptr<Descriptor> desc)
: DescriptorScriptPubKeyMan(storage, keypool_size)
{ {
LOCK(cs_desc_man); LOCK(cs_desc_man);
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)); assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
@ -42,7 +43,6 @@ bool ExternalSignerScriptPubKeyMan::SetupDescriptor(WalletBatch& batch, std::uni
TopUpWithDB(batch); TopUpWithDB(batch);
m_storage.UnsetBlankWalletFlag(batch); m_storage.UnsetBlankWalletFlag(batch);
return true;
} }
ExternalSigner ExternalSignerScriptPubKeyMan::GetExternalSigner() { ExternalSigner ExternalSignerScriptPubKeyMan::GetExternalSigner() {

View file

@ -15,17 +15,12 @@ namespace wallet {
class ExternalSignerScriptPubKeyMan : public DescriptorScriptPubKeyMan class ExternalSignerScriptPubKeyMan : public DescriptorScriptPubKeyMan
{ {
public: public:
//! Create an ExternalSPKM from existing wallet data
ExternalSignerScriptPubKeyMan(WalletStorage& storage, const uint256& id, WalletDescriptor& descriptor, int64_t keypool_size, const KeyMap& keys, const CryptedKeyMap& ckeys) ExternalSignerScriptPubKeyMan(WalletStorage& storage, const uint256& id, WalletDescriptor& descriptor, int64_t keypool_size, const KeyMap& keys, const CryptedKeyMap& ckeys)
: DescriptorScriptPubKeyMan(storage, id, descriptor, keypool_size, keys, ckeys) : DescriptorScriptPubKeyMan(storage, id, descriptor, keypool_size, keys, ckeys)
{} {}
ExternalSignerScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) //! Create a new ExternalSPKM from just a descriptor
: DescriptorScriptPubKeyMan(storage, keypool_size) ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletBatch& batch, int64_t keypool_size, std::unique_ptr<Descriptor> desc);
{}
/** Provide a descriptor at setup time
* Returns false if already setup or setup fails, true if setup is successful
*/
bool SetupDescriptor(WalletBatch& batch, std::unique_ptr<Descriptor>desc);
static ExternalSigner GetExternalSigner(); static ExternalSigner GetExternalSigner();

View file

@ -3800,8 +3800,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
continue; continue;
} }
OutputType t = *desc->GetOutputType(); OutputType t = *desc->GetOutputType();
auto spk_manager = std::unique_ptr<ExternalSignerScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this, m_keypool_size)); auto spk_manager = std::unique_ptr<ExternalSignerScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this, batch, m_keypool_size, std::move(desc)));
spk_manager->SetupDescriptor(batch, std::move(desc));
uint256 id = spk_manager->GetID(); uint256 id = spk_manager->GetID();
AddScriptPubKeyMan(id, std::move(spk_manager)); AddScriptPubKeyMan(id, std::move(spk_manager));
AddActiveScriptPubKeyManWithDb(batch, id, t, internal); AddActiveScriptPubKeyManWithDb(batch, id, t, internal);