mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 22:42:04 +01:00
wallet: add ExternalSignerScriptPubKeyMan
This commit is contained in:
parent
157ea7c614
commit
8ce7767071
5 changed files with 81 additions and 4 deletions
|
@ -266,6 +266,7 @@ BITCOIN_CORE_H = \
|
||||||
wallet/db.h \
|
wallet/db.h \
|
||||||
wallet/dump.h \
|
wallet/dump.h \
|
||||||
wallet/external_signer.h \
|
wallet/external_signer.h \
|
||||||
|
wallet/external_signer_scriptpubkeyman.h \
|
||||||
wallet/feebumper.h \
|
wallet/feebumper.h \
|
||||||
wallet/fees.h \
|
wallet/fees.h \
|
||||||
wallet/ismine.h \
|
wallet/ismine.h \
|
||||||
|
@ -380,6 +381,7 @@ libbitcoin_wallet_a_SOURCES = \
|
||||||
wallet/crypter.cpp \
|
wallet/crypter.cpp \
|
||||||
wallet/db.cpp \
|
wallet/db.cpp \
|
||||||
wallet/dump.cpp \
|
wallet/dump.cpp \
|
||||||
|
wallet/external_signer_scriptpubkeyman.cpp \
|
||||||
wallet/external_signer.cpp \
|
wallet/external_signer.cpp \
|
||||||
wallet/feebumper.cpp \
|
wallet/feebumper.cpp \
|
||||||
wallet/fees.cpp \
|
wallet/fees.cpp \
|
||||||
|
|
36
src/wallet/external_signer_scriptpubkeyman.cpp
Normal file
36
src/wallet/external_signer_scriptpubkeyman.cpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright (c) 2020 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <chainparams.h>
|
||||||
|
#include <wallet/external_signer.h>
|
||||||
|
#include <wallet/external_signer_scriptpubkeyman.h>
|
||||||
|
|
||||||
|
#ifdef ENABLE_EXTERNAL_SIGNER
|
||||||
|
|
||||||
|
bool ExternalSignerScriptPubKeyMan::SetupDescriptor(std::unique_ptr<Descriptor> desc)
|
||||||
|
{
|
||||||
|
LOCK(cs_desc_man);
|
||||||
|
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
|
||||||
|
assert(m_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;
|
||||||
|
|
||||||
|
// Store the descriptor
|
||||||
|
WalletBatch batch(m_storage.GetDatabase());
|
||||||
|
if (!batch.WriteDescriptor(GetID(), m_wallet_descriptor)) {
|
||||||
|
throw std::runtime_error(std::string(__func__) + ": writing descriptor failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TopUp
|
||||||
|
TopUp();
|
||||||
|
|
||||||
|
m_storage.UnsetBlankWalletFlag(batch);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
28
src/wallet/external_signer_scriptpubkeyman.h
Normal file
28
src/wallet/external_signer_scriptpubkeyman.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (c) 2019-2020 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_WALLET_EXTERNAL_SIGNER_SCRIPTPUBKEYMAN_H
|
||||||
|
#define BITCOIN_WALLET_EXTERNAL_SIGNER_SCRIPTPUBKEYMAN_H
|
||||||
|
|
||||||
|
#ifdef ENABLE_EXTERNAL_SIGNER
|
||||||
|
#include <wallet/scriptpubkeyman.h>
|
||||||
|
|
||||||
|
class ExternalSignerScriptPubKeyMan : public DescriptorScriptPubKeyMan
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor)
|
||||||
|
: DescriptorScriptPubKeyMan(storage, descriptor)
|
||||||
|
{}
|
||||||
|
ExternalSignerScriptPubKeyMan(WalletStorage& storage, bool internal)
|
||||||
|
: DescriptorScriptPubKeyMan(storage, internal)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/** Provide a descriptor at setup time
|
||||||
|
* Returns false if already setup or setup fails, true if setup is successful
|
||||||
|
*/
|
||||||
|
bool SetupDescriptor(std::unique_ptr<Descriptor>desc);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // BITCOIN_WALLET_EXTERNAL_SIGNER_SCRIPTPUBKEYMAN_H
|
|
@ -517,8 +517,6 @@ public:
|
||||||
class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
|
class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
WalletDescriptor m_wallet_descriptor GUARDED_BY(cs_desc_man);
|
|
||||||
|
|
||||||
using ScriptPubKeyMap = std::map<CScript, int32_t>; // Map of scripts to descriptor range index
|
using ScriptPubKeyMap = std::map<CScript, int32_t>; // Map of scripts to descriptor range index
|
||||||
using PubKeyMap = std::map<CPubKey, int32_t>; // Map of pubkeys involved in scripts to descriptor range index
|
using PubKeyMap = std::map<CPubKey, int32_t>; // Map of pubkeys involved in scripts to descriptor range index
|
||||||
using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
|
using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
|
||||||
|
@ -547,6 +545,9 @@ private:
|
||||||
// Fetch the SigningProvider for a given index and optionally include private keys. Called by the above functions.
|
// Fetch the SigningProvider for a given index and optionally include private keys. Called by the above functions.
|
||||||
std::unique_ptr<FlatSigningProvider> GetSigningProvider(int32_t index, bool include_private = false) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
std::unique_ptr<FlatSigningProvider> GetSigningProvider(int32_t index, bool include_private = false) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
WalletDescriptor m_wallet_descriptor GUARDED_BY(cs_desc_man);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DescriptorScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor)
|
DescriptorScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor)
|
||||||
: ScriptPubKeyMan(storage),
|
: ScriptPubKeyMan(storage),
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <wallet/coincontrol.h>
|
#include <wallet/coincontrol.h>
|
||||||
#include <wallet/fees.h>
|
#include <wallet/fees.h>
|
||||||
|
#include <wallet/external_signer_scriptpubkeyman.h>
|
||||||
|
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
|
@ -4457,8 +4458,17 @@ void CWallet::ConnectScriptPubKeyManNotifiers()
|
||||||
|
|
||||||
void CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc)
|
void CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc)
|
||||||
{
|
{
|
||||||
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, desc));
|
if (IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
|
||||||
m_spk_managers[id] = std::move(spk_manager);
|
#ifdef ENABLE_EXTERNAL_SIGNER
|
||||||
|
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this, desc));
|
||||||
|
m_spk_managers[id] = std::move(spk_manager);
|
||||||
|
#else
|
||||||
|
throw std::runtime_error(std::string(__func__) + ": Configure with --enable-external-signer to use external signer wallets");
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, desc));
|
||||||
|
m_spk_managers[id] = std::move(spk_manager);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallet::SetupDescriptorScriptPubKeyMans()
|
void CWallet::SetupDescriptorScriptPubKeyMans()
|
||||||
|
|
Loading…
Add table
Reference in a new issue