bitcoind: detect deposits from (mature) coinbase transactions

This commit is contained in:
Antoine Poinsot 2023-02-04 13:21:20 +01:00
parent 72d04e5a0f
commit af058d59e3
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
2 changed files with 24 additions and 4 deletions

View File

@ -1073,11 +1073,17 @@ impl From<Json> 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 {

View File

@ -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)