Skip to content

Commit d562c4e

Browse files
committed
commands: increment receive index on each use
This is a similar fix as for the change index.
1 parent 36d4767 commit d562c4e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/commands/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl DaemonControl {
266266
.increment()
267267
.expect("Must not get into hardened territory");
268268
db_conn.set_change_index(next_index, &self.secp);
269-
} else if !is_change && db_conn.receive_index() < *index {
269+
} else if !is_change && db_conn.receive_index() <= *index {
270270
let next_index = index
271271
.increment()
272272
.expect("Must not get into hardened territory");

tests/test_spend.py

+14
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,20 @@ def test_send_to_self(lianad, bitcoind):
245245
)
246246
wait_for(lambda: len(list(unspent_coins())) == 1)
247247

248+
# We've used 3 receive addresses and so the DB receive index must be 3.
249+
assert len(lianad.rpc.listaddresses()["addresses"]) == 3
250+
# Create a new spend to the receive address with index 3.
251+
recv_addr = lianad.rpc.listaddresses(3, 1)["addresses"][0]["receive"]
252+
res = lianad.rpc.createspend({recv_addr: 11_955_000}, [], 1)
253+
assert "psbt" in res
254+
# Max(receive_index, change_index) is now 4:
255+
assert len(lianad.rpc.listaddresses()["addresses"]) == 4
256+
# But the spend has no change:
257+
psbt = PSBT.from_base64(res["psbt"])
258+
assert len(psbt.o) == 1
259+
# As the spend has no change, only the receive index was incremented.
260+
# Therefore, the DB receive index is now 4.
261+
248262

249263
def test_coin_selection(lianad, bitcoind):
250264
"""We can create a spend using coin selection."""

0 commit comments

Comments
 (0)