Skip to content

Commit 3a12ea0

Browse files
jp1ac4darosior
authored andcommitted
commands: increment receive index on each use
This is a similar fix as for the change index.
1 parent b10fb40 commit 3a12ea0

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
@@ -267,7 +267,7 @@ impl DaemonControl {
267267
.increment()
268268
.expect("Must not get into hardened territory");
269269
db_conn.set_change_index(next_index, &self.secp);
270-
} else if !is_change && db_conn.receive_index() < *index {
270+
} else if !is_change && db_conn.receive_index() <= *index {
271271
let next_index = index
272272
.increment()
273273
.expect("Must not get into hardened territory");

tests/test_spend.py

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

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

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

0 commit comments

Comments
 (0)