From a43f5daff8819520da32ea7569033625b8ca656f Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Fri, 13 Mar 2020 08:13:33 -0300 Subject: [PATCH] add -lightwalletd experimental option --- qa/rpc-tests/addressindex.py | 46 +++++++++++++++++++++++------------ src/experimental_features.cpp | 6 +++++ src/experimental_features.h | 1 + src/gtest/test_rpc.cpp | 41 +++++++++++++++++++++++++++++++ src/init.cpp | 8 ++++++ src/main.cpp | 32 +++++++++++++++++------- src/rpc/blockchain.cpp | 12 ++++----- src/rpc/misc.cpp | 28 ++++++++++----------- src/rpc/server.cpp | 32 ++++++++++++++++++------ src/rpc/server.h | 2 +- src/wallet/rpcdisclosure.cpp | 4 +-- src/wallet/rpcwallet.cpp | 2 +- 12 files changed, 159 insertions(+), 55 deletions(-) diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index e0ce64155..5e87fc65d 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -3,14 +3,14 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or https://www.opensource.org/licenses/mit-license.php . # -# Test addressindex generation and fetching for insightexplorer +# Test addressindex generation and fetching for insightexplorer or lightwalletd # # RPCs tested here: # # getaddresstxids # getaddressbalance # getaddressdeltas -# getaddressutxos +# getaddressutxos - available only for insightexplorer # getaddressmempool @@ -22,7 +22,7 @@ from test_framework.util import ( start_nodes, stop_nodes, connect_nodes, - wait_bitcoinds, + wait_bitcoinds ) from test_framework.script import ( @@ -46,14 +46,18 @@ class AddressIndexTest(BitcoinTestFramework): def setup_chain(self): print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 3) + initialize_chain_clean(self.options.tmpdir, 4) def setup_network(self): # -insightexplorer causes addressindex to be enabled (fAddressIndex = true) - args = ('-debug', '-txindex', '-experimentalfeatures', '-insightexplorer') - self.nodes = start_nodes(3, self.options.tmpdir, [args] * 3) + args_insight = ('-debug', '-txindex', '-experimentalfeatures', '-insightexplorer') + # -lightwallet also causes addressindex to be enabled + args_lightwallet = ('-debug', '-txindex', '-experimentalfeatures', '-lightwalletd') + self.nodes = start_nodes(4, self.options.tmpdir, [args_insight] * 3 + [args_lightwallet]) + connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 2) + connect_nodes(self.nodes[0], 3) # node3 is only for testing lightwalletd self.is_network_split = False self.sync_all() @@ -120,6 +124,9 @@ class AddressIndexTest(BitcoinTestFramework): assert_equal(len(self.nodes[1].getaddresstxids(addr_p2pkh)), 105) assert_equal(len(self.nodes[1].getaddresstxids(addr_p2sh)), 105) + # test getaddresstxids for lightwalletd + assert_equal(len(self.nodes[3].getaddresstxids(addr_p2pkh)), 105) + assert_equal(len(self.nodes[3].getaddresstxids(addr_p2sh)), 105) # only the oldest 5 transactions are in the unspent list, # dup addresses are ignored @@ -181,6 +188,9 @@ class AddressIndexTest(BitcoinTestFramework): # check that duplicate addresses are processed correctly mempool = self.nodes[0].getaddressmempool({'addresses': [addr2, addr1, addr2]}) assert_equal(len(mempool), 3) + # test getaddressmempool for lightwalletd node + mempool = self.nodes[3].getaddressmempool({'addresses': [addr2, addr1, addr2]}) + assert_equal(len(mempool), 3) # addr2 (first arg) assert_equal(mempool[0]['address'], addr2) @@ -253,8 +263,12 @@ class AddressIndexTest(BitcoinTestFramework): tx = self.nodes[0].getrawtransaction(txid, 1) change_vout = list(filter(lambda v: v['valueZat'] != 3 * COIN, tx['vout'])) change = change_vout[0]['scriptPubKey']['addresses'][0] - bal = self.nodes[2].getaddressbalance(change) - assert(bal['received'] > 0) + + # test getaddressbalance + for node in (2, 3): + bal = self.nodes[node].getaddressbalance(change) + assert(bal['received'] > 0) + # the inequality is due to randomness in the tx fee assert(bal['received'] < (4 - 3) * COIN) assert_equal(bal['received'], bal['balance']) @@ -283,13 +297,15 @@ class AddressIndexTest(BitcoinTestFramework): # set(txids_all) removes its (expected) duplicates assert_equal(set(multitxids), set(txids_all)) - deltas = self.nodes[1].getaddressdeltas({'addresses': [addr1]}) - assert_equal(len(deltas), len(expected_deltas)) - for i in range(len(deltas)): - assert_equal(deltas[i]['address'], addr1) - assert_equal(deltas[i]['height'], expected_deltas[i]['height']) - assert_equal(deltas[i]['satoshis'], expected_deltas[i]['satoshis']) - assert_equal(deltas[i]['txid'], expected_deltas[i]['txid']) + # test getaddressdeltas + for node in (1, 3): + deltas = self.nodes[node].getaddressdeltas({'addresses': [addr1]}) + assert_equal(len(deltas), len(expected_deltas)) + for i in range(len(deltas)): + assert_equal(deltas[i]['address'], addr1) + assert_equal(deltas[i]['height'], expected_deltas[i]['height']) + assert_equal(deltas[i]['satoshis'], expected_deltas[i]['satoshis']) + assert_equal(deltas[i]['txid'], expected_deltas[i]['txid']) # 106-111 is the full range (also the default) deltas_limited = getaddressdeltas(1, [addr1], 106, 111) diff --git a/src/experimental_features.cpp b/src/experimental_features.cpp index fe4d7d4fe..93a4fd2ed 100644 --- a/src/experimental_features.cpp +++ b/src/experimental_features.cpp @@ -10,6 +10,7 @@ bool fExperimentalDeveloperEncryptWallet = false; bool fExperimentalDeveloperSetPoolSizeZero = false; bool fExperimentalPaymentDisclosure = false; bool fExperimentalInsightExplorer = false; +bool fExperimentalLightWalletd = false; boost::optional InitExperimentalMode() { @@ -18,6 +19,7 @@ boost::optional InitExperimentalMode() fExperimentalDeveloperSetPoolSizeZero = GetBoolArg("-developersetpoolsizezero", false); fExperimentalPaymentDisclosure = GetBoolArg("-paymentdisclosure", false); fExperimentalInsightExplorer = GetBoolArg("-insightexplorer", false); + fExperimentalLightWalletd = GetBoolArg("-lightwalletd", false); // Fail if user has set experimental options without the global flag if (!fExperimentalMode) { @@ -29,6 +31,8 @@ boost::optional InitExperimentalMode() return _("Payment disclosure requires -experimentalfeatures."); } else if (fExperimentalInsightExplorer) { return _("Insight explorer requires -experimentalfeatures."); + } else if (fExperimentalLightWalletd) { + return _("Light Walletd requires -experimentalfeatures."); } } return boost::none; @@ -45,6 +49,8 @@ std::vector GetExperimentalFeatures() experimentalfeatures.push_back("paymentdisclosure"); if (fExperimentalInsightExplorer) experimentalfeatures.push_back("insightexplorer"); + if (fExperimentalLightWalletd) + experimentalfeatures.push_back("lightwalletd"); return experimentalfeatures; } diff --git a/src/experimental_features.h b/src/experimental_features.h index 41afcd27e..6511022c6 100644 --- a/src/experimental_features.h +++ b/src/experimental_features.h @@ -10,6 +10,7 @@ extern bool fExperimentalDeveloperEncryptWallet; extern bool fExperimentalDeveloperSetPoolSizeZero; extern bool fExperimentalPaymentDisclosure; extern bool fExperimentalInsightExplorer; +extern bool fExperimentalLightWalletd; boost::optional InitExperimentalMode(); std::vector GetExperimentalFeatures(); diff --git a/src/gtest/test_rpc.cpp b/src/gtest/test_rpc.cpp index 56b8a485f..4d746320f 100644 --- a/src/gtest/test_rpc.cpp +++ b/src/gtest/test_rpc.cpp @@ -26,3 +26,44 @@ TEST(rpc, CheckBlockToJSONReturnsMinifiedSolution) { UniValue obj = blockToJSON(block, &index); EXPECT_EQ("009f44ff7505d789b964d6817734b8ce1377d456255994370d06e59ac99bd5791b6ad174a66fd71c70e60cfc7fd88243ffe06f80b1ad181625f210779c745524629448e25348a5fce4f346a1735e60fdf53e144c0157dbc47c700a21a236f1efb7ee75f65b8d9d9e29026cfd09048233175202b211b9a49de4ab46f1cac71b6ea57a686377bd612378746e70c61a659c9cd683269e9c2a5cbc1d19f1149345302bbd0a1e62bf4bab01e9caeea789a1519441a61b146de35a4cc75dbdf01029127e311ad5073e7e96397f47226a7df9df66b2086b70756db013bbaeb068260157014b2602fc7dc71336e1439c887d2742d9730b4e79b08ec7839c3e2a037ae1565d04e05e351bb3531e5ef42cf7b71ca1482a9205245dd41f4db0f71644f8bdb88e845558537c03834c06ac83f336651e54e2edfc12e15ea9b7ea2c074e6155654d44c4d3bd90d9511050e9ad87d170db01448e5be6f45419cd86008978db5e3ceab79890234f992648d69bf1053855387db646ccdee5575c65f81dd0f670b016d9f9a84707d91f77b862f697b8bb08365ba71fbe6bfa47af39155a75ebdcb1e5d69f59c40c9e3a64988c1ec26f7f5159eef5c244d504a9e46125948ecc389c2ec3028ac4ff39ffd66e7743970819272b21e0c2df75b308bc62896873952147e57ed79446db4cdb5a563e76ec4c25899d41128afb9a5f8fc8063621efb7a58b9dd666d30c73e318cdcf3393bfec200e160f500e645f7baac263db99fa4a7c1cb4fea219fc512193102034d379f244c21a81821301b8d47c90247713a3e902c762d7bafa6cdb744eeb6d3b50dd175599d02b6e9f5bbda59366e04862aa765135968426e7ac0116de7351940dc57c0ae451d63f667e39891bc81e09e6c76f6f8a7582f7447c6f5945f717b0e52a7e3dd0c6db4061362123cc53fd8ede4abed4865201dc4d8eb4e5d48baa565183b69a5304a44c0600bb24dcaeee9d95ceebd27c1b0a33e0b46f23797d7d7907300b2bb7d62ef2fc5aa139250c73930c621bb5f41fc235534ee8014dfaddd5245aeb01198420ba7b5c076545329c94d54fa725a8e807579f5f0cc9d98170598023268f5930893620190275e6b3c6f5181e36310a9a475208316911d78f917d724c5946c553b7ec042c563c540114b6b78bd4c6e808ee391a4a9d93e127032983c5b3708037b14aa604cfb034e7c8b0ffdd6936446fe80216178506a87402653a373926eeff66e704daf992a0a9a5c3ad80566c0339be9e5b8e35b3b3226b2f7767e20d992ea6c3d6e322eca37b0c7f7e60060802f5abcc1975841365cadbdc3867063addfc803766ae525375ecddee61f9df9ffcd20343c83ab82b0e91de039c59cb435c8d3159cc338b4901f40c9b5c27043bcf2bd5fa9b685b65c9ba5a1e11a51dd3f773051560341f9ec81d05bf259e2d4b7161f896fbb6812cfc924a32120b7367d5e40439e267adda6a1315bb0d6200ce6a503174c8d2a638ea6fd6b1f486d68db11bdca63c4f4a725d1ab6231ea875484e70b27d293c05803386924f283d4c12bb953474d92b7dd43d2d97193bd96281ebb63fa075d2f9ecd310c70ee1d97b5330bd8fb5791c5943ecf084e5f2c83915acac57519c46b166136068d6f9ec0dd598616e32c591128ce13705a283ca39d5b211409600e07b3713113374d9700207a45394eac5b3b7afc9b1b2bad7d89fd3f35f6b2413ce615ee7869b3569009403b96fdacdb32ef0a7e5229e2b666d51e95bdfb009b892e88bde70621a9b6509f068781392df4bdbc5723bb15071993f0d9a11575af5ff6ef85eaea39bc86805b35d8beee91b779354147f2d85304b8b49d053e7444fdd3deb9d16de331f2552af5b3be7766bb8f3f6a78c62148efb231f2268", find_value(obj, "solution").get_str()); } + +TEST(rpc, CheckExperimentalDisabledHelpMsg) { + + EXPECT_EQ(experimentalDisabledHelpMsg("somerpc", {"somevalue"}), + "\nWARNING: somerpc is disabled.\n" + "To enable it, restart zcashd with the following command line options:\n" + "-experimentalfeatures and -somevalue\n\n" + "Alternatively add these two lines to the zcash.conf file:\n\n" + "experimentalfeatures=1\n" + "somevalue=1\n"); + + EXPECT_EQ(experimentalDisabledHelpMsg("somerpc", {"somevalue", "someothervalue"}), + "\nWARNING: somerpc is disabled.\n" + "To enable it, restart zcashd with the following command line options:\n" + "-experimentalfeatures and -somevalue" + " or:\n-experimentalfeatures and -someothervalue" + "\n\n" + "Alternatively add these two lines to the zcash.conf file:\n\n" + "experimentalfeatures=1\n" + "somevalue=1\n" + "\nor:\n\n" + "experimentalfeatures=1\n" + "someothervalue=1\n"); + + EXPECT_EQ(experimentalDisabledHelpMsg("somerpc", {"somevalue", "someothervalue", "athirdvalue"}), + "\nWARNING: somerpc is disabled.\n" + "To enable it, restart zcashd with the following command line options:\n" + "-experimentalfeatures and -somevalue" + " or:\n-experimentalfeatures and -someothervalue" + " or:\n-experimentalfeatures and -athirdvalue" + "\n\n" + "Alternatively add these two lines to the zcash.conf file:\n\n" + "experimentalfeatures=1\n" + "somevalue=1\n" + "\nor:\n\n" + "experimentalfeatures=1\n" + "someothervalue=1\n" + "\nor:\n\n" + "experimentalfeatures=1\n" + "athirdvalue=1\n"); +} diff --git a/src/init.cpp b/src/init.cpp index 1f6928e84..ae5a9ef2c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1418,6 +1418,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) break; } + // Check for changed -lightwalletd state + bool fLightWalletdPreviouslySet = false; + pblocktree->ReadFlag("lightwalletd", fLightWalletdPreviouslySet); + if (fExperimentalLightWalletd != fLightWalletdPreviouslySet) { + strLoadError = _("You need to rebuild the database using -reindex to change -lightwalletd"); + break; + } + // Check for changed -prune state. What we are concerned about is a user who has pruned blocks // in the past, but is now trying to run unpruned. if (fHavePruned && !fPruneMode) { diff --git a/src/main.cpp b/src/main.cpp index a3d0b058f..1c8d647c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -70,7 +70,7 @@ int nScriptCheckThreads = 0; bool fImporting = false; std::atomic_bool fReindex(false); bool fTxIndex = false; -bool fAddressIndex = false; // insightexplorer +bool fAddressIndex = false; // insightexplorer || lightwalletd bool fSpentIndex = false; // insightexplorer bool fTimestampIndex = false; // insightexplorer bool fHavePruned = false; @@ -4468,14 +4468,22 @@ bool static LoadBlockIndexDB() pblocktree->ReadFlag("txindex", fTxIndex); LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled"); - // insightexplorer + // insightexplorer and lightwalletd // Check whether block explorer features are enabled bool fInsightExplorer = false; + bool fLightWalletd = false; pblocktree->ReadFlag("insightexplorer", fInsightExplorer); + pblocktree->ReadFlag("lightwalletd", fLightWalletd); LogPrintf("%s: insight explorer %s\n", __func__, fInsightExplorer ? "enabled" : "disabled"); - fAddressIndex = fInsightExplorer; - fSpentIndex = fInsightExplorer; - fTimestampIndex = fInsightExplorer; + LogPrintf("%s: light wallet daemon %s\n", __func__, fLightWalletd ? "enabled" : "disabled"); + if (fInsightExplorer) { + fAddressIndex = true; + fSpentIndex = true; + fTimestampIndex = true; + } + else if (fLightWalletd) { + fAddressIndex = true; + } // Fill in-memory data BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex) @@ -4815,11 +4823,17 @@ bool InitBlockIndex(const CChainParams& chainparams) fTxIndex = GetBoolArg("-txindex", DEFAULT_TXINDEX); pblocktree->WriteFlag("txindex", fTxIndex); - // Use the provided setting for -insightexplorer in the new database + // Use the provided setting for -insightexplorer or -lightwalletd in the new database pblocktree->WriteFlag("insightexplorer", fExperimentalInsightExplorer); - fAddressIndex = fExperimentalInsightExplorer; - fSpentIndex = fExperimentalInsightExplorer; - fTimestampIndex = fExperimentalInsightExplorer; + pblocktree->WriteFlag("lightwalletd", fExperimentalLightWalletd); + if (fExperimentalInsightExplorer) { + fAddressIndex = true; + fSpentIndex = true; + fTimestampIndex = true; + } + else if (fExperimentalLightWalletd) { + fAddressIndex = true; + } LogPrintf("Initializing databases...\n"); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 796f99805..b7605924e 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -408,8 +408,8 @@ UniValue getrawmempool(const UniValue& params, bool fHelp) UniValue getblockdeltas(const UniValue& params, bool fHelp) { std::string disabledMsg = ""; - if (!fExperimentalInsightExplorer) { - disabledMsg = experimentalDisabledHelpMsg("getblockdeltas", "insightexplorer"); + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { + disabledMsg = experimentalDisabledHelpMsg("getblockdeltas", {"insightexplorer", "lightwalletd"}); } if (fHelp || params.size() != 1) throw runtime_error( @@ -462,7 +462,7 @@ UniValue getblockdeltas(const UniValue& params, bool fHelp) + HelpExampleRpc("getblockdeltas", "\"00227e566682aebd6a7a5b772c96d7a999cadaebeaf1ce96f4191a3aad58b00b\"") ); - if (!fExperimentalInsightExplorer) { + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { throw JSONRPCError(RPC_MISC_ERROR, "Error: getblockdeltas is disabled. " "Run './zcash-cli help getblockdeltas' for instructions on how to enable this feature."); } @@ -491,8 +491,8 @@ UniValue getblockdeltas(const UniValue& params, bool fHelp) UniValue getblockhashes(const UniValue& params, bool fHelp) { std::string disabledMsg = ""; - if (!fExperimentalInsightExplorer) { - disabledMsg = experimentalDisabledHelpMsg("getblockhashes", "insightexplorer"); + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { + disabledMsg = experimentalDisabledHelpMsg("getblockhashes", {"insightexplorer", "lightwalletd"}); } if (fHelp || params.size() < 2) throw runtime_error( @@ -525,7 +525,7 @@ UniValue getblockhashes(const UniValue& params, bool fHelp) + HelpExampleCli("getblockhashes", "1558141697 1558141576 '{\"noOrphans\":false, \"logicalTimes\":true}'") ); - if (!fExperimentalInsightExplorer) { + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { throw JSONRPCError(RPC_MISC_ERROR, "Error: getblockhashes is disabled. " "Run './zcash-cli help getblockhashes' for instructions on how to enable this feature."); } diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index e80616150..a09707df1 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -576,8 +576,8 @@ static bool getAddressesFromParams( UniValue getaddressmempool(const UniValue& params, bool fHelp) { std::string disabledMsg = ""; - if (!fExperimentalInsightExplorer) { - disabledMsg = experimentalDisabledHelpMsg("getaddressmempool", "insightexplorer"); + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { + disabledMsg = experimentalDisabledHelpMsg("getaddressmempool", {"insightexplorer", "lightwalletd"}); } if (fHelp || params.size() != 1) throw runtime_error( @@ -611,7 +611,7 @@ UniValue getaddressmempool(const UniValue& params, bool fHelp) + HelpExampleRpc("getaddressmempool", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"]}") ); - if (!fExperimentalInsightExplorer) { + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddressmempool is disabled. " "Run './zcash-cli help getaddressmempool' for instructions on how to enable this feature."); } @@ -656,7 +656,7 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp) { std::string disabledMsg = ""; if (!fExperimentalInsightExplorer) { - disabledMsg = experimentalDisabledHelpMsg("getaddressutxos", "insightexplorer"); + disabledMsg = experimentalDisabledHelpMsg("getaddressutxos", {"insightexplorer"}); } if (fHelp || params.size() != 1) throw runtime_error( @@ -812,8 +812,8 @@ static void getAddressesInHeightRange( UniValue getaddressdeltas(const UniValue& params, bool fHelp) { std::string disabledMsg = ""; - if (!fExperimentalInsightExplorer) { - disabledMsg = experimentalDisabledHelpMsg("getaddressdeltas", "insightexplorer"); + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { + disabledMsg = experimentalDisabledHelpMsg("getaddressdeltas", {"insightexplorer", "lightwalletd"}); } if (fHelp || params.size() != 1) throw runtime_error( @@ -873,7 +873,7 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp) + HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"], \"start\": 1000, \"end\": 2000, \"chainInfo\": true}") ); - if (!fExperimentalInsightExplorer) { + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddressdeltas is disabled. " "Run './zcash-cli help getaddressdeltas' for instructions on how to enable this feature."); } @@ -941,8 +941,8 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp) UniValue getaddressbalance(const UniValue& params, bool fHelp) { std::string disabledMsg = ""; - if (!fExperimentalInsightExplorer) { - disabledMsg = experimentalDisabledHelpMsg("getaddressbalance", "insightexplorer"); + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { + disabledMsg = experimentalDisabledHelpMsg("getaddressbalance", {"insightexplorer", "lightwalletd"}); } if (fHelp || params.size() != 1) throw runtime_error( @@ -969,7 +969,7 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp) + HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"]}") ); - if (!fExperimentalInsightExplorer) { + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddressbalance is disabled. " "Run './zcash-cli help getaddressbalance' for instructions on how to enable this feature."); } @@ -998,8 +998,8 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp) UniValue getaddresstxids(const UniValue& params, bool fHelp) { std::string disabledMsg = ""; - if (!fExperimentalInsightExplorer) { - disabledMsg = experimentalDisabledHelpMsg("getaddresstxids", "insightexplorer"); + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { + disabledMsg = experimentalDisabledHelpMsg("getaddresstxids", {"insightexplorer", "lightwalletd"}); } if (fHelp || params.size() != 1) throw runtime_error( @@ -1029,7 +1029,7 @@ UniValue getaddresstxids(const UniValue& params, bool fHelp) + HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"], \"start\": 1000, \"end\": 2000}") ); - if (!fExperimentalInsightExplorer) { + if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) { throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddresstxids is disabled. " "Run './zcash-cli help getaddresstxids' for instructions on how to enable this feature."); } @@ -1064,7 +1064,7 @@ UniValue getspentinfo(const UniValue& params, bool fHelp) { std::string disabledMsg = ""; if (!fExperimentalInsightExplorer) { - disabledMsg = experimentalDisabledHelpMsg("getspentinfo", "insightexplorer"); + disabledMsg = experimentalDisabledHelpMsg("getspentinfo", {"insightexplorer"}); } if (fHelp || params.size() != 1 || !params[0].isObject()) throw runtime_error( diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 023197359..bd4273bd4 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -467,14 +467,32 @@ std::string HelpExampleRpc(const std::string& methodname, const std::string& arg "\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:8232/\n"; } -string experimentalDisabledHelpMsg(const string& rpc, const string& enableArg) +std::string experimentalDisabledHelpMsg(const std::string& rpc, const std::vector& enableArgs) { - return "\nWARNING: " + rpc + " is disabled.\n" - "To enable it, restart zcashd with the -experimentalfeatures and\n" - "-" + enableArg + " commandline options, or add these two lines\n" - "to the zcash.conf file:\n\n" - "experimentalfeatures=1\n" - + enableArg + "=1\n"; + std::string cmd, config = ""; + const auto size = enableArgs.size(); + assert(size > 0); + + for (size_t i = 0; i < size; ++i) + { + if (size == 1 || i == 0) + { + cmd += "-experimentalfeatures and -" + enableArgs.at(i); + config += "experimentalfeatures=1\n"; + config += enableArgs.at(i) + "=1\n"; + } + else { + cmd += " or:\n-experimentalfeatures and -" + enableArgs.at(i); + config += "\nor:\n\n"; + config += "experimentalfeatures=1\n"; + config += enableArgs.at(i) + "=1\n"; + } + } + return "\nWARNING: " + rpc + " is disabled.\n" + + "To enable it, restart zcashd with the following command line options:\n" + + cmd + "\n\n" + + "Alternatively add these two lines to the zcash.conf file:\n\n" + + config; } void RPCRegisterTimerInterface(RPCTimerInterface *iface) diff --git a/src/rpc/server.h b/src/rpc/server.h index de26b53b7..18d58ca73 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -183,6 +183,6 @@ void InterruptRPC(); void StopRPC(); std::string JSONRPCExecBatch(const UniValue& vReq); -extern std::string experimentalDisabledHelpMsg(const std::string& rpc, const std::string& enableArg); +extern std::string experimentalDisabledHelpMsg(const std::string& rpc, const std::vector& enableArgs); #endif // BITCOIN_RPCSERVER_H diff --git a/src/wallet/rpcdisclosure.cpp b/src/wallet/rpcdisclosure.cpp index e49ac6d13..7d8ca652e 100644 --- a/src/wallet/rpcdisclosure.cpp +++ b/src/wallet/rpcdisclosure.cpp @@ -43,7 +43,7 @@ UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp) string disabledMsg = ""; if (!fExperimentalPaymentDisclosure) { - disabledMsg = experimentalDisabledHelpMsg("z_getpaymentdisclosure", "paymentdisclosure"); + disabledMsg = experimentalDisabledHelpMsg("z_getpaymentdisclosure", {"paymentdisclosure"}); } if (fHelp || params.size() < 3 || params.size() > 4 ) @@ -148,7 +148,7 @@ UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp) string disabledMsg = ""; if (!fExperimentalPaymentDisclosure) { - disabledMsg = experimentalDisabledHelpMsg("z_validatepaymentdisclosure", "paymentdisclosure"); + disabledMsg = experimentalDisabledHelpMsg("z_validatepaymentdisclosure", {"paymentdisclosure"}); } if (fHelp || params.size() != 1) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 500a2cc68..4c93b3a36 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2041,7 +2041,7 @@ UniValue encryptwallet(const UniValue& params, bool fHelp) std::string disabledMsg = ""; if (!fExperimentalDeveloperEncryptWallet) { - disabledMsg = experimentalDisabledHelpMsg("encryptwallet", "developerencryptwallet"); + disabledMsg = experimentalDisabledHelpMsg("encryptwallet", {"developerencryptwallet"}); } if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1))