Пример #1
0
  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 ");
  }
Пример #2
0
  private void setBTCClient(String serverID) {
    try {
      this.serverID = serverID;

      if (!btcClientMap.containsKey(serverID)) {
        // get the details from bitcoin object from datastore
        WalletData walletData = Utility.getWalletData();
        if (walletData == null) {
          System.out.println("setBTCClient - walletData returns null");
          return;
        }
        for (int i = 0; i < walletData.GetBitcoinServerCount(); i++) {
          BitcoinServer btcServer = walletData.GetBitcoinServer(i);
          if (btcServer == null) {
            continue;
          }
          System.out.println(
              "serverID:" + serverID + " btcServer.getServer_id():" + btcServer.getServer_id());
          if (serverID.equals(btcServer.getServer_id())) {
            int port = 8332;
            try {
              port = Integer.parseInt(btcServer.getServer_port());
            } catch (NumberFormatException nfe) {
            }
            System.out.println(
                "btcServer.getServer_host():"
                    + btcServer.getServer_host()
                    + " btcServer.getBitcoin_username():"
                    + btcServer.getBitcoin_username()
                    + " btcServer.getBitcoin_password():"
                    + btcServer.getBitcoin_password()
                    + " port:"
                    + port);
            // btcClient = new BitcoinClient(Configuration.getHostBitcoin(),
            // Configuration.getUserBitcoin(), Configuration.getPwdBitcoin(),
            // Configuration.getPortBitcoin());
            btcClient =
                new BitcoinClient(
                    btcServer.getServer_host(),
                    btcServer.getBitcoin_username(),
                    btcServer.getBitcoin_password(),
                    port);
            btcClientMap.put(serverID, btcClient);
            break;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
  }
Пример #3
0
 @Override
 public boolean editLabel(String accountID, String newLabel) {
   // Loop
   boolean status = false;
   WalletData walletData = Utility.getWalletData();
   if (walletData == null) {
     System.out.println("editLabel - walletData returns null");
     return false;
   }
   for (int i = 0; i < walletData.GetBitcoinAcctCount(); i++) {
     BitcoinAcct btcAcct = walletData.GetBitcoinAcct(i);
     if (btcAcct == null) continue;
     if (accountID.equals(btcAcct.getAcct_id())) {
       btcAcct.setGui_label(newLabel);
       status = otapi.StoreObject(walletData, "moneychanger", "gui_wallet.dat");
       System.out.println("Edit label status otapi.StoreObject:" + status);
       break;
     }
   }
   return status;
 }