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

Add a BitcoinURI.convertToURI variant that takes a String instead of an Address. Remove test for null param -> IllegalArgumentException as that's not consistent with the rest of the library. Resolves issue 152.

This commit is contained in:
Mike Hearn 2012-05-14 20:57:14 -07:00
parent 3d5a7ea7ec
commit 1b1457449a
2 changed files with 7 additions and 14 deletions

View File

@ -291,6 +291,10 @@ public class BitcoinURI {
return builder.toString();
}
public static String convertToBitcoinURI(Address address, BigInteger amount, String label, String message) {
return convertToBitcoinURI(address.toString(), amount, label, message);
}
/**
* Simple Bitcoin URI builder using known good fields.
*
@ -300,17 +304,14 @@ public class BitcoinURI {
* @param message A message
* @return A String containing the Bitcoin URI
*/
public static String convertToBitcoinURI(Address address, BigInteger amount, String label, String message) {
if (address == null) {
throw new IllegalArgumentException("Missing address");
}
public static String convertToBitcoinURI(String address, BigInteger amount, String label, String message) {
Preconditions.checkNotNull(address);
if (amount != null && amount.compareTo(BigInteger.ZERO) < 0) {
throw new IllegalArgumentException("Amount must be positive");
}
StringBuilder builder = new StringBuilder();
builder.append(BITCOIN_SCHEME).append(COLON_SEPARATOR).append(address.toString());
builder.append(BITCOIN_SCHEME).append(COLON_SEPARATOR).append(address);
boolean questionMarkHasBeenOutput = false;

View File

@ -51,14 +51,6 @@ public class BitcoinURITest {
// example with spaces, ampersand and plus
assertEquals("bitcoin:" + PRODNET_GOOD_ADDRESS + "?amount=12.34&label=Hello%20World&message=Mess%20%26%20age%20%2B%20hope", BitcoinURI.convertToBitcoinURI(goodAddress, Utils.toNanoCoins("12.34"), "Hello World", "Mess & age + hope"));
// address null
try {
BitcoinURI.convertToBitcoinURI(null, Utils.toNanoCoins("0.1"), "hope", "glory");
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("address"));
}
// amount negative
try {