public String createNewAddress(String label, String account) {
   btcClient = (BitcoinClient) btcClientMap.get(serverID);
   String newAddress = btcClient.getNewAddress(label);
   System.out.println("newAddress:" + newAddress);
   if (newAddress != null) {
     btcClient.setAccountForAddress(newAddress, account);
   }
   return newAddress;
 }
  public Map getSentBoxData(String account) {
    HashMap data = new HashMap();
    btcClient = (BitcoinClient) btcClientMap.get(serverID);
    List listOfTransactions = btcClient.listTransactions(account);
    System.out.println(" listOfTransactions.size(): " + listOfTransactions.size());
    for (int i = 0; i < listOfTransactions.size(); i++) {
      TransactionInfo trnInfo = (TransactionInfo) listOfTransactions.get(i);
      /*System.out.println(" ------------------------------------ " + trnInfo);
      System.out.println("confirm:" + trnInfo.getConfirmations());
      System.out.println("amout:" + trnInfo.getAmount());
      System.out.println("Address:" + trnInfo.getAddress());
      System.out.println("mess:" + trnInfo.getMessage());
      System.out.println("cat:" + trnInfo.getCategory());
      System.out.println("other acct:" + trnInfo.getOtherAccount());
      System.out.println("fees:" + trnInfo.getFee());
      System.out.println("ID:" + trnInfo.getTxId());
      System.out.println("Date:" + trnInfo.getTimestamp());
      System.out.println("Formatted Date:" + new Date(trnInfo.getTimestamp() * 1000));*/

      if ("send".equalsIgnoreCase(trnInfo.getCategory())) {
        String[] row = new String[6];
        row[0] = String.valueOf(trnInfo.getConfirmations() + " Confirmations");
        row[1] = String.valueOf(new Date(trnInfo.getTimestamp() * 1000));
        row[2] = String.valueOf(trnInfo.getAmount() * -1);
        row[3] = String.valueOf(trnInfo.getAddress());
        row[4] = trnInfo.getMessage() == null ? "" : trnInfo.getMessage();
        row[5] = String.valueOf(trnInfo.getTxId());

        data.put(row[5], row);
      }
    }
    return data;
  }
  @Override
  public Object getAccountDetails(String accountID) {
    System.out.println(" getAccountDetails - Starts ");
    btcClient = (BitcoinClient) btcClientMap.get(serverID);
    BitcoinDetails bitcoinDetails = new BitcoinDetails();

    bitcoinDetails.setAccount(accountID);
    bitcoinDetails.setServerID(serverID);
    System.out.println(" getLabel - " + bitcoinDetails.getLabel());
    btcClient.getServerInfo();

    bitcoinDetails.setAddress(btcClient.getAccountAddress(accountID));

    bitcoinDetails.setName(btcClient.getLabel(bitcoinDetails.getAddress()));

    bitcoinDetails.setBalance(String.valueOf(btcClient.getBalance()));

    bitcoinDetails.setCurrentBlockNumber(btcClient.getBlockNumber());

    bitcoinDetails.setSentboxData(getSentBoxData(accountID));
    bitcoinDetails.setReceivedboxData(getReceivedBoxData(accountID));
    bitcoinDetails.setReceivedAddrboxData(getRecevingAddrBoxData(accountID));
    System.out.println(
        "Block Count:"
            + btcClient.getBlockCount()
            + " btcClient.getBlockNumber():"
            + btcClient.getBlockNumber());
    return bitcoinDetails;
  }
  public void getBitcoinAccountList() throws Exception {
    System.out.println("getBitcoinAccountList strts ");
    btcClient = (BitcoinClient) btcClientMap.get(serverID);

    List accountsList = btcClient.getAccountList();

    for (int j = 0; j < accountsList.size(); j++) {

      String data[] = (String[]) accountsList.get(j);
      WalletData walletData = Utility.getWalletData();
      if (walletData == null) {
        System.out.println("getBitcoinAccountList - walletData returns null");
        return;
      }
      int count = (int) walletData.GetBitcoinAcctCount();
      BitcoinAcct btcAcct = null;
      boolean acctExists = false;

      for (int i = 0; i < count; i++) {
        acctExists = false;
        btcAcct = walletData.GetBitcoinAcct(i);
        if (btcAcct != null && btcAcct.getAcct_id().equals(data[0])) {
          acctExists = true;
          break;
        }
      }
      if (!acctExists) {
        Storable storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_BITCOIN_ACCT);
        if (storable != null) {
          btcAcct = BitcoinAcct.ot_dynamic_cast(storable);
          if (btcAcct != null) {
            btcAcct.setGui_label(data[0]);
            btcAcct.setBitcoin_acct_name(data[0]);
            btcAcct.setAcct_id(data[0]);
            btcAcct.setServer_id(serverID);

            boolean status = walletData.AddBitcoinAcct(btcAcct);
            System.out.println("status walletData.AddBitcoinAcct:" + status);

            status = otapi.StoreObject(walletData, "moneychanger", "gui_wallet.dat");

            System.out.println("status otapi.StoreObject:" + status);
          }
        }
      }
      if (btcAcct != null) {
        key = btcAcct.getAcct_id();
        label = btcAcct.getGui_label();
        amount = data[1];
        accountList.put(key, new String[] {label, amount, type, key});
      }
    }
    System.out.println("getBitcoinAccountList ends ");
  }
  public Map getRecevingAddrBoxData(String account) {

    HashMap data = new HashMap();
    btcClient = (BitcoinClient) btcClientMap.get(serverID);
    List listOfAddress = btcClient.getAddressesByAccount(account);

    for (int i = 0; i < listOfAddress.size(); i++) {
      String address = (String) listOfAddress.get(i);
      boolean addAddress = true;
      double amount = 0.0;
      List list = btcClient.listTransactions(account);
      for (int j = 0; j < list.size(); j++) {
        TransactionInfo info = (TransactionInfo) list.get(j);

        if (address != null
            && address.equals(info.getAddress())
            && "send".equalsIgnoreCase(info.getCategory())) {
          addAddress = false;
          break;
        } else if (address != null
            && address.equals(info.getAddress())
            && "receive".equalsIgnoreCase(info.getCategory())) {
          amount += info.getAmount();
        }
      }
      if (addAddress) {

        String[] row = new String[3];

        row[0] = btcClient.getLabel(address);
        row[1] = address;
        row[2] = String.valueOf(Utility.roundTwoDecimals(amount));

        data.put(row[1], row);
      }
    }
    return data;
  }
  public String sendFunds(String toAddress, double amount, String comment, String commentTo) {
    btcClient = (BitcoinClient) btcClientMap.get(serverID);
    try {
      String result = btcClient.sendToAddress(toAddress, amount, comment, commentTo);
      System.out.println("result:" + result);

    } catch (BitcoinClientException btcException) {
      return btcException.getMessage();
    } catch (Exception e) {
      e.printStackTrace();
      return "Failed";
    }
    return "Success";
  }
 public String getLabel(String address) {
   btcClient = (BitcoinClient) btcClientMap.get(serverID);
   return btcClient.getLabel(address);
 }
 public String getBlockNumber() {
   btcClient = (BitcoinClient) btcClientMap.get(serverID);
   return String.valueOf(btcClient.getBlockNumber());
 }
 public boolean isMineAddress(String address) {
   btcClient = (BitcoinClient) btcClientMap.get(serverID);
   ValidatedAddressInfo addressInfo = btcClient.validateAddress(address);
   return addressInfo.getIsMine();
 }
 public void setLabelForAddress(String address, String newLabel) {
   btcClient = (BitcoinClient) btcClientMap.get(serverID);
   btcClient.setLabelForAddress(address, newLabel);
 }
 public double checkBalance(String account) {
   btcClient = (BitcoinClient) btcClientMap.get(serverID);
   System.out.println("bal:" + btcClient.getBalance());
   return btcClient.getBalance();
 }