diff --git a/core/src/main/java/org/bitcoinj/wallet/BasicKeyChain.java b/core/src/main/java/org/bitcoinj/wallet/BasicKeyChain.java index bbbe72f0abc..453eb5d77d0 100644 --- a/core/src/main/java/org/bitcoinj/wallet/BasicKeyChain.java +++ b/core/src/main/java/org/bitcoinj/wallet/BasicKeyChain.java @@ -409,7 +409,11 @@ public void addEventListener(KeyChainEventListener listener) { @Override public void addEventListener(KeyChainEventListener listener, Executor executor) { - listeners.add(new ListenerRegistration<>(listener, executor)); + addEventListener(new ListenerRegistration<>(listener, executor)); + } + + public void addEventListener(ListenerRegistration listener) { + listeners.add(listener); } @Override @@ -476,6 +480,9 @@ public BasicKeyChain toEncrypted(KeyCrypter keyCrypter, KeyParameter aesKey) { throw new KeyCrypterException("The key " + key.toString() + " cannot be successfully decrypted after encryption so aborting wallet encryption."); encrypted.importKeyLocked(encryptedKey); } + for (ListenerRegistration listener : listeners) { + encrypted.listeners.add(listener); + } return encrypted; } finally { lock.unlock(); @@ -501,6 +508,9 @@ public BasicKeyChain toDecrypted(KeyParameter aesKey) { for (ECKey key : hashToKeys.values()) { decrypted.importKeyLocked(key.decrypt(aesKey)); } + for (ListenerRegistration listener : listeners) { + decrypted.listeners.add(listener); + } return decrypted; } finally { lock.unlock(); diff --git a/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java b/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java index 96b0df75110..7828581ca4f 100644 --- a/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java +++ b/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java @@ -22,6 +22,7 @@ import org.bitcoinj.core.Utils; import org.bitcoinj.crypto.*; import org.bitcoinj.script.Script; +import org.bitcoinj.utils.ListenerRegistration; import org.bitcoinj.utils.Threading; import org.bitcoinj.wallet.listeners.KeyChainEventListener; @@ -428,6 +429,9 @@ protected DeterministicKeyChain(KeyCrypter crypter, KeyParameter aesKey, Determi hierarchy.putKey(key); basicKeyChain.importKey(key); } + for (ListenerRegistration listener : chain.basicKeyChain.getListeners()) { + basicKeyChain.addEventListener(listener); + } } public ImmutableList getAccountPath() { @@ -1030,6 +1034,9 @@ public DeterministicKeyChain toDecrypted(KeyParameter aesKey) { } chain.issuedExternalKeys = issuedExternalKeys; chain.issuedInternalKeys = issuedInternalKeys; + for (ListenerRegistration listener : basicKeyChain.getListeners()) { + chain.basicKeyChain.addEventListener(listener); + } return chain; }