Skip to content

Commit

Permalink
AddressFormatException: Make unchecked. Base58 strings are rarely typ…
Browse files Browse the repository at this point in the history
…ed manually these days.
  • Loading branch information
schildbach committed Aug 8, 2015
1 parent ecbd021 commit 200f236
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
/*
* Copyright 2011 Google Inc.
* Copyright 2015 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +18,7 @@
package org.bitcoinj.core;

@SuppressWarnings("serial")
public class AddressFormatException extends Exception {
public class AddressFormatException extends IllegalArgumentException {
public AddressFormatException() {
super();
}
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/org/bitcoinj/crypto/DeterministicKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,10 @@ public static DeterministicKey deserializeB58(String base58, NetworkParameters p
/**
* Deserialize a base-58-encoded HD Key.
* @param parent The parent node in the given key's deterministic hierarchy.
* @throws IllegalArgumentException if the base58 encoded key could not be parsed.
*/
public static DeterministicKey deserializeB58(@Nullable DeterministicKey parent, String base58, NetworkParameters params) {
try {
return deserialize(params, Base58.decodeChecked(base58), parent);
} catch (AddressFormatException e) {
throw new IllegalArgumentException(e);
}
return deserialize(params, Base58.decodeChecked(base58), parent);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/org/bitcoinj/core/Base58Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -84,7 +84,7 @@ public void testDecode() throws Exception {
}

@Test
public void testDecodeToBigInteger() throws AddressFormatException {
public void testDecodeToBigInteger() {
byte[] input = Base58.decode("129");
assertEquals(new BigInteger(1, input), Base58.decodeToBigInteger("129"));
}
Expand Down
7 changes: 3 additions & 4 deletions core/src/test/java/org/bitcoinj/crypto/BIP32Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2013 Matija Mazi.
* Copyright 2014 Andreas Schildbach
*
Expand All @@ -17,7 +17,6 @@

package org.bitcoinj.crypto;

import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Base58;
import com.google.common.base.Functions;
import com.google.common.base.Joiner;
Expand Down Expand Up @@ -127,7 +126,7 @@ public void testVector2() throws Exception {
testVector(1);
}

private void testVector(int testCase) throws AddressFormatException {
private void testVector(int testCase) {
log.info("======= Test vector {}", testCase);
HDWTestVector tv = tvs[testCase];
NetworkParameters params = MainNetParams.get();
Expand All @@ -146,7 +145,7 @@ private void testVector(int testCase) throws AddressFormatException {
}
}

private String testEncode(String what) throws AddressFormatException {
private String testEncode(String what) {
return HEX.encode(Base58.decodeChecked(what));
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/org/bitcoinj/script/ScriptTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2011 Google Inc.
* Copyright 2014 Andreas Schildbach
*
Expand Down Expand Up @@ -118,7 +118,7 @@ public void testIp() throws Exception {
}

@Test
public void testCreateMultiSigInputScript() throws AddressFormatException {
public void testCreateMultiSigInputScript() {
// Setup transaction and signatures
ECKey key1 = DumpedPrivateKey.fromBase58(params, "cVLwRLTvz3BxDAWkvS3yzT9pUcTCup7kQnfT2smRjvmmm1wAP6QT").getKey();
ECKey key2 = DumpedPrivateKey.fromBase58(params, "cTine92s8GLpVqvebi8rYce3FrUYq78ZGQffBYCS1HmDPJdSTxUo").getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ public void onFailure(Throwable t) {
overlayUI.done();
} catch (ECKey.KeyIsEncryptedException e) {
askForPasswordAndRetry();
} catch (AddressFormatException e) {
// Cannot happen because we already validated it when the text field changed.
throw new RuntimeException(e);
}
}

Expand Down

0 comments on commit 200f236

Please sign in to comment.