Disable Sapling features on mainnet

Also places them behind an experimental features flag on testnet
This commit is contained in:
Jack Grigg 2018-08-13 14:18:18 +01:00
parent dfcf33fe15
commit 554e00e8f9
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
4 changed files with 24 additions and 9 deletions

View File

@ -4,7 +4,7 @@
#include <gtest/gtest.h>
TEST(Keys, EncodeAndDecodeSapling)
TEST(Keys, DISABLED_EncodeAndDecodeSapling)
{
SelectParams(CBaseChainParams::MAIN);

View File

@ -286,7 +286,11 @@ libzcash::PaymentAddress DecodePaymentAddress(const std::string& str)
}
data.clear();
auto bech = bech32::Decode(str);
if (bech.first == Params().Bech32HRP(CChainParams::SAPLING_PAYMENT_ADDRESS) &&
bool allowSapling = Params().NetworkIDString() == "regtest" || (
Params().NetworkIDString() == "test" &&
GetBoolArg("-experimentalfeatures", false) &&
GetBoolArg("-developersapling", false));
if (allowSapling && bech.first == Params().Bech32HRP(CChainParams::SAPLING_PAYMENT_ADDRESS) &&
bech.second.size() == ConvertedSaplingPaymentAddressSize) {
// Bech32 decoding
data.reserve((bech.second.size() * 5) / 8);
@ -352,7 +356,11 @@ libzcash::SpendingKey DecodeSpendingKey(const std::string& str)
}
data.clear();
auto bech = bech32::Decode(str);
if (bech.first == Params().Bech32HRP(CChainParams::SAPLING_SPENDING_KEY) &&
bool allowSapling = Params().NetworkIDString() == "regtest" || (
Params().NetworkIDString() == "test" &&
GetBoolArg("-experimentalfeatures", false) &&
GetBoolArg("-developersapling", false));
if (allowSapling && bech.first == Params().Bech32HRP(CChainParams::SAPLING_SPENDING_KEY) &&
bech.second.size() == ConvertedSaplingSpendingKeySize) {
// Bech32 decoding
data.reserve((bech.second.size() * 5) / 8);

View File

@ -383,12 +383,13 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_validateaddress)
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_validateaddress zs1z7rejlpsa98s2rrrfkwmaxu53e4ue0ulcrw0h4x5g8jl04tak0d3mm47vdtahatqrlkngh9slya"));
resultObj = retValue.get_obj();
b = find_value(resultObj, "isvalid").get_bool();
BOOST_CHECK_EQUAL(b, true);
BOOST_CHECK_EQUAL(find_value(resultObj, "type").get_str(), "sapling");
b = find_value(resultObj, "ismine").get_bool();
// TODO: Revert when we re-enable Sapling addresses on mainnet
BOOST_CHECK_EQUAL(b, false);
BOOST_CHECK_EQUAL(find_value(resultObj, "diversifier").get_str(), "1787997c30e94f050c634d");
BOOST_CHECK_EQUAL(find_value(resultObj, "diversifiedtransmissionkey").get_str(), "34ed1f60f5db5763beee1ddbb37dd5f7e541d4d4fbdcc09fbfcc6b8e949bbe9d");
// BOOST_CHECK_EQUAL(find_value(resultObj, "type").get_str(), "sapling");
// b = find_value(resultObj, "ismine").get_bool();
// BOOST_CHECK_EQUAL(b, false);
// BOOST_CHECK_EQUAL(find_value(resultObj, "diversifier").get_str(), "1787997c30e94f050c634d");
// BOOST_CHECK_EQUAL(find_value(resultObj, "diversifiedtransmissionkey").get_str(), "34ed1f60f5db5763beee1ddbb37dd5f7e541d4d4fbdcc09fbfcc6b8e949bbe9d");
}
/*
@ -536,6 +537,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importwallet)
*/
BOOST_AUTO_TEST_CASE(rpc_wallet_z_importexport)
{
SelectParams(CBaseChainParams::REGTEST);
LOCK2(cs_main, pwalletMain->cs_wallet);
UniValue retValue;
int n1 = 1000; // number of times to import/export

View File

@ -3133,9 +3133,13 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp)
addrType = params[0].get_str();
}
bool allowSapling = Params().NetworkIDString() == "regtest" || (
Params().NetworkIDString() == "test" &&
GetBoolArg("-experimentalfeatures", false) &&
GetBoolArg("-developersapling", false));
if (addrType == ADDR_TYPE_SPROUT) {
return EncodePaymentAddress(pwalletMain->GenerateNewZKey());
} else if (addrType == ADDR_TYPE_SAPLING) {
} else if (addrType == ADDR_TYPE_SAPLING && allowSapling) {
return EncodePaymentAddress(pwalletMain->GenerateNewSaplingZKey());
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid address type");