diff --git a/src/bitcoin/d/mod.rs b/src/bitcoin/d/mod.rs index 1558ed60..598412b6 100644 --- a/src/bitcoin/d/mod.rs +++ b/src/bitcoin/d/mod.rs @@ -1073,11 +1073,17 @@ impl From for LSBlockRes { .expect("Array must be present") .iter() .filter_map(|j| { - if j.get("category") + // From 'listunspent' help: + // "send" Transactions sent. + // "receive" Non-coinbase transactions received. + // "generate" Coinbase transactions received with more than 100 confirmations. + // "immature" Coinbase transactions received with 100 or fewer confirmations. + // "orphan" Orphaned coinbase transactions received. + let category = j + .get("category") .and_then(Json::as_str) - .expect("must be present") - == "receive" - { + .expect("must be present"); + if category == "receive" || category == "generate" { let lsb_entry: LSBlockEntry = j.into(); Some(lsb_entry) } else { diff --git a/tests/test_misc.py b/tests/test_misc.py index 31308b65..ff709b98 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -72,3 +72,17 @@ def test_multisig(lianad_multisig, bitcoind): signed_psbt = lianad.signer.sign_psbt(reco_psbt, [1, 4], recovery=True) lianad.rpc.updatespend(signed_psbt.to_base64()) lianad.rpc.broadcastspend(txid) + + +def test_coinbase_deposit(lianad, bitcoind): + """Check we detect deposits from (mature) coinbase transactions.""" + # Create a new deposit in a coinbase transaction. + addr = lianad.rpc.getnewaddress()["address"] + bitcoind.rpc.generatetoaddress(1, addr) + assert len(lianad.rpc.listcoins()["coins"]) == 0 + + # Generate 100 blocks to make the coinbase mature. + bitcoind.generate_block(100) + + # We must have detected a new deposit. + wait_for(lambda: len(lianad.rpc.listcoins()["coins"]) == 1)