diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index ea3507bc75..74c2272177 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -27,6 +27,8 @@ static const std::map WALLET_FLAG_CAVEATS{ "You need to rescan the blockchain in order to correctly mark used " "destinations in the past. Until this is done, some destinations may " "be considered unused, even if the opposite is the case."}, + {WALLET_FLAG_EXTERNAL_SIGNER, + "The ability to toggle this flag may be removed in a future update."}, }; /** Checks if a CKey is in the given CWallet compressed or otherwise*/ @@ -302,6 +304,16 @@ static RPCHelpMan setwalletflag() auto flag = WALLET_FLAG_MAP.at(flag_str); + if (flag == WALLET_FLAG_EXTERNAL_SIGNER) { +#ifdef ENABLE_EXTERNAL_SIGNER + if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) || !pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { + throw JSONRPCError(RPC_WALLET_ERROR, "This flag can only be set on a watch-only descriptor wallet"); + } +#else + throw JSONRPCError(RPC_WALLET_ERROR, "Compiled without external signing support (required for external signing)"); +#endif + } + if (!(flag & MUTABLE_WALLET_FLAGS)) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Wallet flag is immutable: %s", flag_str)); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 581a6bd9cb..3a1ce69678 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -134,6 +134,7 @@ static constexpr uint64_t KNOWN_WALLET_FLAGS = | WALLET_FLAG_EXTERNAL_SIGNER; static constexpr uint64_t MUTABLE_WALLET_FLAGS = + WALLET_FLAG_EXTERNAL_SIGNER | WALLET_FLAG_AVOID_REUSE; static const std::map WALLET_FLAG_MAP{ diff --git a/test/functional/wallet_signer.py b/test/functional/wallet_signer.py index 8d25044e43..a95a99d679 100755 --- a/test/functional/wallet_signer.py +++ b/test/functional/wallet_signer.py @@ -91,7 +91,14 @@ class WalletSignerTest(BitcoinTestFramework): self.nodes[1].createwallet(wallet_name='not_hww', disable_private_keys=True, descriptors=True, external_signer=False) not_hww = self.nodes[1].get_wallet_rpc('not_hww') assert_equal(not_hww.getwalletinfo()["external_signer"], False) - assert_raises_rpc_error(-8, "Wallet flag is immutable: external_signer", not_hww.setwalletflag, "external_signer", True) + + # Flag can be set + not_hww.setwalletflag("external_signer", True) + assert_equal(not_hww.getwalletinfo()["external_signer"], True) + + # Flag can be unset + not_hww.setwalletflag("external_signer", False) + assert_equal(not_hww.getwalletinfo()["external_signer"], False) # assert_raises_rpc_error(-4, "Multiple signers found, please specify which to use", wallet_name='not_hww', disable_private_keys=True, descriptors=True, external_signer=True)