mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-15 09:09:46 +02:00
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:
@@ -26,28 +26,30 @@ std::unique_ptr<ExternalSignerScriptPubKeyMan> ExternalSignerScriptPubKeyMan::Lo
|
||||
return std::unique_ptr<ExternalSignerScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(storage, descriptor, keypool_size, keys, ckeys));
|
||||
}
|
||||
|
||||
bool ExternalSignerScriptPubKeyMan::SetupDescriptor(WalletBatch& batch, std::unique_ptr<Descriptor> desc)
|
||||
std::unique_ptr<ExternalSignerScriptPubKeyMan> ExternalSignerScriptPubKeyMan::CreateNew(WalletStorage& storage, WalletBatch& batch, int64_t keypool_size, std::unique_ptr<Descriptor> desc)
|
||||
{
|
||||
LOCK(cs_desc_man);
|
||||
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
|
||||
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER));
|
||||
auto spkm = std::unique_ptr<ExternalSignerScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(storage, keypool_size));
|
||||
|
||||
LOCK(spkm->cs_desc_man);
|
||||
assert(storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
|
||||
assert(storage.IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER));
|
||||
|
||||
int64_t creation_time = GetTime();
|
||||
|
||||
// Make the descriptor
|
||||
WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0);
|
||||
m_wallet_descriptor = w_desc;
|
||||
spkm->m_wallet_descriptor = w_desc;
|
||||
|
||||
// Store the descriptor
|
||||
if (!batch.WriteDescriptor(GetID(), m_wallet_descriptor)) {
|
||||
if (!batch.WriteDescriptor(spkm->GetID(), spkm->m_wallet_descriptor)) {
|
||||
throw std::runtime_error(std::string(__func__) + ": writing descriptor failed");
|
||||
}
|
||||
|
||||
// TopUp
|
||||
TopUpWithDB(batch);
|
||||
spkm->TopUpWithDB(batch);
|
||||
|
||||
m_storage.UnsetBlankWalletFlag(batch);
|
||||
return true;
|
||||
storage.UnsetBlankWalletFlag(batch);
|
||||
return spkm;
|
||||
}
|
||||
|
||||
util::Result<ExternalSigner> ExternalSignerScriptPubKeyMan::GetExternalSigner() {
|
||||
|
||||
@@ -16,21 +16,18 @@ namespace wallet {
|
||||
class ExternalSignerScriptPubKeyMan : public DescriptorScriptPubKeyMan
|
||||
{
|
||||
private:
|
||||
//! Create an ExternalSPKM from existing wallet data
|
||||
ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor, int64_t keypool_size, const KeyMap& keys, const CryptedKeyMap& ckeys)
|
||||
: DescriptorScriptPubKeyMan(storage, descriptor, keypool_size, keys, ckeys)
|
||||
{}
|
||||
|
||||
ExternalSignerScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size)
|
||||
: DescriptorScriptPubKeyMan(storage, keypool_size)
|
||||
{}
|
||||
|
||||
public:
|
||||
ExternalSignerScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size)
|
||||
: DescriptorScriptPubKeyMan(storage, keypool_size)
|
||||
{}
|
||||
|
||||
static std::unique_ptr<ExternalSignerScriptPubKeyMan> LoadFromStorage(WalletStorage& storage, WalletDescriptor& descriptor, int64_t keypool_size, const KeyMap& keys, const CryptedKeyMap& ckeys);
|
||||
|
||||
/** 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 std::unique_ptr<ExternalSignerScriptPubKeyMan> CreateNew(WalletStorage& storage, WalletBatch& batch, int64_t keypool_size, std::unique_ptr<Descriptor> desc);
|
||||
|
||||
static util::Result<ExternalSigner> GetExternalSigner();
|
||||
|
||||
|
||||
@@ -3634,8 +3634,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
|
||||
continue;
|
||||
}
|
||||
OutputType t = *desc->GetOutputType();
|
||||
auto spk_manager = std::unique_ptr<ExternalSignerScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this, m_keypool_size));
|
||||
spk_manager->SetupDescriptor(batch, std::move(desc));
|
||||
auto spk_manager = ExternalSignerScriptPubKeyMan::CreateNew(*this, batch, m_keypool_size, std::move(desc));
|
||||
uint256 id = spk_manager->GetID();
|
||||
AddScriptPubKeyMan(id, std::move(spk_manager));
|
||||
AddActiveScriptPubKeyManWithDb(batch, id, t, internal);
|
||||
|
||||
Reference in New Issue
Block a user