private void doEmptyWallet(KeyParameter aesKey) {
   emptyWalletButton.setDisable(true);
   try {
     walletService.emptyWallet(
         addressInputTextField.getText(),
         aesKey,
         () -> {
           closeButton.setText("Close");
           addressTextField.setText(
               formatter.formatCoinWithCode(walletService.getAvailableBalance()));
           emptyWalletButton.setDisable(true);
           log.debug("wallet empty successful");
           FxTimer.runLater(
               Duration.ofMillis(Transitions.DEFAULT_DURATION),
               () ->
                   new Popup()
                       .information("The balance of your wallet was successfully transferred.")
                       .onClose(() -> blurAgain())
                       .show());
         },
         (errorMessage) -> {
           emptyWalletButton.setDisable(false);
           log.debug("wallet empty failed " + errorMessage);
         });
   } catch (InsufficientMoneyException | AddressFormatException e1) {
     e1.printStackTrace();
     log.error(e1.getMessage());
     emptyWalletButton.setDisable(false);
   }
 }
  private void addContent() {
    addMultilineLabel(
        gridPane,
        ++rowIndex,
        "Please use that only in emergency case if you cannot access your fund from the UI.\n"
            + "Before you use this tool, you should backup your data directory. After you have successfully transferred your wallet balance, remove"
            + " the db directory inside the data directory to start with a newly created and consistent data structure.\n"
            + "Please make a bug report on Github so that we can investigate what was causing the problem.",
        10);

    Coin totalBalance = walletService.getAvailableBalance();
    boolean isBalanceSufficient = totalBalance.compareTo(FeePolicy.TX_FEE) >= 0;
    addressTextField =
        addLabelTextField(
                gridPane,
                ++rowIndex,
                "Your available wallet balance:",
                formatter.formatCoinWithCode(totalBalance),
                10)
            .second;
    Tuple2<Label, InputTextField> tuple =
        addLabelInputTextField(gridPane, ++rowIndex, "Your destination address:");
    addressInputTextField = tuple.second;

    emptyWalletButton = new Button("Empty wallet");
    emptyWalletButton.setDefaultButton(isBalanceSufficient);
    emptyWalletButton.setDisable(
        !isBalanceSufficient && addressInputTextField.getText().length() > 0);
    emptyWalletButton.setOnAction(
        e -> {
          if (addressInputTextField.getText().length() > 0 && isBalanceSufficient) {
            if (walletService.getWallet().isEncrypted()) {
              walletPasswordPopup
                  .onClose(() -> blurAgain())
                  .onAesKey(aesKey -> doEmptyWallet(aesKey))
                  .show();
            } else {
              doEmptyWallet(null);
            }
          }
        });

    closeButton = new Button("Cancel");
    closeButton.setOnAction(
        e -> {
          hide();
          closeHandlerOptional.ifPresent(closeHandler -> closeHandler.run());
        });

    HBox hBox = new HBox();
    hBox.setSpacing(10);
    GridPane.setRowIndex(hBox, ++rowIndex);
    GridPane.setColumnIndex(hBox, 1);
    hBox.getChildren().addAll(emptyWalletButton, closeButton);
    gridPane.getChildren().add(hBox);
    GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
  }
Exemplo n.º 3
0
  private void tryOpenDispute(boolean isSupportTicket) {
    if (trade != null) {
      Transaction depositTx = trade.getDepositTx();
      if (depositTx != null) {
        doOpenDispute(isSupportTicket, trade.getDepositTx());
      } else {
        log.warn("Trade.depositTx is null. We try to find the tx in our wallet.");
        List<Transaction> candidates = new ArrayList<>();
        List<Transaction> transactions = walletService.getWallet().getRecentTransactions(100, true);
        transactions
            .stream()
            .forEach(
                transaction -> {
                  Coin valueSentFromMe = transaction.getValueSentFromMe(walletService.getWallet());
                  if (!valueSentFromMe.isZero()) {
                    // spending tx
                    for (TransactionOutput transactionOutput : transaction.getOutputs()) {
                      if (!transactionOutput.isMine(walletService.getWallet())) {
                        if (transactionOutput.getScriptPubKey().isPayToScriptHash()) {
                          // MS tx
                          candidates.add(transaction);
                        }
                      }
                    }
                  }
                });

        if (candidates.size() == 1) doOpenDispute(isSupportTicket, candidates.get(0));
        else if (candidates.size() > 1)
          new SelectDepositTxPopup()
              .transactions(candidates)
              .onSelect(
                  transaction -> {
                    doOpenDispute(isSupportTicket, transaction);
                  })
              .closeButtonText("Cancel")
              .show();
        else log.error("Trade.depositTx is null and we did not find any MultiSig transaction.");
      }
    } else {
      log.error("Trade is null");
    }
  }
Exemplo n.º 4
0
  public void onWithdrawRequest(
      String toAddress,
      KeyParameter aesKey,
      Trade trade,
      ResultHandler resultHandler,
      FaultHandler faultHandler) {
    AddressEntry addressEntry = walletService.getAddressEntryByOfferId(trade.getId());
    String fromAddress = addressEntry.getAddressString();

    FutureCallback<Transaction> callback =
        new FutureCallback<Transaction>() {
          @Override
          public void onSuccess(@javax.annotation.Nullable Transaction transaction) {
            if (transaction != null) {
              log.info("onWithdraw onSuccess tx ID:" + transaction.getHashAsString());
              trade.setState(Trade.State.WITHDRAW_COMPLETED);
              addTradeToClosedTrades(trade);
              resultHandler.handleResult();
            }
          }

          @Override
          public void onFailure(@NotNull Throwable t) {
            t.printStackTrace();
            log.error(t.getMessage());
            faultHandler.handleFault("An exception occurred at requestWithdraw (onFailure).", t);
          }
        };
    try {
      walletService.sendFunds(fromAddress, toAddress, trade.getPayoutAmount(), aesKey, callback);
    } catch (AddressFormatException | InsufficientMoneyException e) {
      e.printStackTrace();
      log.error(e.getMessage());
      faultHandler.handleFault("An exception occurred at requestWithdraw.", e);
    }
  }
Exemplo n.º 5
0
 void onWithdrawRequest(String toAddress) {
   checkNotNull(trade, "trade must not be null");
   if (walletService.getWallet().isEncrypted())
     walletPasswordPopup.show().onAesKey(aesKey -> doWithdrawRequest(toAddress, aesKey));
   else doWithdrawRequest(toAddress, null);
 }