Skip to content

listreceivedbyaddress incorrectly shows watchonly addresses as empty #10468

Closed

Description

@keystrike

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": [
...
]
}
]

Activity

  1. Sjors commented on Jul 10, 2018

    @Sjors
    Member

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

    $ src/bitcoin-cli -rpcwallet="hi" listreceivedbyaddress 0 true
    [
      {
        "address": "mzDWjPWzsNr7Nbd5rhC73MnmJt9L1Vd9CH",
        "account": "",
        "amount": 0.00000000,
        "confirmations": 0,
        "label": "",
        "txids": [
        ]
      }
    ]
    
    $ src/bitcoin-cli -rpcwallet="hi" listreceivedbyaddress 0 true true
    [
      {
        "involvesWatchonly": true,
        "address": "mzDWjPWzsNr7Nbd5rhC73MnmJt9L1Vd9CH",
        "account": "",
        "amount": 0.01000000,
        "confirmations": 0,
        "label": "",
        "txids": [
          "e710f6f7f1c9cd9e4cd86ec345d7058dd8236c717caf0e0088ad018c231cfa92"
        ]
      }
    ]
    
  2. kouloumos commented on Aug 3, 2022

    @kouloumos
    Contributor

    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
      # create directories for nodes
      mkdir -p /tmp/node1-datadir
      mkdir -p /tmp/node2-datadir
      
      # run node1
      src/bitcoind -regtest -datadir=/tmp/node1-datadir
       
      # run node2
      src/bitcoind -regtest -datadir=/tmp/node2-datadir -rpcport=18300 -port=18400
      
      # (using variables for productivity)
      NODE1="src/bitcoin-cli -regtest -datadir=/tmp/node1-datadir"
      NODE2="src/bitcoin-cli -regtest -datadir=/tmp/node2-datadir -rpcport=18300"
      
      # create wallets (legacy) 
      $NODE1 -named createwallet wallet_name=wallet1 descriptors=false
      $NODE2 -named createwallet wallet_name=wallet2 descriptors=false
      
      watch_address=$($NODE1 getnewaddress) # generate address on node1
      $NODE2 importaddress $watch_address # add address as watchonly on node2
      
    • Observe issue when there is no balance in $watch_address.
      #  This returns nothing, **as expected**.
      $NODE2 -named listreceivedbyaddress include_empty=false include_watchonly={false,true}
      []
      
      # This should also return nothing, but it returns the empty $watch_address
      $NODE2 -named listreceivedbyaddress include_empty=true include_watchonly=false
      [
        {
          "address": $watch_address,
          "amount": 0.00000000,
          "confirmations": 0,
          "label": "",
          "txids": [
          ]
        }
      ]
    • Observe issue with balance in $watch_address.
      $NODE1 addnode 127.0.0.1:18400 "add"  # connect nodes 1->2
      $NODE1 generatetoaddress 101 $watch_address # mine blocks to address 
      
      # Correctly returns the watchonly address
      $NODE2 -named listreceivedbyaddress include_empty={false,true} include_watchonly=true
      [
        {
          "involvesWatchonly": true,
          "address": $watch_address,
          "amount": 50.00000000,
          "confirmations": 101,
          "label": "",
          "txids": [
            "c0be670898b208f156a7be5776b97f2c459e7056450ff10c66e0a2058352c319"
          ]
        }
      ]
      
      # Correctly returns nothing
      $NODE2 -named listreceivedbyaddress include_empty=false include_watchonly=false
      []
      
      # This should also return nothing , but it returns the empty $watch_address
      $NODE2 -named listreceivedbyaddress include_empty=true include_watchonly=false
      [
        {
          "address": $watch_address,
          "amount": 0.00000000,
          "confirmations": 0,
          "label": "",
          "txids": [
          ]
        }
      ]

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

  3. aureleoules commented on Sep 20, 2022

    @aureleoules
    Contributor

    nAmount = (*it).second.nAmount;
    nConf = (*it).second.nConf;
    fIsWatchonly = (*it).second.fIsWatchonly;

    these values are never set because the loop above it

    std::map<CTxDestination, tallyitem> mapTally;
    for (const std::pair<const uint256, CWalletTx>& pairWtx : wallet.mapWallet) {
    const CWalletTx& wtx = pairWtx.second;
    int nDepth = wallet.GetTxDepthInMainChain(wtx);
    if (nDepth < nMinDepth)
    continue;
    // Coinbase with less than 1 confirmation is no longer in the main chain
    if ((wtx.IsCoinBase() && (nDepth < 1))
    || (wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase)) {
    continue;
    }
    for (const CTxOut& txout : wtx.tx->vout) {
    CTxDestination address;
    if (!ExtractDestination(txout.scriptPubKey, address))
    continue;
    if (filtered_address && !(filtered_address == address)) {
    continue;
    }
    isminefilter mine = wallet.IsMine(address);
    if (!(mine & filter))
    continue;
    tallyitem& item = mapTally[address];
    item.nAmount += txout.nValue;
    item.nConf = std::min(item.nConf, nDepth);
    item.txids.push_back(wtx.GetHash());
    if (mine & ISMINE_WATCH_ONLY)
    item.fIsWatchonly = true;
    }
    }

    is never called because wallet.mapWallet is empty.

  4. willcl-ark commented on Oct 21, 2025

    @willcl-ark
    Member

    It looks like this issue has been resolved by the descriptor wallet. If that’s not the case, please let us know by commenting here or opening a new issue.

  5. locked and limited conversation to collaborators on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions