DeterministicKeyChain: Change return type of getKeys() and getIssuedReceiveKeys() from List<ECKey> to List<DeterministicKey>.

This commit is contained in:
Andreas Schildbach
2019-02-19 11:53:55 +01:00
parent 2502847dfd
commit 09d5d33313

View File

@@ -1260,11 +1260,11 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
}
// For internal usage only
/* package */ List<ECKey> getKeys(boolean includeLookahead, boolean includeParents) {
/* package */ List<DeterministicKey> getKeys(boolean includeLookahead, boolean includeParents) {
List<ECKey> keys = basicKeyChain.getKeys();
List<DeterministicKey> result = new LinkedList<>();
if (!includeLookahead) {
int treeSize = internalParentKey.getPath().size();
List<ECKey> issuedKeys = new LinkedList<>();
for (ECKey key : keys) {
DeterministicKey detkey = (DeterministicKey) key;
DeterministicKey parent = detkey.getParent();
@@ -1272,20 +1272,23 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
if (!includeParents && detkey.getPath().size() <= treeSize) continue;
if (internalParentKey.equals(parent) && detkey.getChildNumber().i() >= issuedInternalKeys) continue;
if (externalParentKey.equals(parent) && detkey.getChildNumber().i() >= issuedExternalKeys) continue;
issuedKeys.add(detkey);
result.add(detkey);
}
return issuedKeys;
} else {
for (ECKey key : keys)
result.add((DeterministicKey) key);
// TODO includeParents is ignored here
}
return keys;
return result;
}
/**
* Returns only the external keys that have been issued by this chain, lookahead not included.
*/
public List<ECKey> getIssuedReceiveKeys() {
final List<ECKey> keys = new ArrayList<>(getKeys(false, false));
for (Iterator<ECKey> i = keys.iterator(); i.hasNext();) {
DeterministicKey parent = ((DeterministicKey) i.next()).getParent();
public List<DeterministicKey> getIssuedReceiveKeys() {
final List<DeterministicKey> keys = new ArrayList<>(getKeys(false, false));
for (Iterator<DeterministicKey> i = keys.iterator(); i.hasNext();) {
DeterministicKey parent = i.next().getParent();
if (parent == null || !externalParentKey.equals(parent))
i.remove();
}