WalletManager { public boolean isWalletAddressExists(String prefixAddress) { boolean isCacheExists = false; if (TextUtils.isEmpty(prefixAddress)) { return false; } if (mWalletList == null || mWalletList.isEmpty()) { return false; } for (Wallet walletEntity : mWalletList) { if (walletEntity.getPrefixAddress().toLowerCase().equals(prefixAddress.toLowerCase())) { isCacheExists = true; return true; } } if(!isCacheExists){ Wallet wallet = WalletManager.getInstance().getWalletInfoByAddress(prefixAddress); if(wallet != null && (wallet.getPrefixAddress() != null && !wallet.getPrefixAddress().equals("")) && wallet.getPrefixAddress().equals(prefixAddress)){ return true; } } return false; } private  WalletManager(); static WalletManager getInstance(); void initWalletNet(); boolean isMainNetWalletAddress(); BigDecimal getSumAccountBalance(); void setSumAccountBalance(BigDecimal sumAccountBalance); Wallet getSelectedWallet(); void addAndSelectedWalletStatusNotice(Wallet selectedWallet); void setWalletList(List<Wallet> walletList); String getSelectedWalletAddress(); void perInit(); void init(); Single<List<Wallet>> getWalletListFromDB(); Single<List<Wallet>> getWalletInfoListByOrdinaryAndSubWallet(); Single<List<Wallet>> getWalletListFromDBByOrdinaryAndHD(); Single<List<Wallet>> getHDWalletListDBByParentId(String parendId); Wallet getWalletInfoByUuid(String uuid); Wallet getWalletInfoByAddress(String address); List<TransactionWallet> getTransactionWalletData(); int getWalletInfoListByOrdinaryAndSubWalletNum(); List<Wallet> getWalletListByOrdinaryAndHD(); List<Wallet> getHDWalletListByParentId(String parentId); String getMnemonicByUuid(String uuid); List<Wallet> getWalletListByAddressAndNameAndType(@WalletTypeSearch int walletType,String name,String address); void addWallet(Wallet wallet); void updateAccountBalance(AccountBalance accountBalance); boolean updateSubWalletIsShowByUuid(Wallet oldWallet, Wallet newWallet); Boolean updateDBSelectedWalletByUuid(String uuid); Boolean updateDBWalletSortIndexByUuid(Wallet wallet, int sortIndex); AccountBalance getAccountBalance(String address); List<String> getAddressListFromDB(); List<String> getAddressList(); Single<String> getWalletNameFromAddress(String address); boolean isObservedWallet(String walletAddress); String getWalletNameByWalletAddress(String walletAddress); String getWalletIconByWalletAddress(String walletAddress); List<Wallet> getWalletList(); String generateMnemonic(); String exportPrivateKey(String mnemonic); Single<Wallet> createWallet(String name, String password); Single<List<Wallet>> createWalletList(String name, String password); int importKeystore(String store, String name, String password); int importWalletAddress(String walletAddress); int importPrivateKey(String privateKey, String name, String password); Single<Wallet> importMnemonicGenerateWallet(String mnemonic, String name, String password, int... index); int importMnemonic(String mnemonic, String name, String password, @WalletType int walletType); boolean updateWalletName(Wallet wallet, String newName); boolean updateBackedUpWithUuid(Wallet wallet, boolean backedUp); void updateWalletBackedUpPromptWithUUID(String uuid, boolean isBackedUp); Wallet getWalletByAddress(String address); boolean deleteWallet(Wallet wallet); boolean deleteBatchWallet(Wallet rootWallet); boolean isValidWallet(Wallet walletEntity, String password); boolean isWalletNameExistsFromDB(String walletName); boolean isWalletNameExists(String walletName); boolean isWalletAddressExists(String prefixAddress); Observable<BigDecimal> getAccountBalance(); int getPositionByAddress(String address); Observable<BigDecimal> getTotal(); Wallet getFirstSortedWallet(); static final int CODE_OK; static final int CODE_ERROR_NAME; static final int CODE_ERROR_PASSWORD; static final int CODE_ERROR_KEYSTORE; static final int CODE_ERROR_PRIVATEKEY; static final int CODE_ERROR_MNEMONIC; static final int CODE_ERROR_WALLET_EXISTS; static final int CODE_ERROR_UNKNOW; static final int CODE_ERROR_INVALIA_ADDRESS; }
@Test public void isWalletAddressExists() { List<Wallet> list = new ArrayList<>(); Wallet wallet = new Wallet(); wallet.setCreateTime(1115448481); wallet.setName("001"); wallet.setAddress("0xfb1b74328f936973a59620d683e1b1acb487d9e7"); AccountBalance balance = new AccountBalance(); balance.setFree("10000000084489"); balance.setLock("0"); wallet.setAccountBalance(balance); list.add(wallet); Wallet wallet2 = new Wallet(); wallet2.setCreateTime(1115448485); wallet2.setName("002"); wallet2.setAddress("0x2e95e3ce0a54951eb9a99152a6d5827872dfb4fd"); AccountBalance balance2 = new AccountBalance(); balance2.setFree("1000000005655655"); balance2.setLock("0"); wallet2.setAccountBalance(balance2); list.add(wallet2); Wallet wallet3 = new Wallet(); wallet3.setName("003"); wallet3.setAddress("0xca4b151b0b100ae53c9d78dd136905e681622ee7"); wallet3.setCreateTime(1115448483); AccountBalance balance3 = new AccountBalance(); balance3.setFree("10000000056556584855"); balance3.setLock("0"); wallet3.setAccountBalance(balance3); list.add(wallet3); Wallet wallet4 = new Wallet(); wallet4.setName("004"); wallet4.setCreateTime(1115448486); AccountBalance balance4 = new AccountBalance(); balance4.setFree("1000000001156584855"); balance4.setLock("0"); wallet4.setAccountBalance(balance4); list.add(wallet4); String address = "0x2e95e3ce0a54951eb9a99152a6d5827872dfb4fd"; boolean isExitAddress = Flowable .fromIterable(list) .map(new Function<Wallet, Boolean>() { @Override public Boolean apply(Wallet walletEntity) throws Exception { return walletEntity.getPrefixAddress().toLowerCase().equalsIgnoreCase(address.toLowerCase()); } }) .filter(new Predicate<Boolean>() { @Override public boolean test(Boolean aBoolean) throws Exception { return aBoolean; } }) .firstElement() .defaultIfEmpty(false) .blockingGet(); Log.d("=========", "地址是否存在" + "====>" + isExitAddress); }