From 0c59fd9a20dc0c9382342eb38e84b9e22c630567 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 5 May 2022 07:43:08 -0600 Subject: [PATCH 1/2] Add z_get(total)balance to deprecation flags. --- doc/book/src/user/deprecation.md | 2 ++ doc/release-notes.md | 2 ++ src/deprecation.cpp | 4 ++++ src/deprecation.h | 4 ++++ src/wallet/rpcwallet.cpp | 16 +++++++++++++++- 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/book/src/user/deprecation.md b/doc/book/src/user/deprecation.md index 12bd7f2b4..3ecffd74c 100644 --- a/doc/book/src/user/deprecation.md +++ b/doc/book/src/user/deprecation.md @@ -45,6 +45,8 @@ default as of release 5.3.0. conform to the `FullPrivacy` directive in all cases instead of just for transactions involving unified addresses. - `getnewaddress` - The `getnewaddress` RPC method is deprecated. + - `z_getbalance` - The `z_getbalance` RPC method is deprecated. + - `z_gettotalbalance` - The `z_gettotalbalance` RPC method is deprecated. - `z_getnewaddress` - The `z_getnewaddress` RPC method is deprecated. - `addrtype` - The `type` attribute is deprecated in the results of RPC methods that return address metadata. It is recommended that applications diff --git a/doc/release-notes.md b/doc/release-notes.md index 951b77e15..3253717f6 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -37,6 +37,8 @@ be required to permit their continued use: conform to the `FullPrivacy` directive (introduced in 4.7.0) in all cases instead of just for transactions involving unified addresses. - `getnewaddress` - controls availability of the `getnewaddress` RPC method. + - `z_getbalance` - controls availability of the `z_getbalance` RPC method. + - `z_gettotalbalance` - controls availability of the `z_gettotalbalance` RPC method. - `z_getnewaddress` - controls availability of the `z_getnewaddress` RPC method. - `addrtype` - controls availability of the deprecated `type` attribute returned by RPC methods that return address metadata. diff --git a/src/deprecation.cpp b/src/deprecation.cpp index bd8ec28ce..fbc6e82bb 100644 --- a/src/deprecation.cpp +++ b/src/deprecation.cpp @@ -15,6 +15,8 @@ #ifdef ENABLE_WALLET bool fEnableGetNewAddress = true; bool fEnableZGetNewAddress = true; +bool fEnableZGetBalance = true; +bool fEnableZGetTotalBalance = true; bool fEnableLegacyPrivacyStrategy = true; bool fEnableZCRawReceive = true; bool fEnableZCRawJoinSplit = true; @@ -93,6 +95,8 @@ std::optional SetAllowedDeprecatedFeaturesFromCLIArgs() { fEnableLegacyPrivacyStrategy = allowdeprecated.count("legacy_privacy") > 0; fEnableGetNewAddress = allowdeprecated.count("getnewaddress") > 0; fEnableZGetNewAddress = allowdeprecated.count("z_getnewaddress") > 0; + fEnableZGetBalance = allowdeprecated.count("z_getbalance") > 0; + fEnableZGetTotalBalance = allowdeprecated.count("z_gettotalbalance") > 0; fEnableZCRawReceive = allowdeprecated.count("zcrawreceive") > 0; fEnableZCRawJoinSplit = allowdeprecated.count("zcrawjoinsplit") > 0; fEnableZCRawKeygen = allowdeprecated.count("zcrawkeygen") > 0; diff --git a/src/deprecation.h b/src/deprecation.h index a28d37f73..2f8b1a666 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -29,6 +29,8 @@ static const std::set DEFAULT_ALLOW_DEPRECATED{{ "legacy_privacy", "getnewaddress", "z_getnewaddress", + "z_getbalance", + "z_gettotalbalance", "addrtype" #endif }}; @@ -44,6 +46,8 @@ static const std::set DEFAULT_DENY_DEPRECATED{{ #ifdef ENABLE_WALLET extern bool fEnableGetNewAddress; extern bool fEnableZGetNewAddress; +extern bool fEnableZGetBalance; +extern bool fEnableZGetTotalBalance; extern bool fEnableLegacyPrivacyStrategy; extern bool fEnableZCRawReceive; extern bool fEnableZCRawJoinSplit; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index faea46efc..3bb204584 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3990,10 +3990,17 @@ UniValue z_getbalance(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; + if (!fEnableZGetBalance) + throw runtime_error( + "z_getbalance is DEPRECATED and will be removed in a future release\n\n" + "Use z_getbalanceforaccount instead, or restart with `-allowdeprecated=z_getbalance`\n" + "if you require backward compatibility.\n" + "See https://zcash.github.io/zcash/user/deprecation.html for more information."); + if (fHelp || params.size() == 0 || params.size() > 3) throw runtime_error( "z_getbalance \"address\" ( minconf inZat )\n" - "\nDEPRECATED; please use z_getbalanceforviewingkey instead.`\n" + "\nDEPRECATED; please use z_getbalanceforviewingkey or z_getbalanceforaccount instead.`\n" "\nReturns the balance of a taddr or zaddr belonging to the node's wallet.\n" "\nCAUTION: If the wallet has only an incoming viewing key for this address, then spends cannot be" "\ndetected, and so the returned balance may be larger than the actual balance." @@ -4292,6 +4299,13 @@ UniValue z_gettotalbalance(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; + if (!fEnableZGetTotalBalance) + throw runtime_error( + "z_gettotalbalance is DEPRECATED and will be removed in a future release\n\n" + "Use z_getbalanceforaccount instead, or restart with `-allowdeprecated=z_gettotalbalance`\n" + "if you require backward compatibility.\n" + "See https://zcash.github.io/zcash/user/deprecation.html for more information."); + if (fHelp || params.size() > 2) throw runtime_error( "z_gettotalbalance ( minconf includeWatchonly )\n" From 8f2c15cf6f2bdd979e049d9e184fb7a1b9d24a07 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 9 May 2022 10:27:34 -0600 Subject: [PATCH 2/2] Include getbalance in recommendations for z_getbalance and z_gettotalbalance replacements. Co-authored-by: str4d --- src/wallet/rpcwallet.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3bb204584..74c918173 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3993,14 +3993,16 @@ UniValue z_getbalance(const UniValue& params, bool fHelp) if (!fEnableZGetBalance) throw runtime_error( "z_getbalance is DEPRECATED and will be removed in a future release\n\n" - "Use z_getbalanceforaccount instead, or restart with `-allowdeprecated=z_getbalance`\n" + "Use z_getbalanceforaccount, z_getbalanceforviewingkey, or getbalance (for\n" + "legacy transparent balance) instead, or restart with `-allowdeprecated=z_getbalance`\n" "if you require backward compatibility.\n" "See https://zcash.github.io/zcash/user/deprecation.html for more information."); if (fHelp || params.size() == 0 || params.size() > 3) throw runtime_error( "z_getbalance \"address\" ( minconf inZat )\n" - "\nDEPRECATED; please use z_getbalanceforviewingkey or z_getbalanceforaccount instead.`\n" + "\nDEPRECATED; please use z_getbalanceforaccount, z_getbalanceforviewingkey,\n" + "or getbalance (for legacy transparent balance) instead.\n" "\nReturns the balance of a taddr or zaddr belonging to the node's wallet.\n" "\nCAUTION: If the wallet has only an incoming viewing key for this address, then spends cannot be" "\ndetected, and so the returned balance may be larger than the actual balance." @@ -4302,14 +4304,14 @@ UniValue z_gettotalbalance(const UniValue& params, bool fHelp) if (!fEnableZGetTotalBalance) throw runtime_error( "z_gettotalbalance is DEPRECATED and will be removed in a future release\n\n" - "Use z_getbalanceforaccount instead, or restart with `-allowdeprecated=z_gettotalbalance`\n" - "if you require backward compatibility.\n" + "Use z_getbalanceforaccount, or getbalance (for legacy transparent balance) instead, or\n" + "restart with `-allowdeprecated=z_gettotalbalance if you require backward compatibility.\n" "See https://zcash.github.io/zcash/user/deprecation.html for more information."); if (fHelp || params.size() > 2) throw runtime_error( "z_gettotalbalance ( minconf includeWatchonly )\n" - "\nDEPRECATED. Please use the z_getbalanceforaccount RPC instead.\n" + "\nDEPRECATED. Please use z_getbalanceforaccount or getbalance (for legacy transparent balance) instead.\n" "\nReturn the total value of funds stored in the node's wallet.\n" "\nCAUTION: If the wallet contains any addresses for which it only has incoming viewing keys," "\nthe returned private balance may be larger than the actual balance, because spends cannot"