<commit_before><commit_msg>Add BalanceCoinSelector<commit_after>package fi.bittiraha.walletd;

import org.bitcoinj.wallet.DefaultCoinSelector;
import org.bitcoinj.core.*;

public class BalanceCoinSelector extends DefaultCoinSelector {
    @Override
    protected boolean shouldSelect(Transaction tx) {
        if (tx != null) {
            return isSelectable(tx);
        }
        return true;
    }
    
    public static boolean isSelectable(Transaction tx) {
        // Only pick chain-included transactions, or transactions that are ours and pending.
        TransactionConfidence confidence = tx.getConfidence();
        TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
        // BalanceCoinSelector doesn't require another peer to have seen the transaction
        // prior to selecting it, unlike DefaultCoinSelector. This is useful for calculating
        // wallet balance reliably.
        return type.equals(TransactionConfidence.ConfidenceType.BUILDING) ||
               type.equals(TransactionConfidence.ConfidenceType.PENDING) &&
               confidence.getSource().equals(TransactionConfidence.Source.SELF);
    }
}
{'fraction_non_alphanumeric': 0.07566638005159071, 'fraction_numerical': 0.0, 'mean_word_length': 3.2637362637362637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7143940', 'n_tokens_mistral': 289, 'n_tokens_neox': 284, 'n_words': 74}