Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out provideBlockStore() method to allow overriding #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions core/src/main/java/io/xpydev/paycoinj/kits/WalletAppKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.xpydev.paycoinj.protocols.channels.StoredPaymentChannelClientStates;
import io.xpydev.paycoinj.protocols.channels.StoredPaymentChannelServerStates;
import io.xpydev.paycoinj.store.BlockStoreException;
import io.xpydev.paycoinj.store.BlockStore;
import io.xpydev.paycoinj.store.SPVBlockStore;
import io.xpydev.paycoinj.store.ValidHashStore;
import io.xpydev.paycoinj.store.WalletProtobufSerializer;
Expand All @@ -32,6 +33,7 @@
import com.google.common.util.concurrent.Service;
import com.subgraph.orchid.TorClient;
import io.xpydev.paycoinj.wallet.Protos;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -75,7 +77,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 ValidHashStore validHashStore;
protected volatile Wallet vWallet;
protected volatile PeerGroup vPeerGroup;
Expand Down Expand Up @@ -203,6 +205,13 @@ protected List<WalletExtension> provideWalletExtensions() throws Exception {
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.
Expand Down Expand Up @@ -251,7 +260,8 @@ protected void startUp() throws Exception {

validHashStore = new ValidHashStore(validHashFile);

vStore = new SPVBlockStore(params, chainFile);
// Initiate Paycoin network objects (block store, blockchain and peer group)
vStore = provideBlockStore(chainFile);
if ((!chainFileExists || restoreFromSeed != null) && checkpoints != null) {
// Initialize the chain file with a checkpoint to speed up first-run sync.
long time;
Expand Down Expand Up @@ -463,7 +473,7 @@ public BlockChain chain() {
return vChain;
}

public SPVBlockStore store() {
public BlockStore store() {
checkState(state() == State.STARTING || state() == State.RUNNING, "Cannot call until startup is complete");
return vStore;
}
Expand Down