From ec6f8a3c9dd188f0e109945a3d183f1ae05113dc Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 8 Apr 2015 18:30:34 +0200 Subject: [PATCH] WalletAppKit: Allow overriding of the block store in use. --- .../main/java/org/bitcoinj/kits/WalletAppKit.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/kits/WalletAppKit.java b/core/src/main/java/org/bitcoinj/kits/WalletAppKit.java index 167275ca0..a7d6169f8 100644 --- a/core/src/main/java/org/bitcoinj/kits/WalletAppKit.java +++ b/core/src/main/java/org/bitcoinj/kits/WalletAppKit.java @@ -65,7 +65,7 @@ public class WalletAppKit extends AbstractIdleService { protected final String filePrefix; protected final NetworkParameters params; protected volatile BlockChain vChain; - protected volatile SPVBlockStore vStore; + protected volatile BlockStore vStore; protected volatile Wallet vWallet; protected volatile PeerGroup vPeerGroup; @@ -222,6 +222,13 @@ public class WalletAppKit extends AbstractIdleService { 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 * 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); // Initiate Bitcoin network objects (block store, blockchain and peer group) - vStore = new SPVBlockStore(params, chainFile); + vStore = provideBlockStore(chainFile); if (!chainFileExists || restoreFromSeed != null) { if (checkpoints != null) { // Initialize the chain file with a checkpoint to speed up first-run sync. @@ -483,7 +490,7 @@ public class WalletAppKit extends AbstractIdleService { return vChain; } - public SPVBlockStore store() { + public BlockStore store() { checkState(state() == State.STARTING || state() == State.RUNNING, "Cannot call until startup is complete"); return vStore; }