Ejemplo n.º 1
0
 private void send(String address, float amount) {
   DialogSend dialog = new DialogSend();
   dialog.setLocationRelativeTo(frmWow);
   BigDecimal valueInBTC =
       new BigDecimal(coreWallet.getBalance()).divide(new BigDecimal(Utils.COIN));
   dialog.setMaximum(valueInBTC.floatValue());
   dialog.setNetworkParameters(coreWallet.getNetworkParameters());
   if (address != null) {
     dialog.setAddress(address);
     dialog.setAmount(amount);
   }
   while (dialog.showDialog()) {
     System.out.println(
         "SEND: " + dialog.getAddress() + " " + dialog.getAmount() + " " + dialog.isFeeUsed());
     try {
       if (coreWallet.isEncrypted()) {
         DialogPassword d = new DialogPassword();
         d.setLocationRelativeTo(frmWow);
         if (d.showDialog()) {
           try {
             if (coreWallet.checkPassword(new String(d.getPassword()))) {
               coreWallet.sendCoins(
                   dialog.getAddress(), dialog.getAmount(), new String(d.getPassword()));
             } else {
               JOptionPane.showMessageDialog(
                   frmWow,
                   "Not correct password provided!",
                   "Information",
                   JOptionPane.INFORMATION_MESSAGE);
               break;
             }
           } catch (KeyCrypterException e) {
             JOptionPane.showMessageDialog(
                 frmWow, "Wallet dencryption failed!", "Error", JOptionPane.ERROR_MESSAGE);
             break;
           }
         }
         // coreWallet.sendCoins(dialog.getAddress(), dialog.getAmount());
       } else coreWallet.sendCoins(dialog.getAddress(), dialog.getAmount());
       break;
     } catch (InsufficientMoneyException e) {
       JOptionPane.showMessageDialog(
           frmWow, "Insufficient coins!", "Warning", JOptionPane.WARNING_MESSAGE);
       break;
     } catch (KeyCrypterException e) {
       JOptionPane.showMessageDialog(frmWow, e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
       break;
     }
   }
 }
Ejemplo n.º 2
0
  public void run() {
    while (true) {
      try {
        // System.out.println("Hello from a thread!");
        if (coreWallet.isDirty()) { // Setup completed
          updateEncryptionState();
          // System.out.println(coreWallet.getKeys());
          java.util.List<ECKey> keys = coreWallet.getKeys();
          // if (keys.size() != listAddresses.getModel().getSize()) {
          int selectedIndex = listAddresses.getSelectedIndex();
          // DefaultListModel model = (DefaultListModel) listAddresses.getModel();
          // model.removeAllElements();
          // NetworkParameters params = MainNetParams.get();
          List<String> addresses = new ArrayList<String>();
          for (ECKey k : keys) {
            // System.out.println(k.toAddress(coreWallet.getNetworkParameters())); //params));
            // model.addElement(k.toAddress(coreWallet.getNetworkParameters()).toString());
            addresses.add(k.toAddress(coreWallet.getNetworkParameters()).toString());
          }
          addressesListModel.setAddresses(addresses);
          if (selectedIndex != -1) {
            if (selectedIndex < addressesListModel.getSize())
              listAddresses.setSelectedIndex(selectedIndex);
            else listAddresses.setSelectedIndex(0);
          } else if (addressesListModel.getSize() > 0) listAddresses.setSelectedIndex(0);
          refreshAddressAndQRCode();

          if (coreWallet.getWallet().isEncrypted()) {
            tglbtnLock.setText("Encrypted");
            tglbtnLock.setSelected(true);
          } else {
            tglbtnLock.setText("Not Encrypted");
            tglbtnLock.setSelected(false);
          }
          // }
          String textBalance = bitcoinValueToFriendlyString(coreWallet.getBalance());
          if (!textBalance.matches(textTotalBalance.getText())) {
            this.textTotalBalance.setText(textBalance);
          }
          this.frmWow.setTitle(coreWallet.getWalletFilePath() + " - Wow Doge Wallet");

          // java.lang.Iterable<WalletTransaction> transactions =
          // coreWallet.getWalletTransactions();
          List<Transaction> transactions = coreWallet.getTransactionsByTime();
          System.out.println(transactions);
          // transactionsTableModel = new TransactionsTableModel();
          // tableTransactions.setModel(transactionsTableModel);
          this.transactionsTableModel.setTransactions(transactions, coreWallet.getWallet());
          tableTransactions.repaint();

          coreWallet.setDirty(false);
        }
        if (coreWallet.isRunning()) {
          this.progressBarStatus.setVisible(false);
          this.lblStatus.setText(" Online    ");
          this.progressBarStatus.setToolTipText("Synchronized");
        } else if (coreWallet.isSynchronizing() != 0) {
          if (this.progressBarStatus.isIndeterminate()) {
            this.lblStatus.setText(" Synchronizing...    ");
            this.progressBarStatus.setIndeterminate(false);
            this.progressBarStatus.setMaximum(coreWallet.isSynchronizing());
          }
          int progress = this.progressBarStatus.getMaximum() - coreWallet.isSynchronizing();
          int max = this.progressBarStatus.getMaximum();
          this.progressBarStatus.setValue(progress);
          this.progressBarStatus.setToolTipText((((float) progress) / max * 100) + "%");
        } else this.progressBarStatus.setIndeterminate(true);
        if (coreWallet.isStoreFileLocked()) {
          JOptionPane.showMessageDialog(
              frmWow,
              "Another Wow Doge Wallet instance is already running!\nPress OK button to quit.",
              "Information",
              JOptionPane.INFORMATION_MESSAGE);
          System.exit(1);
        }
        Thread.sleep(30);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }