SimpleHDKeyChain implements EncryptableKeyChain, KeyBag { @Nullable public DeterministicKey getLastIssuedKey(KeyPurpose purpose) { lock.lock(); try { List<DeterministicKey> keys; switch (purpose) { case RECEIVE_FUNDS: case REFUND: if (issuedExternalKeys <= 0) return null; keys = getDeterministicKeys(1, externalKey, issuedExternalKeys); break; case CHANGE: if (issuedInternalKeys <= 0) return null; keys = getDeterministicKeys(1, internalKey, issuedInternalKeys); break; default: throw new UnsupportedOperationException(); } return keys.get(0); } finally { lock.unlock(); } } SimpleHDKeyChain(DeterministicKey rootkey);   SimpleHDKeyChain(DeterministicKey rootkey, @Nullable KeyCrypter crypter);   SimpleHDKeyChain(DeterministicKey rootkey, @Nullable KeyCrypter crypter,
                     @Nullable KeyParameter key); private  SimpleHDKeyChain(KeyCrypter crypter, KeyParameter aesKey, SimpleHDKeyChain chain); boolean isEncrypted(); DeterministicKey getCurrentUnusedKey(KeyPurpose purpose); @Nullable DeterministicKey getLastIssuedKey(KeyPurpose purpose); @Override DeterministicKey getKey(KeyPurpose purpose); @Override List<DeterministicKey> getKeys(KeyPurpose purpose, int numberOfKeys); DeterministicKey markKeyAsUsed(DeterministicKey k); @Override DeterministicKey findKeyFromPubHash(byte[] pubkeyHash); @Override DeterministicKey findKeyFromPubKey(byte[] pubkey); @Nullable @Override RedeemData findRedeemDataFromScriptHash(byte[] bytes); boolean markPubHashAsUsed(byte[] pubkeyHash); boolean markPubKeyAsUsed(byte[] pubkey); @Override boolean hasKey(ECKey key); DeterministicKey getWatchingKey(); @Override int numKeys(); DeterministicKey getRootKey(); int numLeafKeysIssued(); @Override long getEarliestKeyCreationTime(); @Override void addEventListener(KeyChainEventListener listener); @Override void addEventListener(KeyChainEventListener listener, Executor executor); @Override boolean removeEventListener(KeyChainEventListener listener); boolean isFollowing(); static SimpleHDKeyChain fromProtobuf(List<Protos.Key> keys); static SimpleHDKeyChain fromProtobuf(List<Protos.Key> keys, @Nullable KeyCrypter crypter); @Override List<org.bitcoinj.wallet.Protos.Key> serializeToProtobuf(); @Override SimpleHDKeyChain toEncrypted(CharSequence password); @Override SimpleHDKeyChain toEncrypted(KeyCrypter keyCrypter, KeyParameter aesKey); @Override SimpleHDKeyChain toDecrypted(CharSequence password); @Override SimpleHDKeyChain toDecrypted(KeyParameter aesKey); @Override boolean checkPassword(CharSequence password); @Override boolean checkAESKey(KeyParameter aesKey); @Nullable @Override KeyCrypter getKeyCrypter(); @Override int numBloomFilterEntries(); @Override BloomFilter getFilter(int size, double falsePositiveRate, long tweak); int getLookaheadSize(); void setLookaheadSize(int lookaheadSize); void setLookaheadThreshold(int num); int getLookaheadThreshold(); void maybeLookAhead(); ArrayList<DeterministicKey> getIssuedExternalKeys(); int getNumIssuedExternalKeys(); int getNumIssuedInternalKeys(); List<DeterministicKey> getActiveKeys(); boolean isExternal(DeterministicKey key); int getAccountIndex(); static final int LOOKAHEAD; static final ChildNumber EXTERNAL_PATH_NUM; static final ChildNumber INTERNAL_PATH_NUM; static final ImmutableList<ChildNumber> EXTERNAL_PATH; static final ImmutableList<ChildNumber> INTERNAL_PATH; }
@Test public void getLastIssuedKey() { assertNull(chain.getLastIssuedKey(KeyChain.KeyPurpose.RECEIVE_FUNDS)); assertNull(chain.getLastIssuedKey(KeyChain.KeyPurpose.CHANGE)); DeterministicKey extKey = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); DeterministicKey intKey = chain.getKey(KeyChain.KeyPurpose.CHANGE); assertEquals(extKey, chain.getLastIssuedKey(KeyChain.KeyPurpose.RECEIVE_FUNDS)); assertEquals(intKey, chain.getLastIssuedKey(KeyChain.KeyPurpose.CHANGE)); }