diff --git a/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java b/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java index c793c6d6..0debf8f7 100644 --- a/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java +++ b/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java @@ -245,25 +245,24 @@ public class DeterministicKeyChain implements EncryptableKeyChain { } public DeterministicKeyChain build() { - checkState(random != null || entropy != null || seed != null || watchingKey!= null, "Must provide either entropy or random or seed or watchingKey"); checkState(passphrase == null || seed == null, "Passphrase must not be specified with seed"); if (accountPath == null) accountPath = ACCOUNT_ZERO_PATH; - DeterministicKeyChain chain; - if (random != null) { + if (random != null) // Default passphrase to "" if not specified - chain = new DeterministicKeyChain(new DeterministicSeed(random, bits, getPassphrase()), null, accountPath); - } else if (entropy != null) { - chain = new DeterministicKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs), null, accountPath); - } else if (seed != null) { - chain = new DeterministicKeyChain(seed, null, accountPath); - } else { - chain = new DeterministicKeyChain(watchingKey); - } - - return chain; + return new DeterministicKeyChain(new DeterministicSeed(random, bits, getPassphrase()), null, + accountPath); + else if (entropy != null) + return new DeterministicKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs), + null, accountPath); + else if (seed != null) + return new DeterministicKeyChain(seed, null, accountPath); + else if (watchingKey != null) + return new DeterministicKeyChain(watchingKey); + else + throw new IllegalStateException(); } protected String getPassphrase() { diff --git a/core/src/main/java/org/bitcoinj/wallet/MarriedKeyChain.java b/core/src/main/java/org/bitcoinj/wallet/MarriedKeyChain.java index 48f03955..5cd7eda0 100644 --- a/core/src/main/java/org/bitcoinj/wallet/MarriedKeyChain.java +++ b/core/src/main/java/org/bitcoinj/wallet/MarriedKeyChain.java @@ -94,7 +94,6 @@ public class MarriedKeyChain extends DeterministicKeyChain { @Override public MarriedKeyChain build() { - checkState(random != null || entropy != null || seed != null || watchingKey!= null, "Must provide either entropy or random or seed or watchingKey"); checkNotNull(followingKeys, "followingKeys must be provided"); if (threshold == 0) @@ -103,15 +102,17 @@ public class MarriedKeyChain extends DeterministicKeyChain { accountPath = ACCOUNT_ZERO_PATH; MarriedKeyChain chain; - if (random != null) { + if (random != null) chain = new MarriedKeyChain(new DeterministicSeed(random, bits, getPassphrase()), null, accountPath); - } else if (entropy != null) { - chain = new MarriedKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs), null, accountPath); - } else if (seed != null) { + else if (entropy != null) + chain = new MarriedKeyChain(new DeterministicSeed(entropy, getPassphrase(), creationTimeSecs), null, + accountPath); + else if (seed != null) chain = new MarriedKeyChain(seed, null, accountPath); - } else { + else if (watchingKey != null) chain = new MarriedKeyChain(watchingKey); - } + else + throw new IllegalStateException(); chain.addFollowingAccountKeys(followingKeys, threshold); return chain; }