listreceivedbyaddress incorrectly shows watchonly addresses as empty #10468

issue keystrike openend this issue on May 27, 2017
  1. keystrike commented at 3:05 pm on May 27, 2017: contributor

    The arguments are minconf, include_empty, and include_watchonly. If include_empty is true then watchonly addresses are returned as having a 0 balance even if they have a positive balance. Only when include_watchonly is also true do watchonly addresses with a balance return with their correct balance.

    When include_empty is true and include_watchonly is false then the watchonly addresses should not be returned at all.

    Example: $ ./bitcoin-cli listreceivedbyaddress 1 true [ { “address”: “watch only”, “account”: “”, “amount”: 0.00000000, “confirmations”: 0, “label”: “”, “txids”: [ ] }, { “address”: “address with privkey”, “account”: “”, “amount”: 0.00000000, “confirmations”: 0, “label”: “”, “txids”: [ ] } ]

    $ ./bitcoin-cli listreceivedbyaddress 1 true true [ { “address”: “address with privkey”, “account”: “”, “amount”: 0.00000000, “confirmations”: 0, “label”: “”, “txids”: [ ] }, { “address”: “watch only”, “account”: “”, “amount”: 1.0000000, “confirmations”: 1234, “txids”: [ … ] } ]

  2. fanquake added the label RPC/REST/ZMQ on May 28, 2017
  3. Sjors commented at 3:10 pm on July 10, 2018: member

    Just noticed this while reviewing #9662. It’s quite weird:

     0$ src/bitcoin-cli -rpcwallet="hi" listreceivedbyaddress 0 true
     1[
     2  {
     3    "address": "mzDWjPWzsNr7Nbd5rhC73MnmJt9L1Vd9CH",
     4    "account": "",
     5    "amount": 0.00000000,
     6    "confirmations": 0,
     7    "label": "",
     8    "txids": [
     9    ]
    10  }
    11]
    12
    13$ src/bitcoin-cli -rpcwallet="hi" listreceivedbyaddress 0 true true
    14[
    15  {
    16    "involvesWatchonly": true,
    17    "address": "mzDWjPWzsNr7Nbd5rhC73MnmJt9L1Vd9CH",
    18    "account": "",
    19    "amount": 0.01000000,
    20    "confirmations": 0,
    21    "label": "",
    22    "txids": [
    23      "e710f6f7f1c9cd9e4cd86ec345d7058dd8236c717caf0e0088ad018c231cfa92"
    24    ]
    25  }
    26]
    
  4. kouloumos commented at 4:11 pm on August 3, 2022: member

    The expected behavior with listreceivedbyaddress is that when include_empty=true and include_watchonly=false the watchonly addresses should not be returned at all.

    What has been reported and what I was able to reproduce is that when watchonly addresses are not supposed to be included (include_watchonly=false), they are included if include_empty=true and are always returned as having 0 balance even if they have a positive balance.

    I was able to reproduced this using legacy wallets on regtest.

    • Preparation
       0# create directories for nodes
       1mkdir -p /tmp/node1-datadir
       2mkdir -p /tmp/node2-datadir
       3
       4# run node1
       5src/bitcoind -regtest -datadir=/tmp/node1-datadir
       6
       7# run node2
       8src/bitcoind -regtest -datadir=/tmp/node2-datadir -rpcport=18300 -port=18400
       9
      10# (using variables for productivity)
      11NODE1="src/bitcoin-cli -regtest -datadir=/tmp/node1-datadir"
      12NODE2="src/bitcoin-cli -regtest -datadir=/tmp/node2-datadir -rpcport=18300"
      13
      14# create wallets (legacy) 
      15$NODE1 -named createwallet wallet_name=wallet1 descriptors=false
      16$NODE2 -named createwallet wallet_name=wallet2 descriptors=false
      17
      18watch_address=$($NODE1 getnewaddress) # generate address on node1
      19$NODE2 importaddress $watch_address # add address as watchonly on node2
      
    • Observe issue when there is no balance in $watch_address.
       0#  This returns nothing, **as expected**.
       1$NODE2 -named listreceivedbyaddress include_empty=false include_watchonly={false,true}
       2[]
       3
       4# This should also return nothing, but it returns the empty $watch_address
       5$NODE2 -named listreceivedbyaddress include_empty=true include_watchonly=false
       6[
       7  {
       8    "address": $watch_address,
       9    "amount": 0.00000000,
      10    "confirmations": 0,
      11    "label": "",
      12    "txids": [
      13    ]
      14  }
      15]
      
    • Observe issue with balance in $watch_address.
       0$NODE1 addnode 127.0.0.1:18400 "add"  # connect nodes 1->2
       1$NODE1 generatetoaddress 101 $watch_address # mine blocks to address 
       2
       3# Correctly returns the watchonly address
       4$NODE2 -named listreceivedbyaddress include_empty={false,true} include_watchonly=true
       5[
       6  {
       7    "involvesWatchonly": true,
       8    "address": $watch_address,
       9    "amount": 50.00000000,
      10    "confirmations": 101,
      11    "label": "",
      12    "txids": [
      13      "c0be670898b208f156a7be5776b97f2c459e7056450ff10c66e0a2058352c319"
      14    ]
      15  }
      16]
      17
      18# Correctly returns nothing
      19$NODE2 -named listreceivedbyaddress include_empty=false include_watchonly=false
      20[]
      21
      22# This should also return nothing , but it returns the empty $watch_address
      23$NODE2 -named listreceivedbyaddress include_empty=true include_watchonly=false
      24[
      25  {
      26    "address": $watch_address,
      27    "amount": 0.00000000,
      28    "confirmations": 0,
      29    "label": "",
      30    "txids": [
      31    ]
      32  }
      33]
      

    Note: The same behavior can also reproduced for the listreceivedbylabel RPC.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-24 03:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me