Skip to content

Commit 8ce7767

Browse files
committed
wallet: add ExternalSignerScriptPubKeyMan
1 parent 157ea7c commit 8ce7767

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ BITCOIN_CORE_H = \
266266
wallet/db.h \
267267
wallet/dump.h \
268268
wallet/external_signer.h \
269+
wallet/external_signer_scriptpubkeyman.h \
269270
wallet/feebumper.h \
270271
wallet/fees.h \
271272
wallet/ismine.h \
@@ -380,6 +381,7 @@ libbitcoin_wallet_a_SOURCES = \
380381
wallet/crypter.cpp \
381382
wallet/db.cpp \
382383
wallet/dump.cpp \
384+
wallet/external_signer_scriptpubkeyman.cpp \
383385
wallet/external_signer.cpp \
384386
wallet/feebumper.cpp \
385387
wallet/fees.cpp \
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2020 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <chainparams.h>
6+
#include <wallet/external_signer.h>
7+
#include <wallet/external_signer_scriptpubkeyman.h>
8+
9+
#ifdef ENABLE_EXTERNAL_SIGNER
10+
11+
bool ExternalSignerScriptPubKeyMan::SetupDescriptor(std::unique_ptr<Descriptor> desc)
12+
{
13+
LOCK(cs_desc_man);
14+
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
15+
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER));
16+
17+
int64_t creation_time = GetTime();
18+
19+
// Make the descriptor
20+
WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0);
21+
m_wallet_descriptor = w_desc;
22+
23+
// Store the descriptor
24+
WalletBatch batch(m_storage.GetDatabase());
25+
if (!batch.WriteDescriptor(GetID(), m_wallet_descriptor)) {
26+
throw std::runtime_error(std::string(__func__) + ": writing descriptor failed");
27+
}
28+
29+
// TopUp
30+
TopUp();
31+
32+
m_storage.UnsetBlankWalletFlag(batch);
33+
return true;
34+
}
35+
36+
#endif
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2019-2020 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_WALLET_EXTERNAL_SIGNER_SCRIPTPUBKEYMAN_H
6+
#define BITCOIN_WALLET_EXTERNAL_SIGNER_SCRIPTPUBKEYMAN_H
7+
8+
#ifdef ENABLE_EXTERNAL_SIGNER
9+
#include <wallet/scriptpubkeyman.h>
10+
11+
class ExternalSignerScriptPubKeyMan : public DescriptorScriptPubKeyMan
12+
{
13+
public:
14+
ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor)
15+
: DescriptorScriptPubKeyMan(storage, descriptor)
16+
{}
17+
ExternalSignerScriptPubKeyMan(WalletStorage& storage, bool internal)
18+
: DescriptorScriptPubKeyMan(storage, internal)
19+
{}
20+
21+
/** Provide a descriptor at setup time
22+
* Returns false if already setup or setup fails, true if setup is successful
23+
*/
24+
bool SetupDescriptor(std::unique_ptr<Descriptor>desc);
25+
};
26+
#endif
27+
28+
#endif // BITCOIN_WALLET_EXTERNAL_SIGNER_SCRIPTPUBKEYMAN_H

src/wallet/scriptpubkeyman.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,6 @@ class LegacySigningProvider : public SigningProvider
517517
class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
518518
{
519519
private:
520-
WalletDescriptor m_wallet_descriptor GUARDED_BY(cs_desc_man);
521-
522520
using ScriptPubKeyMap = std::map<CScript, int32_t>; // Map of scripts to descriptor range index
523521
using PubKeyMap = std::map<CPubKey, int32_t>; // Map of pubkeys involved in scripts to descriptor range index
524522
using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
@@ -547,6 +545,9 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
547545
// Fetch the SigningProvider for a given index and optionally include private keys. Called by the above functions.
548546
std::unique_ptr<FlatSigningProvider> GetSigningProvider(int32_t index, bool include_private = false) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
549547

548+
protected:
549+
WalletDescriptor m_wallet_descriptor GUARDED_BY(cs_desc_man);
550+
550551
public:
551552
DescriptorScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor)
552553
: ScriptPubKeyMan(storage),

src/wallet/wallet.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <util/translation.h>
3333
#include <wallet/coincontrol.h>
3434
#include <wallet/fees.h>
35+
#include <wallet/external_signer_scriptpubkeyman.h>
3536

3637
#include <univalue.h>
3738

@@ -4457,8 +4458,17 @@ void CWallet::ConnectScriptPubKeyManNotifiers()
44574458

44584459
void CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc)
44594460
{
4460-
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, desc));
4461-
m_spk_managers[id] = std::move(spk_manager);
4461+
if (IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
4462+
#ifdef ENABLE_EXTERNAL_SIGNER
4463+
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this, desc));
4464+
m_spk_managers[id] = std::move(spk_manager);
4465+
#else
4466+
throw std::runtime_error(std::string(__func__) + ": Configure with --enable-external-signer to use external signer wallets");
4467+
#endif
4468+
} else {
4469+
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, desc));
4470+
m_spk_managers[id] = std::move(spk_manager);
4471+
}
44624472
}
44634473

44644474
void CWallet::SetupDescriptorScriptPubKeyMans()

0 commit comments

Comments
 (0)