Skip to content

Commit 5e0ba8f

Browse files
committed
[wallet] getreceivedbyaddress should return error if address is not mine
1 parent ea0cd24 commit 5e0ba8f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ UniValue getreceivedbyaddress(const JSONRPCRequest& request)
654654
}
655655
CScript scriptPubKey = GetScriptForDestination(dest);
656656
if (!IsMine(*pwallet, scriptPubKey)) {
657-
return ValueFromAmount(0);
657+
throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet");
658658
}
659659

660660
// Minimum confirmations

test/functional/receivedby.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
from decimal import Decimal
77

88
from test_framework.test_framework import BitcoinTestFramework
9-
from test_framework.util import assert_array_result, assert_equal
9+
from test_framework.util import (assert_array_result,
10+
assert_equal,
11+
assert_raises_rpc_error,
12+
)
1013

1114
class ReceivedByTest(BitcoinTestFramework):
1215
def set_test_params(self):
@@ -68,6 +71,9 @@ def run_test(self):
6871
balance = self.nodes[1].getreceivedbyaddress(addr)
6972
assert_equal(balance, Decimal("0.1"))
7073

74+
# Trying to getreceivedby for an address the wallet doesn't own should return an error
75+
assert_raises_rpc_error(-4, "Address not found in wallet", self.nodes[0].getreceivedbyaddress, addr)
76+
7177
self.log.info("listreceivedbyaccount + getreceivedbyaccount Test")
7278

7379
# set pre-state

0 commit comments

Comments
 (0)