Merge pull request #5545 from LarryRuane/2022-02-z_listreceivedbyaddress-reject-ua-component
z_listreceivedbyaddress: reject UA component addr (#5537)
This commit is contained in:
commit
d0d6d47aa7
|
@ -384,6 +384,15 @@ class ListReceivedTest (BitcoinTestFramework):
|
|||
assert_equal(len(receivers), 2)
|
||||
assert 'transparent' in receivers
|
||||
assert 'sapling' in receivers
|
||||
assert_raises_message(
|
||||
JSONRPCException,
|
||||
"The provided address is a bare receiver from a Unified Address in this wallet.",
|
||||
node.z_listreceivedbyaddress, receivers['transparent'], 0)
|
||||
assert_raises_message(
|
||||
JSONRPCException,
|
||||
"The provided address is a bare receiver from a Unified Address in this wallet.",
|
||||
node.z_listreceivedbyaddress, receivers['sapling'], 0)
|
||||
|
||||
# Wallet contains no notes
|
||||
r = node.z_listreceivedbyaddress(unified_addr, 0)
|
||||
assert_equal(len(r), 0, "unified_addr should have received zero notes")
|
||||
|
|
|
@ -3470,6 +3470,30 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
|
|||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr.");
|
||||
}
|
||||
|
||||
// A non-unified address argument that is a receiver within a
|
||||
// unified address known to this wallet is not allowed.
|
||||
if (std::visit(match {
|
||||
[&](const CKeyID& addr) {
|
||||
return pwalletMain->FindUnifiedAddressByReceiver(addr).has_value();
|
||||
},
|
||||
[&](const CScriptID& addr) {
|
||||
return pwalletMain->FindUnifiedAddressByReceiver(addr).has_value();
|
||||
},
|
||||
[&](const libzcash::SaplingPaymentAddress& addr) {
|
||||
return pwalletMain->FindUnifiedAddressByReceiver(addr).has_value();
|
||||
},
|
||||
[&](const libzcash::SproutPaymentAddress& addr) {
|
||||
// A unified address can't contain a Sprout receiver.
|
||||
return false;
|
||||
},
|
||||
[&](const libzcash::UnifiedAddress& addr) {
|
||||
// We allow unified addresses themselves, which cannot recurse.
|
||||
return false;
|
||||
}
|
||||
}, decoded.value())) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "The provided address is a bare receiver from a Unified Address in this wallet. Provide the full UA instead.");
|
||||
}
|
||||
|
||||
// Visitor to support Sprout and Sapling addrs
|
||||
if (!std::visit(PaymentAddressBelongsToWallet(pwalletMain), decoded.value())) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key or viewing key not found.");
|
||||
|
|
Loading…
Reference in New Issue