Package org.bitcoinj.uri
Class BitcoinURI
- java.lang.Object
-
- org.bitcoinj.uri.BitcoinURI
-
public class BitcoinURI extends java.lang.Object
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:
- BIP 0021
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
BITCOIN_SCHEME
Deprecated.static java.lang.String
FIELD_ADDRESS
static java.lang.String
FIELD_AMOUNT
static java.lang.String
FIELD_LABEL
static java.lang.String
FIELD_MESSAGE
static java.lang.String
FIELD_PAYMENT_REQUEST_URL
-
Constructor Summary
Constructors Constructor Description BitcoinURI(NetworkParameters params, java.lang.String input)
Deprecated.Useof(String, Network)
orof(String)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.String
convertToBitcoinURI(Address address, Coin amount, java.lang.String label, java.lang.String message)
Simple Bitcoin URI builder using known good fields.static java.lang.String
convertToBitcoinURI(Network network, java.lang.String address, Coin amount, java.lang.String label, java.lang.String message)
Simple Bitcoin URI builder using known good fields.static java.lang.String
convertToBitcoinURI(NetworkParameters params, java.lang.String address, Coin amount, java.lang.String label, java.lang.String message)
Deprecated.Address
getAddress()
The Bitcoin address from the URI, if one was present.Coin
getAmount()
java.lang.String
getLabel()
java.lang.String
getMessage()
java.lang.Object
getParameterByName(java.lang.String name)
java.lang.String
getPaymentRequestUrl()
java.util.List<java.lang.String>
getPaymentRequestUrls()
Returns the URLs where a payment request (as specified in BIP 70) may be fetched.static BitcoinURI
of(java.lang.String uri)
Constructs a new BitcoinURI from the given string.static BitcoinURI
of(java.lang.String uri, Network network)
Constructs a new object by trying to parse the input as a valid Bitcoin URI.java.lang.String
toString()
-
-
-
Field Detail
-
FIELD_MESSAGE
public static final java.lang.String FIELD_MESSAGE
- See Also:
- Constant Field Values
-
FIELD_LABEL
public static final java.lang.String FIELD_LABEL
- See Also:
- Constant Field Values
-
FIELD_AMOUNT
public static final java.lang.String FIELD_AMOUNT
- See Also:
- Constant Field Values
-
FIELD_ADDRESS
public static final java.lang.String FIELD_ADDRESS
- See Also:
- Constant Field Values
-
FIELD_PAYMENT_REQUEST_URL
public static final java.lang.String FIELD_PAYMENT_REQUEST_URL
- See Also:
- Constant Field Values
-
BITCOIN_SCHEME
@Deprecated public static final java.lang.String BITCOIN_SCHEME
Deprecated.URI Scheme for Bitcoin network.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BitcoinURI
@Deprecated public BitcoinURI(@Nullable NetworkParameters params, java.lang.String input) throws BitcoinURIParseException
Deprecated.Useof(String, Network)
orof(String)
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 Detail
-
of
public static BitcoinURI of(java.lang.String uri) throws BitcoinURIParseException
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.
-
of
public static BitcoinURI of(java.lang.String uri, @Nonnull Network network) throws BitcoinURIParseException
Constructs a new object by trying to parse the input as a valid Bitcoin URI.- Parameters:
uri
- The raw URI data to be parsed (see class comments for accepted formats)network
- The network the URI is from- Throws:
BitcoinURIParseException
- If the input fails Bitcoin URI syntax and semantic checks.
-
getAddress
@Nullable public Address 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
public Coin 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
public java.lang.String getLabel()
- Returns:
- The label from the URI.
-
getMessage
public java.lang.String getMessage()
- Returns:
- The message from the URI.
-
getPaymentRequestUrl
public final java.lang.String getPaymentRequestUrl()
- Returns:
- The URL where a payment request (as specified in BIP 70) may be fetched.
-
getPaymentRequestUrls
public java.util.List<java.lang.String> 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
public java.lang.Object getParameterByName(java.lang.String name)
- Parameters:
name
- The name of the parameter- Returns:
- The parameter value, or null if not present
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
convertToBitcoinURI
public static java.lang.String convertToBitcoinURI(Address address, Coin amount, java.lang.String label, java.lang.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
@Deprecated public static java.lang.String convertToBitcoinURI(NetworkParameters params, java.lang.String address, @Nullable Coin amount, @Nullable java.lang.String label, @Nullable java.lang.String message)
Deprecated.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
-
convertToBitcoinURI
public static java.lang.String convertToBitcoinURI(Network network, java.lang.String address, @Nullable Coin amount, @Nullable java.lang.String label, @Nullable java.lang.String message)
Simple Bitcoin URI builder using known good fields.- Parameters:
network
- The network the URI is for.address
- The Bitcoin addressamount
- The amountlabel
- A labelmessage
- A message- Returns:
- A String containing the Bitcoin URI
-
-