WalletAppKit: Allow overriding of the block store in use.

This commit is contained in:
Mike Hearn 2015-04-08 18:30:34 +02:00
parent d46ba33343
commit ec6f8a3c9d

View file

@ -65,7 +65,7 @@ public class WalletAppKit extends AbstractIdleService {
protected final String filePrefix; protected final String filePrefix;
protected final NetworkParameters params; protected final NetworkParameters params;
protected volatile BlockChain vChain; protected volatile BlockChain vChain;
protected volatile SPVBlockStore vStore; protected volatile BlockStore vStore;
protected volatile Wallet vWallet; protected volatile Wallet vWallet;
protected volatile PeerGroup vPeerGroup; protected volatile PeerGroup vPeerGroup;
@ -222,6 +222,13 @@ public class WalletAppKit extends AbstractIdleService {
return ImmutableList.of(); return ImmutableList.of();
} }
/**
* Override this to use a {@link BlockStore} that isn't the default of {@link SPVBlockStore}.
*/
protected BlockStore provideBlockStore(File file) throws BlockStoreException {
return new SPVBlockStore(params, file);
}
/** /**
* This method is invoked on a background thread after all objects are initialised, but before the peer group * This method is invoked on a background thread after all objects are initialised, but before the peer group
* or block chain download is started. You can tweak the objects configuration here. * or block chain download is started. You can tweak the objects configuration here.
@ -269,7 +276,7 @@ public class WalletAppKit extends AbstractIdleService {
vWallet = createOrLoadWallet(shouldReplayWallet); vWallet = createOrLoadWallet(shouldReplayWallet);
// Initiate Bitcoin network objects (block store, blockchain and peer group) // Initiate Bitcoin network objects (block store, blockchain and peer group)
vStore = new SPVBlockStore(params, chainFile); vStore = provideBlockStore(chainFile);
if (!chainFileExists || restoreFromSeed != null) { if (!chainFileExists || restoreFromSeed != null) {
if (checkpoints != null) { if (checkpoints != null) {
// Initialize the chain file with a checkpoint to speed up first-run sync. // Initialize the chain file with a checkpoint to speed up first-run sync.
@ -483,7 +490,7 @@ public class WalletAppKit extends AbstractIdleService {
return vChain; return vChain;
} }
public SPVBlockStore store() { public BlockStore store() {
checkState(state() == State.STARTING || state() == State.RUNNING, "Cannot call until startup is complete"); checkState(state() == State.STARTING || state() == State.RUNNING, "Cannot call until startup is complete");
return vStore; return vStore;
} }