Introduce UnreadableWalletException and make WalletProtobufSerializer throw it in all cases where there's a problem reading the wallet. Resolves issue 415. Resolves issue 416.

This commit is contained in:
Mike Hearn
2013-07-11 16:03:33 +02:00
parent be89be6f43
commit 99f32b16af
6 changed files with 84 additions and 71 deletions

View File

@@ -24,13 +24,13 @@ import com.google.bitcoin.params.RegTestParams;
import com.google.bitcoin.params.TestNet3Params;
import com.google.bitcoin.store.BlockStore;
import com.google.bitcoin.store.SPVBlockStore;
import com.google.bitcoin.store.UnreadableWalletException;
import com.google.bitcoin.utils.BriefLogFormatter;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.net.InetAddress;
@@ -97,7 +97,7 @@ public class PingService {
// Wipe the wallet if the chain file was deleted.
if (walletFile.exists() && chainFile.exists())
w = Wallet.loadFromFile(walletFile);
} catch (IOException e) {
} catch (UnreadableWalletException e) {
System.err.println("Couldn't load wallet: " + e);
// Fall through.
}

View File

@@ -22,6 +22,7 @@ import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.params.TestNet3Params;
import com.google.bitcoin.store.H2FullPrunedBlockStore;
import com.google.bitcoin.store.SPVBlockStore;
import com.google.bitcoin.store.UnreadableWalletException;
import com.google.bitcoin.utils.BriefLogFormatter;
import com.google.common.collect.Lists;
import org.spongycastle.util.encoders.Hex;
@@ -34,7 +35,6 @@ import java.awt.datatransfer.StringSelection;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Date;
import java.util.LinkedList;
@@ -125,7 +125,7 @@ public class ToyWallet {
walletFile = new File("toy.wallet");
try {
wallet = Wallet.loadFromFile(walletFile);
} catch (IOException e) {
} catch (UnreadableWalletException e) {
wallet = new Wallet(params);
// Allow user to specify the first key on the command line as: