Skip to content

Commit

Permalink
HD Wallets: add getImportedKeys() method that returns just the basic …
Browse files Browse the repository at this point in the history
…key chain.
  • Loading branch information
mikehearn committed May 29, 2014
1 parent 6951a6b commit dbf504f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/com/google/bitcoin/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ public int getKeychainSize() {
}
}

/**
* Returns a list of the non-deterministic keys that have been imported into the wallet, or the empty list if none.
*/
public List<ECKey> getImportedKeys() {
lock.lock();
try {
return keychain.getImportedKeys();
} finally {
lock.unlock();
}
}

/** Returns the address used for change outputs. Note: this will probably go away in future. */
public Address getChangeAddress() {
return currentKey(KeyChain.KeyPurpose.CHANGE).toAddress(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ public boolean isEncrypted() {
/** Returns the key crypter or null if the group is not encrypted. */
@Nullable public KeyCrypter getKeyCrypter() { return keyCrypter; }

/**
* Returns a list of the non-deterministic keys that have been imported into the wallet, or the empty list if none.
*/
public List<ECKey> getImportedKeys() {
return basic.getKeys();
}

public long getEarliestKeyCreationTime() {
long time = basic.getEarliestKeyCreationTime(); // Long.MAX_VALUE if empty.
for (DeterministicKeyChain chain : chains)
Expand Down
2 changes: 2 additions & 0 deletions core/src/test/java/com/google/bitcoin/core/WalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,8 @@ public void mismatchedCrypter() throws Exception {
public void importAndEncrypt() throws IOException, InsufficientMoneyException {
final ECKey key = new ECKey();
encryptedWallet.importKeysAndEncrypt(ImmutableList.of(key), PASSWORD1);
assertEquals(1, encryptedWallet.getImportedKeys().size());
assertEquals(key.getPubKeyPoint(), encryptedWallet.getImportedKeys().get(0).getPubKeyPoint());
sendMoneyToWallet(encryptedWallet, Utils.COIN, key.toAddress(params), AbstractBlockChain.NewBlockType.BEST_CHAIN);
assertEquals(Utils.COIN, encryptedWallet.getBalance());
SendRequest req = Wallet.SendRequest.emptyWallet(new ECKey().toAddress(params));
Expand Down

0 comments on commit dbf504f

Please sign in to comment.