@Test public void deleteAccount() throws Exception { KeyStoreImpl keyStore = new KeyStoreImpl(new FakeStore(), new FakeBackupRestore()); KeyPair account1 = keyStore.newAccount(); KeyPair keyPair = keyStore.newAccount(); keyStore.deleteAccount(keyPair.getAccountId()); List<KeyPair> accounts = keyStore.loadAccounts(); assertEquals(1, accounts.size()); assertEquals(String.valueOf(account1.getSecretSeed()), String.valueOf(accounts.get(0).getSecretSeed())); }
@Override public void deleteAccount(String publicAddress) throws DeleteAccountException { JSONObject json = new JSONObject(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { JSONArray newJsonArray = new JSONArray(); for (int i = 0; i < jsonArray.length(); i++) { Object account = jsonArray.get(i); if (!((JSONObject) account).get(JSON_KEY_PUBLIC_KEY).equals(publicAddress)) { newJsonArray.put(account); } } json.put(JSON_KEY_ACCOUNTS_ARRAY, newJsonArray); } } catch (JSONException e) { throw new DeleteAccountException(e); } store.saveString(STORE_KEY_ACCOUNTS, json.toString()); }
KeyStoreImpl implements KeyStore { @Override public void deleteAccount(String publicAddress) throws DeleteAccountException { JSONObject json = new JSONObject(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { JSONArray newJsonArray = new JSONArray(); for (int i = 0; i < jsonArray.length(); i++) { Object account = jsonArray.get(i); if (!((JSONObject) account).get(JSON_KEY_PUBLIC_KEY).equals(publicAddress)) { newJsonArray.put(account); } } json.put(JSON_KEY_ACCOUNTS_ARRAY, newJsonArray); } } catch (JSONException e) { throw new DeleteAccountException(e); } store.saveString(STORE_KEY_ACCOUNTS, json.toString()); } }
KeyStoreImpl implements KeyStore { @Override public void deleteAccount(String publicAddress) throws DeleteAccountException { JSONObject json = new JSONObject(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { JSONArray newJsonArray = new JSONArray(); for (int i = 0; i < jsonArray.length(); i++) { Object account = jsonArray.get(i); if (!((JSONObject) account).get(JSON_KEY_PUBLIC_KEY).equals(publicAddress)) { newJsonArray.put(account); } } json.put(JSON_KEY_ACCOUNTS_ARRAY, newJsonArray); } } catch (JSONException e) { throw new DeleteAccountException(e); } store.saveString(STORE_KEY_ACCOUNTS, json.toString()); } KeyStoreImpl(@NonNull Store store, @NonNull BackupRestore backupRestore); }
KeyStoreImpl implements KeyStore { @Override public void deleteAccount(String publicAddress) throws DeleteAccountException { JSONObject json = new JSONObject(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { JSONArray newJsonArray = new JSONArray(); for (int i = 0; i < jsonArray.length(); i++) { Object account = jsonArray.get(i); if (!((JSONObject) account).get(JSON_KEY_PUBLIC_KEY).equals(publicAddress)) { newJsonArray.put(account); } } json.put(JSON_KEY_ACCOUNTS_ARRAY, newJsonArray); } } catch (JSONException e) { throw new DeleteAccountException(e); } store.saveString(STORE_KEY_ACCOUNTS, json.toString()); } KeyStoreImpl(@NonNull Store store, @NonNull BackupRestore backupRestore); @NonNull @Override List<KeyPair> loadAccounts(); @Override void deleteAccount(String publicAddress); @Override KeyPair newAccount(); @Override KeyPair importAccount(@NonNull String json, @NonNull String passphrase); @Override void clearAllAccounts(); }
KeyStoreImpl implements KeyStore { @Override public void deleteAccount(String publicAddress) throws DeleteAccountException { JSONObject json = new JSONObject(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { JSONArray newJsonArray = new JSONArray(); for (int i = 0; i < jsonArray.length(); i++) { Object account = jsonArray.get(i); if (!((JSONObject) account).get(JSON_KEY_PUBLIC_KEY).equals(publicAddress)) { newJsonArray.put(account); } } json.put(JSON_KEY_ACCOUNTS_ARRAY, newJsonArray); } } catch (JSONException e) { throw new DeleteAccountException(e); } store.saveString(STORE_KEY_ACCOUNTS, json.toString()); } KeyStoreImpl(@NonNull Store store, @NonNull BackupRestore backupRestore); @NonNull @Override List<KeyPair> loadAccounts(); @Override void deleteAccount(String publicAddress); @Override KeyPair newAccount(); @Override KeyPair importAccount(@NonNull String json, @NonNull String passphrase); @Override void clearAllAccounts();  }