diff --git a/core/src/main/java/com/google/bitcoin/core/Wallet.java b/core/src/main/java/com/google/bitcoin/core/Wallet.java index cb88aa89..9e97ba13 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -3318,7 +3318,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha } /** - * Atomically adds extension or returns an existing extension if there is one with the same id alreadypresent. + * Atomically adds extension or returns an existing extension if there is one with the same id already present. */ public WalletExtension addOrGetExistingExtension(WalletExtension extension) { String id = checkNotNull(extension).getWalletExtensionID(); diff --git a/core/src/main/java/com/google/bitcoin/store/WalletProtobufSerializer.java b/core/src/main/java/com/google/bitcoin/store/WalletProtobufSerializer.java index 975c951e..6b2199ee 100644 --- a/core/src/main/java/com/google/bitcoin/store/WalletProtobufSerializer.java +++ b/core/src/main/java/com/google/bitcoin/store/WalletProtobufSerializer.java @@ -459,6 +459,9 @@ public class WalletProtobufSerializer { final Map extensions = new HashMap(); for (WalletExtension e : extensionsList) extensions.put(e.getWalletExtensionID(), e); + // The Wallet object, if subclassed, might have added some extensions to itself already. In that case, don't + // expect them to be passed in, just fetch them here and don't re-add. + extensions.putAll(wallet.getExtensions()); for (Protos.Extension extProto : walletProto.getExtensionList()) { String id = extProto.getId(); WalletExtension extension = extensions.get(id); @@ -473,7 +476,7 @@ public class WalletProtobufSerializer { log.info("Loading wallet extension {}", id); try { extension.deserializeWalletExtension(wallet, extProto.getData().toByteArray()); - wallet.addExtension(extension); + wallet.addOrGetExistingExtension(extension); } catch (Exception e) { if (extProto.getMandatory() && requireMandatoryExtensions) throw new UnreadableWalletException("Could not parse mandatory extension in wallet: " + id);