For #3533. Replace asserts with JSON errors.
This helps prevent users from triggering an assert if they pass in Sapling addresses to RPC calls: z_mergetoaddress, z_importviewingkey and z_exportviewingkey.
This commit is contained in:
@@ -82,8 +82,10 @@ AsyncRPCOperation_mergetoaddress::AsyncRPCOperation_mergetoaddress(
|
|||||||
auto address = DecodePaymentAddress(std::get<0>(recipient));
|
auto address = DecodePaymentAddress(std::get<0>(recipient));
|
||||||
if (IsValidPaymentAddress(address)) {
|
if (IsValidPaymentAddress(address)) {
|
||||||
isToZaddr_ = true;
|
isToZaddr_ = true;
|
||||||
// TODO: Add Sapling support. For now, ensure we can later convert freely.
|
// TODO: Add Sapling support. For now, return an error to the user.
|
||||||
assert(boost::get<libzcash::SproutPaymentAddress>(&address) != nullptr);
|
if (boost::get<libzcash::SproutPaymentAddress>(&address) == nullptr) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Currently, only Sprout zaddrs are supported");
|
||||||
|
}
|
||||||
toPaymentAddress_ = address;
|
toPaymentAddress_ = address;
|
||||||
} else {
|
} else {
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid recipient address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid recipient address");
|
||||||
@@ -328,8 +330,10 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
|
|||||||
// Copy zinputs to more flexible containers
|
// Copy zinputs to more flexible containers
|
||||||
std::deque<MergeToAddressInputNote> zInputsDeque;
|
std::deque<MergeToAddressInputNote> zInputsDeque;
|
||||||
for (auto o : noteInputs_) {
|
for (auto o : noteInputs_) {
|
||||||
// TODO: Add Sapling support. For now, ensure we can later convert freely.
|
// TODO: Add Sapling support. For now, return an error to the user.
|
||||||
assert(boost::get<libzcash::SproutSpendingKey>(&std::get<3>(o)) != nullptr);
|
if (boost::get<libzcash::SproutSpendingKey>(&std::get<3>(o)) == nullptr) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Currently, only Sprout zaddrs are supported");
|
||||||
|
}
|
||||||
zInputsDeque.push_back(o);
|
zInputsDeque.push_back(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -724,8 +724,10 @@ UniValue z_importviewingkey(const UniValue& params, bool fHelp)
|
|||||||
if (!IsValidViewingKey(viewingkey)) {
|
if (!IsValidViewingKey(viewingkey)) {
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid viewing key");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid viewing key");
|
||||||
}
|
}
|
||||||
// TODO: Add Sapling support. For now, ensure we can freely convert.
|
// TODO: Add Sapling support. For now, return an error to the user.
|
||||||
assert(boost::get<libzcash::SproutViewingKey>(&viewingkey) != nullptr);
|
if (boost::get<libzcash::SproutViewingKey>(&viewingkey) == nullptr) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Currently, only Sprout viewing keys are supported");
|
||||||
|
}
|
||||||
auto vkey = boost::get<libzcash::SproutViewingKey>(viewingkey);
|
auto vkey = boost::get<libzcash::SproutViewingKey>(viewingkey);
|
||||||
auto addr = vkey.address();
|
auto addr = vkey.address();
|
||||||
|
|
||||||
@@ -824,8 +826,10 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
|
|||||||
if (!IsValidPaymentAddress(address)) {
|
if (!IsValidPaymentAddress(address)) {
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr");
|
||||||
}
|
}
|
||||||
// TODO: Add Sapling support. For now, ensure we can freely convert.
|
// TODO: Add Sapling support. For now, return an error to the user.
|
||||||
assert(boost::get<libzcash::SproutPaymentAddress>(&address) != nullptr);
|
if (boost::get<libzcash::SproutPaymentAddress>(&address) == nullptr) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Currently, only Sprout zaddrs are supported");
|
||||||
|
}
|
||||||
auto addr = boost::get<libzcash::SproutPaymentAddress>(address);
|
auto addr = boost::get<libzcash::SproutPaymentAddress>(address);
|
||||||
|
|
||||||
libzcash::SproutViewingKey vk;
|
libzcash::SproutViewingKey vk;
|
||||||
|
|||||||
Reference in New Issue
Block a user