3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-15 11:45:51 +00:00

AddressFormatException: Make unchecked. Base58 strings are rarely typed manually these days.

This commit is contained in:
Andreas Schildbach 2015-08-08 16:33:29 +02:00
parent ecbd021167
commit 200f2368c6
6 changed files with 12 additions and 18 deletions

View File

@ -1,5 +1,6 @@
/** /*
* Copyright 2011 Google Inc. * Copyright 2011 Google Inc.
* Copyright 2015 Andreas Schildbach
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,7 +18,7 @@
package org.bitcoinj.core; package org.bitcoinj.core;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class AddressFormatException extends Exception { public class AddressFormatException extends IllegalArgumentException {
public AddressFormatException() { public AddressFormatException() {
super(); super();
} }

View File

@ -498,13 +498,10 @@ public class DeterministicKey extends ECKey {
/** /**
* Deserialize a base-58-encoded HD Key. * Deserialize a base-58-encoded HD Key.
* @param parent The parent node in the given key's deterministic hierarchy. * @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) { public static DeterministicKey deserializeB58(@Nullable DeterministicKey parent, String base58, NetworkParameters params) {
try { return deserialize(params, Base58.decodeChecked(base58), parent);
return deserialize(params, Base58.decodeChecked(base58), parent);
} catch (AddressFormatException e) {
throw new IllegalArgumentException(e);
}
} }
/** /**

View File

@ -1,4 +1,4 @@
/** /*
* Copyright 2011 Google Inc. * Copyright 2011 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -84,7 +84,7 @@ public class Base58Test extends TestCase {
} }
@Test @Test
public void testDecodeToBigInteger() throws AddressFormatException { public void testDecodeToBigInteger() {
byte[] input = Base58.decode("129"); byte[] input = Base58.decode("129");
assertEquals(new BigInteger(1, input), Base58.decodeToBigInteger("129")); assertEquals(new BigInteger(1, input), Base58.decodeToBigInteger("129"));
} }

View File

@ -1,4 +1,4 @@
/** /*
* Copyright 2013 Matija Mazi. * Copyright 2013 Matija Mazi.
* Copyright 2014 Andreas Schildbach * Copyright 2014 Andreas Schildbach
* *
@ -17,7 +17,6 @@
package org.bitcoinj.crypto; package org.bitcoinj.crypto;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Base58; import org.bitcoinj.core.Base58;
import com.google.common.base.Functions; import com.google.common.base.Functions;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@ -127,7 +126,7 @@ public class BIP32Test {
testVector(1); testVector(1);
} }
private void testVector(int testCase) throws AddressFormatException { private void testVector(int testCase) {
log.info("======= Test vector {}", testCase); log.info("======= Test vector {}", testCase);
HDWTestVector tv = tvs[testCase]; HDWTestVector tv = tvs[testCase];
NetworkParameters params = MainNetParams.get(); NetworkParameters params = MainNetParams.get();
@ -146,7 +145,7 @@ public class BIP32Test {
} }
} }
private String testEncode(String what) throws AddressFormatException { private String testEncode(String what) {
return HEX.encode(Base58.decodeChecked(what)); return HEX.encode(Base58.decodeChecked(what));
} }

View File

@ -1,4 +1,4 @@
/** /*
* Copyright 2011 Google Inc. * Copyright 2011 Google Inc.
* Copyright 2014 Andreas Schildbach * Copyright 2014 Andreas Schildbach
* *
@ -118,7 +118,7 @@ public class ScriptTest {
} }
@Test @Test
public void testCreateMultiSigInputScript() throws AddressFormatException { public void testCreateMultiSigInputScript() {
// Setup transaction and signatures // Setup transaction and signatures
ECKey key1 = DumpedPrivateKey.fromBase58(params, "cVLwRLTvz3BxDAWkvS3yzT9pUcTCup7kQnfT2smRjvmmm1wAP6QT").getKey(); ECKey key1 = DumpedPrivateKey.fromBase58(params, "cVLwRLTvz3BxDAWkvS3yzT9pUcTCup7kQnfT2smRjvmmm1wAP6QT").getKey();
ECKey key2 = DumpedPrivateKey.fromBase58(params, "cTine92s8GLpVqvebi8rYce3FrUYq78ZGQffBYCS1HmDPJdSTxUo").getKey(); ECKey key2 = DumpedPrivateKey.fromBase58(params, "cTine92s8GLpVqvebi8rYce3FrUYq78ZGQffBYCS1HmDPJdSTxUo").getKey();

View File

@ -83,9 +83,6 @@ public class SendMoneyController {
overlayUI.done(); overlayUI.done();
} catch (ECKey.KeyIsEncryptedException e) { } catch (ECKey.KeyIsEncryptedException e) {
askForPasswordAndRetry(); askForPasswordAndRetry();
} catch (AddressFormatException e) {
// Cannot happen because we already validated it when the text field changed.
throw new RuntimeException(e);
} }
} }