diff --git a/src/main/java/com/sparrowwallet/drongo/uri/BitcoinURI.java b/src/main/java/com/sparrowwallet/drongo/uri/BitcoinURI.java new file mode 100644 index 0000000..6ee9bc0 --- /dev/null +++ b/src/main/java/com/sparrowwallet/drongo/uri/BitcoinURI.java @@ -0,0 +1,377 @@ +package com.sparrowwallet.drongo.uri; + +import com.sparrowwallet.drongo.address.Address; +import com.sparrowwallet.drongo.address.InvalidAddressException; + +import java.math.BigDecimal; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.*; + +import static com.sparrowwallet.drongo.protocol.Transaction.*; + +/** + *
Provides a standard implementation of a Bitcoin URI with support for the following:
+ * + *The following input forms are accepted:
+ * + *The name/value pairs are processed as follows.
+ *The following names are known and have the following formats:
+ *Exception to provide the following to {@link BitcoinURI}:
+ *This base exception acts as a general failure mode not attributable to a specific cause (other than + * that reported in the exception message). Since this is in English, it may not be worth reporting directly + * to the user other than as part of a "general failure to parse" response.
+ */ +public class BitcoinURIParseException extends Exception { + public BitcoinURIParseException(String s) { + super(s); + } + + public BitcoinURIParseException(String s, Throwable throwable) { + super(s, throwable); + } +} diff --git a/src/main/java/com/sparrowwallet/drongo/uri/OptionalFieldValidationException.java b/src/main/java/com/sparrowwallet/drongo/uri/OptionalFieldValidationException.java new file mode 100644 index 0000000..f5d2437 --- /dev/null +++ b/src/main/java/com/sparrowwallet/drongo/uri/OptionalFieldValidationException.java @@ -0,0 +1,23 @@ +package com.sparrowwallet.drongo.uri; + +/** + *Exception to provide the following to {@link BitcoinURI}:
+ *This exception occurs when an optional field is detected (under the Bitcoin URI scheme) and fails + * to pass the associated test (such as {@code amount} not being a valid number).
+ * + * @since 0.3.0 + * + */ +public class OptionalFieldValidationException extends BitcoinURIParseException { + + public OptionalFieldValidationException(String s) { + super(s); + } + + public OptionalFieldValidationException(String s, Throwable throwable) { + super(s, throwable); + } +} diff --git a/src/main/java/com/sparrowwallet/drongo/uri/RequiredFieldValidationException.java b/src/main/java/com/sparrowwallet/drongo/uri/RequiredFieldValidationException.java new file mode 100644 index 0000000..73131ac --- /dev/null +++ b/src/main/java/com/sparrowwallet/drongo/uri/RequiredFieldValidationException.java @@ -0,0 +1,24 @@ +package com.sparrowwallet.drongo.uri; + +/** + *Exception to provide the following to {@link BitcoinURI}:
+ *This exception occurs when a required field is detected (under the BIP21 rules) and fails + * to pass the associated test (such as {@code req-expires} being out of date), or the required field is unknown + * to this version of the client in which case it should fail for security reasons.
+ * + * @since 0.3.0 + * + */ +public class RequiredFieldValidationException extends BitcoinURIParseException { + + public RequiredFieldValidationException(String s) { + super(s); + } + + public RequiredFieldValidationException(String s, Throwable throwable) { + super(s, throwable); + } +} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index cbe6610..41f8136 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -11,4 +11,5 @@ open module com.sparrowwallet.drongo { exports com.sparrowwallet.drongo.crypto; exports com.sparrowwallet.drongo.wallet; exports com.sparrowwallet.drongo.policy; + exports com.sparrowwallet.drongo.uri; } \ No newline at end of file