Skip to content

Commit

Permalink
Tweaks to allow wallet subclasses to add their own extensions in thei…
Browse files Browse the repository at this point in the history
…r c'tors.
  • Loading branch information
mikehearn committed May 29, 2014
1 parent 748ff6f commit e4af9a6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/com/google/bitcoin/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3318,7 +3318,7 @@ public void addExtension(WalletExtension extension) {
}

/**
* 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ private void loadExtensions(Wallet wallet, WalletExtension[] extensionsList, Pro
final Map<String, WalletExtension> extensions = new HashMap<String, WalletExtension>();
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);
Expand All @@ -473,7 +476,7 @@ private void loadExtensions(Wallet wallet, WalletExtension[] extensionsList, Pro
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);
Expand Down

0 comments on commit e4af9a6

Please sign in to comment.