@Test public void getKey() { ECKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(onKeysAddedRan.getAndSet(false)); assertEquals(key1, onKeysAdded.getAndSet(null).get(0)); ECKey key2 = chain.getKey(KeyChain.KeyPurpose.CHANGE); assertFalse(onKeysAddedRan.getAndSet(false)); assertEquals(key2, key1); }
@Override public ECKey getKey(@Nullable KeyPurpose ignored) { lock.lock(); try { if (hashToKeys.isEmpty()) { checkState(keyCrypter == null); final ECKey key = new ECKey(); importKeyLocked(key); queueOnKeysAdded(ImmutableList.of(key)); } return hashToKeys.values().iterator().next(); } finally { lock.unlock(); } }
BasicKeyChain implements EncryptableKeyChain { @Override public ECKey getKey(@Nullable KeyPurpose ignored) { lock.lock(); try { if (hashToKeys.isEmpty()) { checkState(keyCrypter == null); final ECKey key = new ECKey(); importKeyLocked(key); queueOnKeysAdded(ImmutableList.of(key)); } return hashToKeys.values().iterator().next(); } finally { lock.unlock(); } } }
BasicKeyChain implements EncryptableKeyChain { @Override public ECKey getKey(@Nullable KeyPurpose ignored) { lock.lock(); try { if (hashToKeys.isEmpty()) { checkState(keyCrypter == null); final ECKey key = new ECKey(); importKeyLocked(key); queueOnKeysAdded(ImmutableList.of(key)); } return hashToKeys.values().iterator().next(); } finally { lock.unlock(); } } BasicKeyChain();  BasicKeyChain(@Nullable KeyCrypter crypter); }
BasicKeyChain implements EncryptableKeyChain { @Override public ECKey getKey(@Nullable KeyPurpose ignored) { lock.lock(); try { if (hashToKeys.isEmpty()) { checkState(keyCrypter == null); final ECKey key = new ECKey(); importKeyLocked(key); queueOnKeysAdded(ImmutableList.of(key)); } return hashToKeys.values().iterator().next(); } finally { lock.unlock(); } } BasicKeyChain();  BasicKeyChain(@Nullable KeyCrypter crypter); @Override @Nullable KeyCrypter getKeyCrypter(); @Override ECKey getKey(@Nullable KeyPurpose ignored); @Override List<ECKey> getKeys(@Nullable KeyPurpose purpose, int numberOfKeys); List<ECKey> getKeys(); int importKeys(ECKey... keys); int importKeys(List<? extends ECKey> keys); void importKey(ECKey key); ECKey findKeyFromPubHash(byte[] pubKeyHash); ECKey findKeyFromPubKey(byte[] pubKey); @Override boolean hasKey(ECKey key); @Override int numKeys(); State isWatching(); boolean removeKey(ECKey key); @Override long getEarliestKeyCreationTime(); List<ListenerRegistration<KeyChainEventListener>> getListeners(); @Override List<Protos.Key> serializeToProtobuf(); static BasicKeyChain fromProtobufUnencrypted(List<Protos.Key> keys); static BasicKeyChain fromProtobufEncrypted(List<Protos.Key> keys, KeyCrypter crypter); @Override void addEventListener(KeyChainEventListener listener); @Override void addEventListener(KeyChainEventListener listener, Executor executor); @Override boolean removeEventListener(KeyChainEventListener listener); @Override BasicKeyChain toEncrypted(CharSequence password); @Override BasicKeyChain toEncrypted(KeyCrypter keyCrypter, KeyParameter aesKey); @Override BasicKeyChain toDecrypted(CharSequence password); @Override BasicKeyChain toDecrypted(KeyParameter aesKey); @Override boolean checkPassword(CharSequence password); @Override boolean checkAESKey(KeyParameter aesKey); @Override BloomFilter getFilter(int size, double falsePositiveRate, long tweak); @Override int numBloomFilterEntries(); @Nullable ECKey findOldestKeyAfter(long timeSecs); List<ECKey> findKeysBefore(long timeSecs); String toString(boolean includePrivateKeys, @Nullable KeyParameter aesKey, NetworkParameters params); }
BasicKeyChain implements EncryptableKeyChain { @Override public ECKey getKey(@Nullable KeyPurpose ignored) { lock.lock(); try { if (hashToKeys.isEmpty()) { checkState(keyCrypter == null); final ECKey key = new ECKey(); importKeyLocked(key); queueOnKeysAdded(ImmutableList.of(key)); } return hashToKeys.values().iterator().next(); } finally { lock.unlock(); } } BasicKeyChain();  BasicKeyChain(@Nullable KeyCrypter crypter); @Override @Nullable KeyCrypter getKeyCrypter(); @Override ECKey getKey(@Nullable KeyPurpose ignored); @Override List<ECKey> getKeys(@Nullable KeyPurpose purpose, int numberOfKeys); List<ECKey> getKeys(); int importKeys(ECKey... keys); int importKeys(List<? extends ECKey> keys); void importKey(ECKey key); ECKey findKeyFromPubHash(byte[] pubKeyHash); ECKey findKeyFromPubKey(byte[] pubKey); @Override boolean hasKey(ECKey key); @Override int numKeys(); State isWatching(); boolean removeKey(ECKey key); @Override long getEarliestKeyCreationTime(); List<ListenerRegistration<KeyChainEventListener>> getListeners(); @Override List<Protos.Key> serializeToProtobuf(); static BasicKeyChain fromProtobufUnencrypted(List<Protos.Key> keys); static BasicKeyChain fromProtobufEncrypted(List<Protos.Key> keys, KeyCrypter crypter); @Override void addEventListener(KeyChainEventListener listener); @Override void addEventListener(KeyChainEventListener listener, Executor executor); @Override boolean removeEventListener(KeyChainEventListener listener); @Override BasicKeyChain toEncrypted(CharSequence password); @Override BasicKeyChain toEncrypted(KeyCrypter keyCrypter, KeyParameter aesKey); @Override BasicKeyChain toDecrypted(CharSequence password); @Override BasicKeyChain toDecrypted(KeyParameter aesKey); @Override boolean checkPassword(CharSequence password); @Override boolean checkAESKey(KeyParameter aesKey); @Override BloomFilter getFilter(int size, double falsePositiveRate, long tweak); @Override int numBloomFilterEntries(); @Nullable ECKey findOldestKeyAfter(long timeSecs); List<ECKey> findKeysBefore(long timeSecs); String toString(boolean includePrivateKeys, @Nullable KeyParameter aesKey, NetworkParameters params);  }