commands: increment receive index on each use

This is a similar fix as for the change index.
This commit is contained in:
jp1ac4 2024-02-07 17:33:25 +00:00 committed by Antoine Poinsot
parent cc5e396ace
commit bfd6ca517b
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
2 changed files with 15 additions and 1 deletions

View File

@ -267,7 +267,7 @@ impl DaemonControl {
.increment()
.expect("Must not get into hardened territory");
db_conn.set_change_index(next_index, &self.secp);
} else if !is_change && db_conn.receive_index() < *index {
} else if !is_change && db_conn.receive_index() <= *index {
let next_index = index
.increment()
.expect("Must not get into hardened territory");

View File

@ -246,6 +246,20 @@ def test_send_to_self(lianad, bitcoind):
)
wait_for(lambda: len(list(unspent_coins())) == 1)
# We've used 3 receive addresses and so the DB receive index must be 3.
assert len(lianad.rpc.listaddresses()["addresses"]) == 3
# Create a new spend to the receive address with index 3.
recv_addr = lianad.rpc.listaddresses(3, 1)["addresses"][0]["receive"]
res = lianad.rpc.createspend({recv_addr: 11_955_000}, [], 1)
assert "psbt" in res
# Max(receive_index, change_index) is now 4:
assert len(lianad.rpc.listaddresses()["addresses"]) == 4
# But the spend has no change:
psbt = PSBT.from_base64(res["psbt"])
assert len(psbt.o) == 1
# As the spend has no change, only the receive index was incremented.
# Therefore, the DB receive index is now 4.
def test_coin_selection(lianad, bitcoind):
"""We can create a spend using coin selection."""