From d5f47f37d3532e0787b13e72ab24cc0aab77c83a Mon Sep 17 00:00:00 2001 From: Oscar Guindzberg Date: Tue, 20 Jan 2015 12:37:58 -0300 Subject: [PATCH] Allow building a MarriedKeyChain with a watchingKey --- .../org/bitcoinj/wallet/DeterministicKeyChain.java | 12 ++++++++++-- .../java/org/bitcoinj/wallet/MarriedKeyChain.java | 10 ++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java b/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java index 2ebf6dd4..dc04931f 100644 --- a/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java +++ b/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java @@ -162,6 +162,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain { protected long seedCreationTimeSecs; protected byte[] entropy; protected DeterministicSeed seed; + protected DeterministicKey watchingKey; protected Builder() { } @@ -214,6 +215,11 @@ public class DeterministicKeyChain implements EncryptableKeyChain { return self(); } + public T watchingKey(DeterministicKey watchingKey) { + this.watchingKey = watchingKey; + return self(); + } + /** The passphrase to use with the generated mnemonic, or null if you would like to use the default empty string. Currently must be the empty string. */ public T passphrase(String passphrase) { // FIXME support non-empty passphrase @@ -223,7 +229,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain { public DeterministicKeyChain build() { - checkState(random != null || entropy != null || seed != null, "Must provide either entropy or random"); + 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"); DeterministicKeyChain chain; @@ -232,8 +238,10 @@ public class DeterministicKeyChain implements EncryptableKeyChain { chain = new DeterministicKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs); } else if (entropy != null) { chain = new DeterministicKeyChain(entropy, getPassphrase(), seedCreationTimeSecs); - } else { + } else if (seed != null) { chain = new DeterministicKeyChain(seed); + } else { + chain = new DeterministicKeyChain(watchingKey, seedCreationTimeSecs); } return chain; diff --git a/core/src/main/java/org/bitcoinj/wallet/MarriedKeyChain.java b/core/src/main/java/org/bitcoinj/wallet/MarriedKeyChain.java index 3450f909..f2ec0e88 100644 --- a/core/src/main/java/org/bitcoinj/wallet/MarriedKeyChain.java +++ b/core/src/main/java/org/bitcoinj/wallet/MarriedKeyChain.java @@ -91,7 +91,7 @@ public class MarriedKeyChain extends DeterministicKeyChain { } public MarriedKeyChain build() { - checkState(random != null || entropy != null || seed != null, "Must provide either entropy or random"); + 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"); MarriedKeyChain chain; if (threshold == 0) @@ -100,8 +100,10 @@ public class MarriedKeyChain extends DeterministicKeyChain { chain = new MarriedKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs); } else if (entropy != null) { chain = new MarriedKeyChain(entropy, getPassphrase(), seedCreationTimeSecs); - } else { + } else if (seed != null) { chain = new MarriedKeyChain(seed); + } else { + chain = new MarriedKeyChain(watchingKey, seedCreationTimeSecs); } chain.addFollowingAccountKeys(followingKeys, threshold); return chain; @@ -117,6 +119,10 @@ public class MarriedKeyChain extends DeterministicKeyChain { super(accountKey, false); } + MarriedKeyChain(DeterministicKey accountKey, long seedCreationTimeSecs) { + super(accountKey, seedCreationTimeSecs); + } + MarriedKeyChain(DeterministicSeed seed, KeyCrypter crypter) { super(seed, crypter); }