diff --git a/core/src/main/java/com/google/bitcoin/store/UnreadableWalletException.java b/core/src/main/java/com/google/bitcoin/store/UnreadableWalletException.java index 0c9d31bcf..6c135bd8b 100644 --- a/core/src/main/java/com/google/bitcoin/store/UnreadableWalletException.java +++ b/core/src/main/java/com/google/bitcoin/store/UnreadableWalletException.java @@ -22,4 +22,10 @@ public class UnreadableWalletException extends Exception { public static class FutureVersion extends UnreadableWalletException { public FutureVersion() { super("Unknown wallet version from the future."); } } + + public static class WrongNetwork extends UnreadableWalletException { + public WrongNetwork() { + super("Mismatched network ID"); + } + } } diff --git a/core/src/main/java/com/google/bitcoin/store/WalletProtobufSerializer.java b/core/src/main/java/com/google/bitcoin/store/WalletProtobufSerializer.java index 4599aeddf..1fede095f 100644 --- a/core/src/main/java/com/google/bitcoin/store/WalletProtobufSerializer.java +++ b/core/src/main/java/com/google/bitcoin/store/WalletProtobufSerializer.java @@ -383,6 +383,8 @@ public class WalletProtobufSerializer { Protos.Wallet walletProto) throws UnreadableWalletException { if (walletProto.getVersion() > 1) throw new UnreadableWalletException.FutureVersion(); + if (!walletProto.getNetworkIdentifier().equals(params.getId())) + throw new UnreadableWalletException.WrongNetwork(); // Read the scrypt parameters that specify how encryption and decryption is performed. KeyChainGroup chain;