DeterministicKeyChain: extract to static addChain() method

This commit is contained in:
Sean Gilligan 2022-04-20 12:23:06 -07:00 committed by Andreas Schildbach
parent 6ac5f0b5a7
commit f37f696108

View File

@ -840,11 +840,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
if (t == Protos.Key.Type.DETERMINISTIC_MNEMONIC) {
accountPath = deserializeAccountPath(key.getAccountPathList());
if (chain != null) {
checkState(lookaheadSize >= 0);
chain.setLookaheadSize(lookaheadSize);
chain.setSigsRequiredToSpend(sigsRequiredToSpend);
chain.maybeLookAhead();
chains.add(chain);
addChain(chains, chain, lookaheadSize, sigsRequiredToSpend);
chain = null;
}
long timestamp = key.getCreationTimestamp() / 1000;
@ -892,11 +888,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
// placed in new following key chain
if (key.getDeterministicKey().getIsFollowing()) {
if (chain != null) {
checkState(lookaheadSize >= 0);
chain.setLookaheadSize(lookaheadSize);
chain.setSigsRequiredToSpend(sigsRequiredToSpend);
chain.maybeLookAhead();
chains.add(chain);
addChain(chains, chain, lookaheadSize, sigsRequiredToSpend);
chain = null;
seed = null;
}
@ -986,15 +978,19 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
}
}
if (chain != null) {
checkState(lookaheadSize >= 0);
chain.setLookaheadSize(lookaheadSize);
chain.setSigsRequiredToSpend(sigsRequiredToSpend);
chain.maybeLookAhead();
chains.add(chain);
addChain(chains, chain, lookaheadSize, sigsRequiredToSpend);
}
return chains;
}
private static void addChain(List<DeterministicKeyChain> chains, DeterministicKeyChain chain, int lookaheadSize, int sigsRequiredToSpend) {
checkState(lookaheadSize >= 0);
chain.setLookaheadSize(lookaheadSize);
chain.setSigsRequiredToSpend(sigsRequiredToSpend);
chain.maybeLookAhead();
chains.add(chain);
}
private static HDPath deserializeAccountPath(List<Integer> integerList) {
HDPath path = HDPath.deserialize(integerList);
return path.isEmpty() ? ACCOUNT_ZERO_PATH : path;