For #3359. Return error if Sapling addresses passed to RPC z_mergetoaddress.
RPC z_mergetoaddress does not support Sapling yet but the existing error reporting was not clear to users.
This commit is contained in:
@@ -20,6 +20,7 @@ class WalletSaplingTest(BitcoinTestFramework):
|
|||||||
return start_nodes(4, self.options.tmpdir, [[
|
return start_nodes(4, self.options.tmpdir, [[
|
||||||
'-nuparams=5ba81b19:201', # Overwinter
|
'-nuparams=5ba81b19:201', # Overwinter
|
||||||
'-nuparams=76b809bb:203', # Sapling
|
'-nuparams=76b809bb:203', # Sapling
|
||||||
|
'-experimentalfeatures', '-zmergetoaddress',
|
||||||
]] * 4)
|
]] * 4)
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
@@ -53,6 +54,18 @@ class WalletSaplingTest(BitcoinTestFramework):
|
|||||||
except JSONRPCException as e:
|
except JSONRPCException as e:
|
||||||
assert_equal("Invalid parameter, Sapling has not activated", e.error['message'])
|
assert_equal("Invalid parameter, Sapling has not activated", e.error['message'])
|
||||||
|
|
||||||
|
# Verify z_mergetoaddress RPC does not support Sapling yet
|
||||||
|
try:
|
||||||
|
self.nodes[3].z_mergetoaddress([tmp_taddr], tmp_zaddr)
|
||||||
|
raise AssertionError("Should have thrown an exception")
|
||||||
|
except JSONRPCException as e:
|
||||||
|
assert_equal("Invalid parameter, Sapling is not supported yet by z_mergetoadress", e.error['message'])
|
||||||
|
try:
|
||||||
|
self.nodes[3].z_mergetoaddress([tmp_zaddr], tmp_taddr)
|
||||||
|
raise AssertionError("Should have thrown an exception")
|
||||||
|
except JSONRPCException as e:
|
||||||
|
assert_equal("Invalid parameter, Sapling is not supported yet by z_mergetoadress", e.error['message'])
|
||||||
|
|
||||||
# Activate Sapling
|
# Activate Sapling
|
||||||
self.nodes[2].generate(2)
|
self.nodes[2].generate(2)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|||||||
@@ -4204,6 +4204,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
|||||||
std::set<std::string> setAddress;
|
std::set<std::string> setAddress;
|
||||||
|
|
||||||
// Sources
|
// Sources
|
||||||
|
bool containsSaplingZaddrSource = false;
|
||||||
for (const UniValue& o : addresses.getValues()) {
|
for (const UniValue& o : addresses.getValues()) {
|
||||||
if (!o.isStr())
|
if (!o.isStr())
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected string");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected string");
|
||||||
@@ -4229,6 +4230,9 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
|||||||
if (!(useAny || useAnyNote)) {
|
if (!(useAny || useAnyNote)) {
|
||||||
zaddrs.insert(zaddr);
|
zaddrs.insert(zaddr);
|
||||||
}
|
}
|
||||||
|
// Check if z-addr is Sapling
|
||||||
|
bool isSapling = boost::get<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr;
|
||||||
|
containsSaplingZaddrSource |= isSapling;
|
||||||
} else {
|
} else {
|
||||||
throw JSONRPCError(
|
throw JSONRPCError(
|
||||||
RPC_INVALID_PARAMETER,
|
RPC_INVALID_PARAMETER,
|
||||||
@@ -4245,10 +4249,19 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
|||||||
// Validate the destination address
|
// Validate the destination address
|
||||||
auto destaddress = params[1].get_str();
|
auto destaddress = params[1].get_str();
|
||||||
bool isToZaddr = false;
|
bool isToZaddr = false;
|
||||||
|
bool isToSaplingZaddr = false;
|
||||||
CTxDestination taddr = DecodeDestination(destaddress);
|
CTxDestination taddr = DecodeDestination(destaddress);
|
||||||
if (!IsValidDestination(taddr)) {
|
if (!IsValidDestination(taddr)) {
|
||||||
if (IsValidPaymentAddressString(destaddress)) {
|
if (IsValidPaymentAddressString(destaddress)) {
|
||||||
isToZaddr = true;
|
isToZaddr = true;
|
||||||
|
|
||||||
|
// Is this a Sapling address?
|
||||||
|
auto res = DecodePaymentAddress(destaddress);
|
||||||
|
if (IsValidPaymentAddress(res)) {
|
||||||
|
isToSaplingZaddr = boost::get<libzcash::SaplingPaymentAddress>(&res) != nullptr;
|
||||||
|
} else {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress );
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress );
|
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress );
|
||||||
}
|
}
|
||||||
@@ -4302,6 +4315,19 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
|||||||
max_tx_size = MAX_TX_SIZE_BEFORE_SAPLING;
|
max_tx_size = MAX_TX_SIZE_BEFORE_SAPLING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This RPC does not support Sapling yet.
|
||||||
|
if (isToSaplingZaddr || containsSaplingZaddrSource) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Sapling is not supported yet by z_mergetoadress");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this RPC does support Sapling...
|
||||||
|
// If Sapling is not active, do not allow sending from or sending to Sapling addresses.
|
||||||
|
if (!NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
|
||||||
|
if (isToSaplingZaddr || containsSaplingZaddrSource) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Sapling has not activated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare to get UTXOs and notes
|
// Prepare to get UTXOs and notes
|
||||||
std::vector<MergeToAddressInputUTXO> utxoInputs;
|
std::vector<MergeToAddressInputUTXO> utxoInputs;
|
||||||
std::vector<MergeToAddressInputNote> noteInputs;
|
std::vector<MergeToAddressInputNote> noteInputs;
|
||||||
|
|||||||
Reference in New Issue
Block a user