From f37f6961081f1c98d8223519345509ff72fa30ff Mon Sep 17 00:00:00 2001 From: Sean Gilligan Date: Wed, 20 Apr 2022 12:23:06 -0700 Subject: [PATCH] DeterministicKeyChain: extract to static addChain() method --- .../wallet/DeterministicKeyChain.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java b/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java index 7db4e34fa..238b628d8 100644 --- a/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java +++ b/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java @@ -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 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 integerList) { HDPath path = HDPath.deserialize(integerList); return path.isEmpty() ? ACCOUNT_ZERO_PATH : path;