SendMoneyController: use CompletableFuture not Guava

This is the last remaining use of Guava futures in
WalletTemplate.
This commit is contained in:
Sean Gilligan 2023-03-25 17:16:14 -07:00 committed by Andreas Schildbach
parent 7302a24962
commit 8566819ff2

View File

@ -16,6 +16,7 @@
package wallettemplate;
import javafx.application.Platform;
import javafx.scene.layout.HBox;
import org.bitcoinj.base.Address;
import org.bitcoinj.base.Coin;
@ -25,10 +26,6 @@ import org.bitcoinj.crypto.ECKey;
import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.Wallet;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
@ -43,8 +40,6 @@ import org.bitcoinj.walletfx.utils.WTUtils;
import static org.bitcoinj.base.internal.Preconditions.checkState;
import static org.bitcoinj.walletfx.utils.GuiUtils.*;
import javax.annotation.Nullable;
public class SendMoneyController implements OverlayController<SendMoneyController> {
public Button sendBtn;
public Button cancelBtn;
@ -97,19 +92,14 @@ public class SendMoneyController implements OverlayController<SendMoneyControlle
// their own money!
req.allowUnconfirmed();
sendResult = app.walletAppKit().wallet().sendCoins(req);
Futures.addCallback(sendResult.broadcastComplete, new FutureCallback<>() {
@Override
public void onSuccess(@Nullable Transaction result) {
checkGuiThread();
overlayUI.done();
}
@Override
public void onFailure(Throwable t) {
sendResult.broadcastComplete.whenComplete((result, t) -> {
if (t == null) {
Platform.runLater(() -> overlayUI.done());
} else {
// We died trying to empty the wallet.
crashAlert(t);
}
}, MoreExecutors.directExecutor());
});
sendResult.tx.getConfidence().addEventListener((tx, reason) -> {
if (reason == TransactionConfidence.Listener.ChangeReason.SEEN_PEERS)
updateTitleForBroadcast();