Wallet: allow customization of the wallet type that is deserialized. Makes subclassing Wallet more useful.

This commit is contained in:
Mike Hearn 2014-04-23 16:48:57 +02:00
parent b374ba5108
commit d2837e8ea9

View File

@ -74,8 +74,24 @@ public class WalletProtobufSerializer {
private boolean requireMandatoryExtensions = true;
public interface WalletFactory {
Wallet create(NetworkParameters params, KeyChainGroup keyChainGroup);
}
private final WalletFactory factory;
public WalletProtobufSerializer() {
this(new WalletFactory() {
@Override
public Wallet create(NetworkParameters params, KeyChainGroup keyChainGroup) {
return new Wallet(params, keyChainGroup);
}
});
}
public WalletProtobufSerializer(WalletFactory factory) {
txMap = new HashMap<ByteString, Transaction>();
this.factory = factory;
}
/**
@ -374,7 +390,7 @@ public class WalletProtobufSerializer {
} else {
chain = KeyChainGroup.fromProtobufUnencrypted(walletProto.getKeyList());
}
Wallet wallet = new Wallet(params, chain);
Wallet wallet = factory.create(params, chain);
List<Script> scripts = Lists.newArrayList();
for (Protos.Script protoScript : walletProto.getWatchedScriptList()) {