Fix off by one in DKC.getKeys(false). Resolves #253

This commit is contained in:
Mike Hearn
2014-10-22 22:00:31 +02:00
parent cd25e673f1
commit afb05867a9
2 changed files with 10 additions and 2 deletions

View File

@@ -1186,8 +1186,8 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
DeterministicKey parent = detkey.getParent();
if (parent == null) continue;
if (detkey.getPath().size() <= treeSize) continue;
if (parent.equals(internalKey) && detkey.getChildNumber().i() > issuedInternalKeys) continue;
if (parent.equals(externalKey) && detkey.getChildNumber().i() > issuedExternalKeys) continue;
if (parent.equals(internalKey) && detkey.getChildNumber().i() >= issuedInternalKeys) continue;
if (parent.equals(externalKey) && detkey.getChildNumber().i() >= issuedExternalKeys) continue;
issuedKeys.add(detkey);
}
return issuedKeys;

View File

@@ -72,6 +72,14 @@ public class DeterministicKeyChainTest {
key3.sign(Sha256Hash.ZERO_HASH);
}
@Test
public void getKeys() throws Exception {
chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
chain.getKey(KeyChain.KeyPurpose.CHANGE);
chain.maybeLookAhead();
assertEquals(2, chain.getKeys(false).size());
}
@Test
public void signMessage() throws Exception {
ECKey key = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);