mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-13 11:40:42 +02:00
wallet: allow external_signer flag toggle
Github-Pull: #21928 Rebased-From: 1af208318067843cc1adbc352c3332ed68ebf391
This commit is contained in:
parent
bbbf89a9de
commit
dc97030bfc
@ -27,6 +27,8 @@ static const std::map<uint64_t, std::string> WALLET_FLAG_CAVEATS{
|
|||||||
"You need to rescan the blockchain in order to correctly mark used "
|
"You need to rescan the blockchain in order to correctly mark used "
|
||||||
"destinations in the past. Until this is done, some destinations may "
|
"destinations in the past. Until this is done, some destinations may "
|
||||||
"be considered unused, even if the opposite is the case."},
|
"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*/
|
/** 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);
|
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)) {
|
if (!(flag & MUTABLE_WALLET_FLAGS)) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Wallet flag is immutable: %s", flag_str));
|
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Wallet flag is immutable: %s", flag_str));
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,7 @@ static constexpr uint64_t KNOWN_WALLET_FLAGS =
|
|||||||
| WALLET_FLAG_EXTERNAL_SIGNER;
|
| WALLET_FLAG_EXTERNAL_SIGNER;
|
||||||
|
|
||||||
static constexpr uint64_t MUTABLE_WALLET_FLAGS =
|
static constexpr uint64_t MUTABLE_WALLET_FLAGS =
|
||||||
|
WALLET_FLAG_EXTERNAL_SIGNER |
|
||||||
WALLET_FLAG_AVOID_REUSE;
|
WALLET_FLAG_AVOID_REUSE;
|
||||||
|
|
||||||
static const std::map<std::string,WalletFlags> WALLET_FLAG_MAP{
|
static const std::map<std::string,WalletFlags> WALLET_FLAG_MAP{
|
||||||
|
@ -91,7 +91,14 @@ class WalletSignerTest(BitcoinTestFramework):
|
|||||||
self.nodes[1].createwallet(wallet_name='not_hww', disable_private_keys=True, descriptors=True, external_signer=False)
|
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')
|
not_hww = self.nodes[1].get_wallet_rpc('not_hww')
|
||||||
assert_equal(not_hww.getwalletinfo()["external_signer"], False)
|
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)
|
# 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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user