public String addWallet() {
   int ndx = nextAvailableWallet();
   List<WalletEntry> wallets = loadWalletDirectory();
   String name = String.format("Wallet %d", ndx);
   String path = String.format("wallet%03d", ndx);
   wallets.add(new WalletEntry(name, path));
   makeWalletDirectory(path);
   persistWalletDirectory(wallets);
   return name;
 }
 public void renameWallet(String path, String newName) {
   mLogger.info("renmaing wallet " + path + " to " + newName);
   List<WalletEntry> wallets = loadWalletDirectory();
   for (WalletEntry entry : wallets) {
     if (entry.mPath.equals(path)) {
       entry.mName = newName;
       persistWalletDirectory(wallets);
       return;
     }
   }
   throw new RuntimeException("wallet " + path + " not found");
 }
  public void deleteWallet(String path) {
    mLogger.info("deleting wallet " + path);

    File dir = new File(getFilesDir(), path);

    // Special case, the root wallet is not in a subdirectory.
    File child = null;
    if (path.equals(".")) {
      try {
        child = new File(dir, "salt");
        child.delete();
        child = new File(dir, "wallet32.spvchain");
        child.delete();
        child = new File(dir, "wallet32.hdwallet");
        child.delete();
        child = new File(dir, "wallet32.wallet");
        child.delete();
      } catch (Exception ex) {
        mLogger.error("delete of " + child.toString() + " failed");
      }
    } else {
      File[] directoryListing = dir.listFiles();
      for (File child2 : directoryListing) {
        try {
          mLogger.info("deleting " + child2.toString());
          child2.delete();
        } catch (Exception ex) {
          mLogger.error("delete of " + child2.toString() + " failed");
        }
      }
      try {
        dir.delete();
      } catch (Exception ex) {
        mLogger.error("delete of " + path + " failed");
      }
    }

    // Re-persist the wallet list without the deleted entry.
    List<WalletEntry> newWalletList = new ArrayList<WalletEntry>();
    List<WalletEntry> walletList = loadWalletDirectory();
    for (WalletEntry entry : walletList) if (!entry.mPath.equals(path)) newWalletList.add(entry);
    persistWalletDirectory(newWalletList);
  }
  public List<WalletEntry> listWallets() {
    List<WalletEntry> wallets = new ArrayList<WalletEntry>();

    File walletDirFile = new File(getFilesDir(), getWalletPrefix() + ".walletdir");

    // Does the directory not exist?
    if (!walletDirFile.exists()) {
      // Yes, we don't have a directory file yet.  Create a
      // default one with a single entry for default wallet.
      mLogger.info("creating default wallet directory in " + walletDirFile.getPath());
      wallets.add(new WalletEntry("Default", "."));
      persistWalletDirectory(wallets);
    } else {
      mLogger.info("reading wallet directory in " + walletDirFile.getPath());
      wallets = loadWalletDirectory();
    }

    return wallets;
  }