add coin selection filter to exclude immature coinbase outputs

This commit is contained in:
Craig Raw 2021-10-16 11:09:30 +02:00
parent c04c249450
commit 57290a20a1
2 changed files with 24 additions and 0 deletions

View file

@ -23,6 +23,7 @@ public class Transaction extends ChildMessage {
public static final long MAX_BLOCK_LOCKTIME = 500000000L;
public static final int WITNESS_SCALE_FACTOR = 4;
public static final int DEFAULT_SEGWIT_FLAG = 1;
public static final int COINBASE_MATURITY_THRESHOLD = 100;
//Min feerate for defining dust, defined in sats/vByte
//From: https://github.com/bitcoin/bitcoin/blob/0.19/src/policy/policy.h#L50

View file

@ -0,0 +1,23 @@
package com.sparrowwallet.drongo.wallet;
import com.sparrowwallet.drongo.protocol.Transaction;
public class CoinbaseUtxoFilter implements UtxoFilter {
private final Wallet wallet;
public CoinbaseUtxoFilter(Wallet wallet) {
this.wallet = wallet;
}
@Override
public boolean isEligible(BlockTransactionHashIndex candidate) {
//Disallow immature coinbase outputs
BlockTransaction blockTransaction = wallet.getTransactions().get(candidate.getHash());
if(blockTransaction != null && blockTransaction.getTransaction() != null && blockTransaction.getTransaction().isCoinBase()
&& wallet.getStoredBlockHeight() != null && candidate.getConfirmations(wallet.getStoredBlockHeight()) < Transaction.COINBASE_MATURITY_THRESHOLD) {
return false;
}
return true;
}
}