Skip to content

Commit eec1566

Browse files
committed
wallet: avoid reuse flags
Add m_avoid_address_reuse flag to coin control object. Add avoid_reuse wallet flag and accompanying strings/caveats.
1 parent 5892809 commit eec1566

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

src/wallet/coincontrol.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ void CCoinControl::SetNull()
1313
fAllowOtherInputs = false;
1414
fAllowWatchOnly = false;
1515
m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS);
16+
m_avoid_address_reuse = false;
1617
setSelected.clear();
1718
m_feerate.reset();
1819
fOverrideFeeRate = false;

src/wallet/coincontrol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class CCoinControl
3434
boost::optional<bool> m_signal_bip125_rbf;
3535
//! Avoid partial use of funds sent to a given address
3636
bool m_avoid_partial_spends;
37+
//! Forbids inclusion of dirty (previously used) addresses
38+
bool m_avoid_address_reuse;
3739
//! Fee estimation mode to control arguments to estimateSmartFee
3840
FeeEstimateMode m_fee_mode;
3941
//! Minimum chain depth value for coin availability

src/wallet/rpcwallet.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@
4747

4848
static const std::string WALLET_ENDPOINT_BASE = "/wallet/";
4949

50+
static inline bool GetAvoidReuseFlag(CWallet * const pwallet, const UniValue& param) {
51+
bool can_avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE);
52+
bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool();
53+
54+
if (avoid_reuse && !can_avoid_reuse) {
55+
throw JSONRPCError(RPC_WALLET_ERROR, "wallet does not have the \"avoid reuse\" feature enabled");
56+
}
57+
58+
return avoid_reuse;
59+
}
60+
5061
bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string& wallet_name)
5162
{
5263
if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) {

src/wallet/wallet.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141

4242
#include <boost/algorithm/string/replace.hpp>
4343

44+
const std::map<uint64_t,std::string> WALLET_FLAG_CAVEATS{
45+
{WALLET_FLAG_AVOID_REUSE,
46+
"You need to rescan the blockchain in order to correctly mark used "
47+
"destinations in the past. Until this is done, some destinations may "
48+
"be considered unused, even if the opposite is the case."
49+
},
50+
};
51+
4452
static const size_t OUTPUT_GROUP_MAX_ENTRIES = 10;
4553

4654
static CCriticalSection cs_wallets;

src/wallet/wallet.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ enum WalletFlags : uint64_t {
120120
// wallet flags in the upper section (> 1 << 31) will lead to not opening the wallet if flag is unknown
121121
// unknown wallet flags in the lower section <= (1 << 31) will be tolerated
122122

123+
// will categorize coins as clean (not reused) and dirty (reused), and handle
124+
// them with privacy considerations in mind
125+
WALLET_FLAG_AVOID_REUSE = (1ULL << 0),
126+
123127
// Indicates that the metadata has already been upgraded to contain key origins
124128
WALLET_FLAG_KEY_ORIGIN_METADATA = (1ULL << 1),
125129

@@ -139,7 +143,20 @@ enum WalletFlags : uint64_t {
139143
WALLET_FLAG_BLANK_WALLET = (1ULL << 33),
140144
};
141145

142-
static constexpr uint64_t KNOWN_WALLET_FLAGS = WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET | WALLET_FLAG_KEY_ORIGIN_METADATA;
146+
static constexpr uint64_t KNOWN_WALLET_FLAGS =
147+
WALLET_FLAG_AVOID_REUSE
148+
| WALLET_FLAG_BLANK_WALLET
149+
| WALLET_FLAG_KEY_ORIGIN_METADATA
150+
| WALLET_FLAG_DISABLE_PRIVATE_KEYS;
151+
152+
static const std::map<std::string,WalletFlags> WALLET_FLAG_MAP{
153+
{"avoid_reuse", WALLET_FLAG_AVOID_REUSE},
154+
{"blank", WALLET_FLAG_BLANK_WALLET},
155+
{"key_origin_metadata", WALLET_FLAG_KEY_ORIGIN_METADATA},
156+
{"disable_private_keys", WALLET_FLAG_DISABLE_PRIVATE_KEYS},
157+
};
158+
159+
extern const std::map<uint64_t,std::string> WALLET_FLAG_CAVEATS;
143160

144161
/** A key from a CWallet's keypool
145162
*

0 commit comments

Comments
 (0)