public ArrayList<WalletItem> all() { ArrayList<WalletItem> list = new ArrayList<WalletItem>(pCaches.size()); for (int i = 0; i < pCaches.size(); i++) { list.add((WalletItem) pCaches.get(i)); } return list; }
public void save(File file) throws Exception { int idx = 0; int size = pCaches.size(); if (size == 0) { return; } synchronized (pCaches) { StringBuilder sbr = new StringBuilder(); WalletSeed seed = new WalletSeed(LSystem.getAppPassword()); for (int i = 0; i < size; i++) { WalletItem item = (WalletItem) pCaches.getEntry(i).getValue(); if (!item.isOnline()) { RPAddress address = new RPAddress(item.getPublicKey(), item.getPrivateKey()); sbr.append(item.getDate()); sbr.append(','); sbr.append(address.getPublic()); sbr.append(','); sbr.append(address.getPrivate()); sbr.append(','); sbr.append(item.getAmount()); sbr.append(','); sbr.append(item.getStatus()); idx++; if (idx < size) { sbr.append(LSystem.LS); } } } seed.save(file, sbr.toString()); } }
public WalletItem findItem(String address) { synchronized (pCaches) { int size = pCaches.size(); if (size > 0) { for (int i = 0; i < size; i++) { WalletItem item = (WalletItem) pCaches.get(i); if (item.getPublicKey().equals(address)) { return item; } } } return null; } }
public void add(String pubKey, String priKey, boolean online) { String key = pubKey.concat(priKey); if (!pCaches.containsKey(key)) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(Calendar.getInstance().getTime()); String date = String.format( "%04d-%02d-%02d", cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH)); WalletItem walletItem = new WalletItem(date, priKey, "0.000000", "none"); walletItem.setOnline(online); pCaches.put(key, walletItem); } }
public void deleted(int idx) { synchronized (pCaches) { int size = pCaches.size(); if (idx > -1 && idx < size) { pCaches.remove(idx); } if (pCaches.size() == 0) { String fileName = LSystem.getDirectory() + LSystem.FS + LSystem.walletName; File file = new File(fileName); if (file.exists()) { file.deleteOnExit(); } } } }
public void reset() { synchronized (pCaches) { BigDecimal count = new BigDecimal("0"); int size = pCaches.size(); for (int i = 0; i < size; i++) { WalletItem item = (WalletItem) pCaches.getEntry(i).getValue(); if (MathUtils.isNan(item.getAmount())) { count = count.add(new BigDecimal(item.getAmount())); } RPClient.ripple().xrp(item); } int res = count.intValue(); if (res > 0) { amounts = String.valueOf(res); } } }
public String load(File file) throws Exception { synchronized (pCaches) { WalletSeed seed = new WalletSeed(LSystem.getAppPassword()); String text = seed.load(file); StringTokenizer tokenizer = new StringTokenizer(text, LSystem.LS); String result = null; BigDecimal count = new BigDecimal("0"); for (; tokenizer.hasMoreElements(); ) { result = tokenizer.nextToken(); if (result != null && result.length() > 0) { String[] split = result.split(","); if (split.length > 4) { String date = split[0]; String pubKey = split[1]; String priKey = split[2]; String amount = split[3]; String status = split[4]; RPAddress address = new RPAddress(pubKey, priKey); pubKey = new String(address.getPublic()); priKey = new String(address.getPrivate()); String key = pubKey.concat(priKey); if (!pCaches.containsKey(key)) { WalletItem walletItem = new WalletItem(date, priKey, amount, status); if (MathUtils.isNan(amount)) { count = count.add(new BigDecimal(amount)); } pCaches.put(key, walletItem); } } } int res = count.intValue(); if (res > 0) { amounts = String.valueOf(res); } } return text; } }
public WalletItem readRow(int index) { return (WalletItem) pCaches.get(index); }
public int size() { return pCaches.size(); }