mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +00:00
Tweaks to allow wallet subclasses to add their own extensions in their c'tors.
This commit is contained in:
parent
748ff6fc8e
commit
e4af9a673f
@ -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();
|
||||
|
@ -459,6 +459,9 @@ public class WalletProtobufSerializer {
|
||||
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);
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user