/** * Get a fresh address by marking the current receive address as used. It will throw * {@link Bip44KeyLookAheadExceededException} if we requested too many addresses that * exceed the BIP44 look ahead threshold. */ public BitAddress getFreshReceiveAddress() throws Bip44KeyLookAheadExceededException { lock.lock(); try { if (!canCreateFreshReceiveAddress()) { throw new Bip44KeyLookAheadExceededException(); } keys.getKey(RECEIVE_FUNDS); return currentAddress(RECEIVE_FUNDS); } finally { lock.unlock(); walletSaveNow(); } }
private void createAddress(WalletPocketHD account, @Nullable String newLabel) { if (account.canCreateFreshReceiveAddress()) { try { AbstractAddress newAddress = account.getFreshReceiveAddress( app.getConfiguration().isManualAddressManagement()); if (newLabel != null && !newLabel.isEmpty()) { final Uri uri = AddressBookProvider.contentUri(getActivity().getPackageName(), account.getCoinType()) .buildUpon().appendPath(newAddress.toString()).build(); final ContentValues values = new ContentValues(); values.put(AddressBookProvider.KEY_LABEL, newLabel); if (resolver != null) resolver.insert(uri, values); } } catch (Bip44KeyLookAheadExceededException e) { // Should not happen as we already checked if we can create a new address Toast.makeText(getActivity(), R.string.too_many_unused_addresses, Toast.LENGTH_LONG).show(); } } else { Toast.makeText(getContext(), R.string.too_many_unused_addresses, Toast.LENGTH_LONG).show(); } } }
if (pocketHD.canCreateFreshReceiveAddress()) { final LayoutInflater inflater = LayoutInflater.from(getActivity()); final View view = inflater.inflate(R.layout.new_address_dialog, null);
@Test public void issuedKeysLimit2() throws Exception { assertTrue(pocket.canCreateFreshReceiveAddress()); try { for (int i = 0; i < 100; i++) { pocket.getFreshReceiveAddress(); } } catch (Bip44KeyLookAheadExceededException e) { assertFalse(pocket.canCreateFreshReceiveAddress()); // We haven't used any key so the total must be 20 - 1 (the unused key) assertEquals(19, pocket.getNumberIssuedReceiveAddresses()); assertEquals(19, pocket.getIssuedReceiveAddresses().size()); } }
@Test public void issuedKeysLimit() throws Exception { assertTrue(pocket.canCreateFreshReceiveAddress()); try { for (int i = 0; i < 100; i++) { assertFalse(pocket.canCreateFreshReceiveAddress()); assertTrue(pocket.canCreateFreshReceiveAddress()); try { for (int i = 0; i < 100; i++) { assertFalse(pocket.canCreateFreshReceiveAddress());