mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-20 10:12:19 +01:00
WalletAppKit: allow control of wallet construction.
This commit is contained in:
parent
4504633fd5
commit
748ff6fc8e
@ -22,6 +22,7 @@ import com.google.bitcoin.net.discovery.DnsDiscovery;
|
|||||||
import com.google.bitcoin.store.BlockStoreException;
|
import com.google.bitcoin.store.BlockStoreException;
|
||||||
import com.google.bitcoin.store.SPVBlockStore;
|
import com.google.bitcoin.store.SPVBlockStore;
|
||||||
import com.google.bitcoin.store.WalletProtobufSerializer;
|
import com.google.bitcoin.store.WalletProtobufSerializer;
|
||||||
|
import com.google.bitcoin.wallet.KeyChainGroup;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.util.concurrent.AbstractIdleService;
|
import com.google.common.util.concurrent.AbstractIdleService;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
@ -83,6 +84,7 @@ public class WalletAppKit extends AbstractIdleService {
|
|||||||
protected boolean blockingStartup = true;
|
protected boolean blockingStartup = true;
|
||||||
protected boolean useTor = false; // Perhaps in future we can change this to true.
|
protected boolean useTor = false; // Perhaps in future we can change this to true.
|
||||||
protected String userAgent, version;
|
protected String userAgent, version;
|
||||||
|
protected WalletProtobufSerializer.WalletFactory walletFactory;
|
||||||
|
|
||||||
public WalletAppKit(NetworkParameters params, File directory, String filePrefix) {
|
public WalletAppKit(NetworkParameters params, File directory, String filePrefix) {
|
||||||
this.params = checkNotNull(params);
|
this.params = checkNotNull(params);
|
||||||
@ -226,14 +228,19 @@ public class WalletAppKit extends AbstractIdleService {
|
|||||||
vWallet = new Wallet(params);
|
vWallet = new Wallet(params);
|
||||||
WalletExtension[] extArray = extensions.toArray(new WalletExtension[extensions.size()]);
|
WalletExtension[] extArray = extensions.toArray(new WalletExtension[extensions.size()]);
|
||||||
Protos.Wallet proto = WalletProtobufSerializer.parseToProto(walletStream);
|
Protos.Wallet proto = WalletProtobufSerializer.parseToProto(walletStream);
|
||||||
vWallet = new WalletProtobufSerializer().readWallet(params, extArray, proto);
|
final WalletProtobufSerializer serializer;
|
||||||
|
if (walletFactory != null)
|
||||||
|
serializer = new WalletProtobufSerializer(walletFactory);
|
||||||
|
else
|
||||||
|
serializer = new WalletProtobufSerializer();
|
||||||
|
vWallet = serializer.readWallet(params, extArray, proto);
|
||||||
if (shouldReplayWallet)
|
if (shouldReplayWallet)
|
||||||
vWallet.clearTransactions(0);
|
vWallet.clearTransactions(0);
|
||||||
} finally {
|
} finally {
|
||||||
walletStream.close();
|
walletStream.close();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vWallet = new Wallet(params);
|
vWallet = walletFactory != null ? walletFactory.create(params, new KeyChainGroup()) : new Wallet(params);
|
||||||
vWallet.freshReceiveKey();
|
vWallet.freshReceiveKey();
|
||||||
for (WalletExtension e : provideWalletExtensions()) {
|
for (WalletExtension e : provideWalletExtensions()) {
|
||||||
vWallet.addExtension(e);
|
vWallet.addExtension(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user