<commit_before>package wallettemplate;

import com.google.bitcoin.core.Address;
import com.google.bitcoin.core.AddressFormatException;
import com.google.bitcoin.core.Transaction;
import com.google.bitcoin.core.Wallet;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import wallettemplate.controls.BitcoinAddressValidator;
import wallettemplate.utils.GuiUtils;

public class SendMoneyController {
    public Button sendBtn;
    public Button cancelBtn;
    public TextField address;
    public Label titleLabel;

    public Main.OverlayUI overlayUi;

    // Called by FXMLLoader
    public void initialize() {
        new BitcoinAddressValidator(Main.params, address, sendBtn);
    }

    public void cancel(ActionEvent event) {
        overlayUi.done();
    }

    public void send(ActionEvent event) {
        try {
            Address destination = new Address(Main.params, address.getText());
            Wallet.SendRequest req = Wallet.SendRequest.emptyWallet(destination);
            final Wallet.SendResult sendResult = Main.bitcoin.wallet().sendCoins(req);
            if (sendResult == null) {
                // We couldn't empty the wallet for some reason. TODO: When bitcoinj issue 425 is fixed, be more helpful
                GuiUtils.informationalAlert("Could not empty the wallet",
                        "You may have too little money left in the wallet to make a transaction.");
                overlayUi.done();
                return;
            }
            Futures.addCallback(sendResult.broadcastComplete, new FutureCallback<Transaction>() {
                @Override
                public void onSuccess(Transaction result) {
                    Platform.runLater(overlayUi::done);
                }

                @Override
                public void onFailure(Throwable t) {
                    // We died trying to empty the wallet.
                    GuiUtils.crashAlert(t);
                }
            });
            sendBtn.setDisable(true);
            address.setDisable(true);
            titleLabel.setText("Broadcasting ...");
        } catch (AddressFormatException e) {
            // Cannot happen because we already validated it when the text field changed.
            throw new RuntimeException(e);
        }
    }
}<commit_msg>WalletTemplate: show number of peers seen when emptying the wallet.<commit_after>package wallettemplate;

import com.google.bitcoin.core.*;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import wallettemplate.controls.BitcoinAddressValidator;

import static wallettemplate.utils.GuiUtils.crashAlert;
import static wallettemplate.utils.GuiUtils.informationalAlert;

public class SendMoneyController {
    public Button sendBtn;
    public Button cancelBtn;
    public TextField address;
    public Label titleLabel;

    public Main.OverlayUI overlayUi;

    private Wallet.SendResult sendResult;

    // Called by FXMLLoader
    public void initialize() {
        new BitcoinAddressValidator(Main.params, address, sendBtn);
    }

    public void cancel(ActionEvent event) {
        overlayUi.done();
    }

    public void send(ActionEvent event) {
        try {
            Address destination = new Address(Main.params, address.getText());
            Wallet.SendRequest req = Wallet.SendRequest.emptyWallet(destination);
            sendResult = Main.bitcoin.wallet().sendCoins(req);
            if (sendResult == null) {
                // We couldn't empty the wallet for some reason. TODO: When bitcoinj issue 425 is fixed, be more helpful
                informationalAlert("Could not empty the wallet",
                        "You may have too little money left in the wallet to make a transaction.");
                overlayUi.done();
                return;
            }

            Futures.addCallback(sendResult.broadcastComplete, new FutureCallback<Transaction>() {
                @Override
                public void onSuccess(Transaction result) {
                    Platform.runLater(overlayUi::done);
                }

                @Override
                public void onFailure(Throwable t) {
                    // We died trying to empty the wallet.
                    crashAlert(t);
                }
            });
            sendResult.tx.getConfidence().addEventListener((tx, reason) -> {
                if (reason == TransactionConfidence.Listener.ChangeReason.SEEN_PEERS)
                    updateTitleForBroadcast();
            });
            sendBtn.setDisable(true);
            address.setDisable(true);
            updateTitleForBroadcast();
        } catch (AddressFormatException e) {
            // Cannot happen because we already validated it when the text field changed.
            throw new RuntimeException(e);
        }
    }

    private void updateTitleForBroadcast() {
        final int peers = sendResult.tx.getConfidence().numBroadcastPeers();
        titleLabel.setText(String.format("Broadcasting ... seen by %d peers", peers));
    }
}
{'fraction_non_alphanumeric': 0.08351648351648351, 'fraction_numerical': 0.001098901098901099, 'mean_word_length': 2.3400611620795106, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '4442268', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1309, 'n_words': 355}