Package org.bitcoinj.uri
Class BitcoinURI
java.lang.Object
org.bitcoinj.uri.BitcoinURI
Provides a standard implementation of a Bitcoin URI with support for the following:
- URLEncoded URIs (as passed in by IE on the command line)
- BIP21 names (including the "req-" prefix handling requirements)
Accepted formats
The following input forms are accepted:
bitcoin:<address>
bitcoin:<address>?<name1>=<value1>&<name2>=<value2>
with multiple additional name/value pairs
The name/value pairs are processed as follows.
- URL encoding is stripped and treated as UTF-8
- names prefixed with
req-
are treated as required and if unknown or conflicting cause a parse exception - Unknown names not prefixed with
req-
are added to a Map, accessible by parameter name - Known names not prefixed with
req-
are processed unless they are malformed
The following names are known and have the following formats:
amount
decimal value to 8 dp (e.g. 0.12345678) Note that the exponent notation is not supported any morelabel
any URL encoded alphanumericmessage
any URL encoded alphanumeric
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionBitcoinURI
(String uri) Constructs a new BitcoinURI from the given string.BitcoinURI
(NetworkParameters params, String input) Constructs a new object by trying to parse the input as a valid Bitcoin URI. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
convertToBitcoinURI
(Address address, Coin amount, String label, String message) Simple Bitcoin URI builder using known good fields.static String
convertToBitcoinURI
(NetworkParameters params, String address, Coin amount, String label, String message) Simple Bitcoin URI builder using known good fields.The Bitcoin address from the URI, if one was present.getLabel()
getParameterByName
(String name) final String
Returns the URLs where a payment request (as specified in BIP 70) may be fetched.toString()
-
Field Details
-
FIELD_MESSAGE
- See Also:
-
FIELD_LABEL
- See Also:
-
FIELD_AMOUNT
- See Also:
-
FIELD_ADDRESS
- See Also:
-
FIELD_PAYMENT_REQUEST_URL
- See Also:
-
BITCOIN_SCHEME
Deprecated.URI for Bitcoin network. UseAbstractBitcoinNetParams.BITCOIN_SCHEME
if you specifically need Bitcoin, or useNetworkParameters.getUriScheme()
to get the scheme from network parameters.- See Also:
-
-
Constructor Details
-
BitcoinURI
Constructs a new BitcoinURI from the given string. Can be for any network.- Parameters:
uri
- The raw URI data to be parsed (see class comments for accepted formats)- Throws:
BitcoinURIParseException
- if the URI is not syntactically or semantically valid.
-
BitcoinURI
Constructs a new object by trying to parse the input as a valid Bitcoin URI.- Parameters:
params
- The network parameters that determine which network the URI is from, or null if you don't have any expectation about what network the URI is for and wish to check yourself.input
- The raw URI data to be parsed (see class comments for accepted formats)- Throws:
BitcoinURIParseException
- If the input fails Bitcoin URI syntax and semantic checks.
-
-
Method Details
-
getAddress
The Bitcoin address from the URI, if one was present. It's possible to have Bitcoin URI's with no address if a r= payment protocol parameter is specified, though this form is not recommended as older wallets can't understand it. -
getAmount
- Returns:
- The amount name encoded using a pure integer value based at 10,000,000 units is 1 BTC. May be null if no amount is specified
-
getLabel
- Returns:
- The label from the URI.
-
getMessage
- Returns:
- The message from the URI.
-
getPaymentRequestUrl
- Returns:
- The URL where a payment request (as specified in BIP 70) may be fetched.
-
getPaymentRequestUrls
Returns the URLs where a payment request (as specified in BIP 70) may be fetched. The first URL is the main URL, all subsequent URLs are fallbacks. -
getParameterByName
- Parameters:
name
- The name of the parameter- Returns:
- The parameter value, or null if not present
-
toString
-
convertToBitcoinURI
public static String convertToBitcoinURI(Address address, Coin amount, String label, String message) Simple Bitcoin URI builder using known good fields.- Parameters:
address
- The Bitcoin addressamount
- The amountlabel
- A labelmessage
- A message- Returns:
- A String containing the Bitcoin URI
-
convertToBitcoinURI
public static String convertToBitcoinURI(NetworkParameters params, String address, @Nullable Coin amount, @Nullable String label, @Nullable String message) Simple Bitcoin URI builder using known good fields.- Parameters:
params
- The network parameters that determine which network the URI is for.address
- The Bitcoin addressamount
- The amountlabel
- A labelmessage
- A message- Returns:
- A String containing the Bitcoin URI
-