HD Wallets: add getImportedKeys() method that returns just the basic key chain.

This commit is contained in:
Mike Hearn 2014-03-28 12:25:26 +01:00
parent 6951a6bc65
commit dbf504faa0
3 changed files with 21 additions and 0 deletions

View File

@ -358,6 +358,18 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
}
}
/**
* 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);

View File

@ -276,6 +276,13 @@ public class KeyChainGroup {
/** 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)

View File

@ -1417,6 +1417,8 @@ public class WalletTest extends TestWithWallet {
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));