Skip to content

Commit 8cf543f

Browse files
committed
wallet: add -signer argument for external signer command
Create basic ExternalSigner class with contructor. A Signer(<cmd>) is added to CWallet on load if -signer=<cmd> is set.
1 parent f7eb7ec commit 8cf543f

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ BITCOIN_CORE_H = \
265265
wallet/crypter.h \
266266
wallet/db.h \
267267
wallet/dump.h \
268+
wallet/external_signer.h \
268269
wallet/feebumper.h \
269270
wallet/fees.h \
270271
wallet/ismine.h \
@@ -379,6 +380,7 @@ libbitcoin_wallet_a_SOURCES = \
379380
wallet/crypter.cpp \
380381
wallet/db.cpp \
381382
wallet/dump.cpp \
383+
wallet/external_signer.cpp \
382384
wallet/feebumper.cpp \
383385
wallet/fees.cpp \
384386
wallet/interfaces.cpp \

src/dummywallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const
3838
"-paytxfee=<amt>",
3939
"-rescan",
4040
"-salvagewallet",
41+
"-signer=<cmd>",
4142
"-spendzeroconfchange",
4243
"-txconfirmtarget=<n>",
4344
"-wallet=<path>",

src/wallet/external_signer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2018-2021 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 <wallet/external_signer.h>
6+
#include <util/system.h>
7+
8+
ExternalSigner::ExternalSigner(const std::string& command, const std::string& fingerprint): m_command(command), m_fingerprint(fingerprint) {}

src/wallet/external_signer.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2018-2021 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_H
6+
#define BITCOIN_WALLET_EXTERNAL_SIGNER_H
7+
8+
#include <stdexcept>
9+
#include <string>
10+
#include <univalue.h>
11+
12+
class ExternalSignerException : public std::runtime_error {
13+
public:
14+
using std::runtime_error::runtime_error;
15+
};
16+
17+
//! Enables interaction with an external signing device or service, such as
18+
//! a hardware wallet. See doc/external-signer.md
19+
class ExternalSigner
20+
{
21+
private:
22+
//! The command which handles interaction with the external signer.
23+
std::string m_command;
24+
25+
public:
26+
//! @param[in] command the command which handles interaction with the external signer
27+
//! @param[in] fingerprint master key fingerprint of the signer
28+
ExternalSigner(const std::string& command, const std::string& fingerprint);
29+
30+
//! Master key fingerprint of the signer
31+
std::string m_fingerprint;
32+
};
33+
34+
#endif // BITCOIN_WALLET_EXTERNAL_SIGNER_H

src/wallet/init.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
6161
argsman.AddArg("-paytxfee=<amt>", strprintf("Fee (in %s/kB) to add to transactions you send (default: %s)",
6262
CURRENCY_UNIT, FormatMoney(CFeeRate{DEFAULT_PAY_TX_FEE}.GetFeePerK())), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
6363
argsman.AddArg("-rescan", "Rescan the block chain for missing wallet transactions on startup", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
64+
#ifdef ENABLE_EXTERNAL_SIGNER
65+
argsman.AddArg("-signer=<cmd>", "External signing tool, see docs/external-signer.md", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
66+
#endif
6467
argsman.AddArg("-spendzeroconfchange", strprintf("Spend unconfirmed change when sending transactions (default: %u)", DEFAULT_SPEND_ZEROCONF_CHANGE), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
6568
argsman.AddArg("-txconfirmtarget=<n>", strprintf("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)", DEFAULT_TX_CONFIRM_TARGET), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
6669
argsman.AddArg("-wallet=<path>", "Specify wallet path to load at startup. Can be used multiple times to load multiple wallets. Path is to a directory containing wallet data and log files. If the path is not absolute, it is interpreted relative to <walletdir>. This only loads existing wallets and does not create new ones. For backwards compatibility this also accepts names of existing top-level data files in <walletdir>.", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET);

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <wallet/coinselection.h>
2323
#include <wallet/crypter.h>
2424
#include <wallet/scriptpubkeyman.h>
25+
#include <wallet/external_signer.h>
2526
#include <wallet/walletdb.h>
2627
#include <wallet/walletutil.h>
2728

@@ -95,7 +96,6 @@ constexpr CAmount DEFAULT_TRANSACTION_MAXFEE{COIN / 10};
9596
constexpr CAmount HIGH_TX_FEE_PER_KB{COIN / 100};
9697
//! -maxtxfee will warn if called with a higher fee than this amount (in satoshis)
9798
constexpr CAmount HIGH_MAX_TX_FEE{100 * HIGH_TX_FEE_PER_KB};
98-
9999
//! Pre-calculated constants for input size estimation in *virtual size*
100100
static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE = 91;
101101

0 commit comments

Comments
 (0)