3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-30 23:02:15 +00:00

Tweak ToyWallet to allow for easy switching to FullPrunedBlockChain

This commit is contained in:
Matt Corallo 2012-07-10 04:11:58 +02:00 committed by Mike Hearn
parent 0cf2325640
commit 6a96b0c392

View File

@ -20,6 +20,7 @@ import com.google.bitcoin.core.*;
import com.google.bitcoin.discovery.DnsDiscovery; import com.google.bitcoin.discovery.DnsDiscovery;
import com.google.bitcoin.discovery.IrcDiscovery; import com.google.bitcoin.discovery.IrcDiscovery;
import com.google.bitcoin.store.BoundedOverheadBlockStore; import com.google.bitcoin.store.BoundedOverheadBlockStore;
import com.google.bitcoin.store.H2FullPrunedBlockStore;
import com.google.bitcoin.utils.BriefLogFormatter; import com.google.bitcoin.utils.BriefLogFormatter;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
@ -46,7 +47,7 @@ public class ToyWallet {
private NetworkParameters params; private NetworkParameters params;
private Wallet wallet; private Wallet wallet;
private PeerGroup peerGroup; private PeerGroup peerGroup;
private BlockChain chain; private AbstractBlockChain chain;
private JLabel networkStats; private JLabel networkStats;
private File walletFile; private File walletFile;
private JScrollPane txScrollPane; private JScrollPane txScrollPane;
@ -55,7 +56,7 @@ public class ToyWallet {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
BriefLogFormatter.init(); BriefLogFormatter.init();
new ToyWallet(true, args); new ToyWallet(true, true, args);
} }
// Converts the contents of the wallet to a table for the GUI. // Converts the contents of the wallet to a table for the GUI.
@ -110,7 +111,7 @@ public class ToyWallet {
} }
} }
public ToyWallet(boolean testnet, String[] args) throws Exception { public ToyWallet(boolean testnet, boolean fullChain, String[] args) throws Exception {
// Set up a Bitcoin connection + empty wallet. TODO: Simplify the setup for this use case. // Set up a Bitcoin connection + empty wallet. TODO: Simplify the setup for this use case.
if (testnet) { if (testnet) {
params = NetworkParameters.testNet3(); params = NetworkParameters.testNet3();
@ -162,7 +163,13 @@ public class ToyWallet {
// the blocks there are no problems (wallets don't support replays without being emptied). // the blocks there are no problems (wallets don't support replays without being emptied).
wallet.clearTransactions(0); wallet.clearTransactions(0);
} }
chain = new BlockChain(params, wallet, new BoundedOverheadBlockStore(params, blockChainFile));
if (fullChain) {
H2FullPrunedBlockStore store = new H2FullPrunedBlockStore(params, blockChainFile.getName(), 100);
chain = new FullPrunedBlockChain(params, wallet, store);
} else {
chain = new BlockChain(params, wallet, new BoundedOverheadBlockStore(params, blockChainFile));
}
peerGroup = new PeerGroup(params, chain); peerGroup = new PeerGroup(params, chain);
peerGroup.setUserAgent("ToyWallet", "1.0"); peerGroup.setUserAgent("ToyWallet", "1.0");