There is a bug in the daemon RPC command getaddressbalance which ultimately calls into protocol command blockchain.scripthash.get_balance.
This check here in interface.py get_balance_for_scripthash asserts that the 'unconfirmed' balance cannot be negative. This is wrong. It most certainly can be negative. See for reference ElectrumX server implementaton here:
Get an address that has confirmed coins on it only (no mempool coins) initially.
Check its balance first using RPC getaddressbalance XXX. You should see some nonzero value in 'confirmed' and 0 in 'unconfirmed'.
Next, spend all of the confirmed coins to another address
Then, quickly, before the block confirms, run electrum RPC command getaddressbalance XXX for that first address again. The server returns a negative value in 'unconfirmed' now.
Observe the RPC fail on that assertion that unconfirmed balance cannot be negative (which it now is, of course).
There is a bug in the daemon RPC command
getaddressbalance
which ultimately calls into protocol commandblockchain.scripthash.get_balance
.This check here in interface.py get_balance_for_scripthash asserts that the
'unconfirmed'
balance cannot be negative. This is wrong. It most certainly can be negative. See for reference ElectrumX server implementaton here:Steps to reproduce:
getaddressbalance XXX
. You should see some nonzero value in'confirmed'
and0
in'unconfirmed
'.getaddressbalance XXX
for that first address again. The server returns a negative value in'unconfirmed'
now.Suggest: relax the assertion that it can be negative, here.