com.google.bitcoin.uri
Class BitcoinURI

java.lang.Object
  extended by com.google.bitcoin.uri.BitcoinURI

public class BitcoinURI
extends Object

Provides a standard implementation of a Bitcoin URI with support for the following:

Accepted formats

The following input forms are accepted:

The name/value pairs are processed as follows.

  1. URL encoding is stripped and treated as UTF-8
  2. names prefixed with req- are treated as required and if unknown or conflicting cause a parse exception
  3. Unknown names not prefixed with req- are added to a Map, accessible by parameter name
  4. Known names not prefixed with req- are processed unless they are malformed

The following names are known and have the following formats:

Author:
Andreas Schildbach (initial code), Jim Burton (enhancements for MultiBit), Gary Rowe (BIP21 support)
See Also:
BIP 0021

Field Summary
static String BITCOIN_SCHEME
           
static String FIELD_ADDRESS
           
static String FIELD_AMOUNT
           
static String FIELD_LABEL
           
static String FIELD_MESSAGE
           
static String FIELD_PAYMENT_REQUEST_URL
           
 
Constructor Summary
BitcoinURI(NetworkParameters params, String input)
          Constructs a new object by trying to parse the input as a valid Bitcoin URI.
BitcoinURI(String uri)
          Constructs a new BitcoinURI from the given string.
 
Method Summary
static String convertToBitcoinURI(Address address, BigInteger amount, String label, String message)
           
static String convertToBitcoinURI(String address, BigInteger amount, String label, String message)
          Simple Bitcoin URI builder using known good fields.
 Address getAddress()
          The Bitcoin Address from the URI, if one was present.
 BigInteger getAmount()
           
 String getLabel()
           
 String getMessage()
           
 Object getParameterByName(String name)
           
 String getPaymentRequestUrl()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FIELD_MESSAGE

public static final String FIELD_MESSAGE
See Also:
Constant Field Values

FIELD_LABEL

public static final String FIELD_LABEL
See Also:
Constant Field Values

FIELD_AMOUNT

public static final String FIELD_AMOUNT
See Also:
Constant Field Values

FIELD_ADDRESS

public static final String FIELD_ADDRESS
See Also:
Constant Field Values

FIELD_PAYMENT_REQUEST_URL

public static final String FIELD_PAYMENT_REQUEST_URL
See Also:
Constant Field Values

BITCOIN_SCHEME

public static final String BITCOIN_SCHEME
See Also:
Constant Field Values
Constructor Detail

BitcoinURI

public BitcoinURI(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.

BitcoinURI

public BitcoinURI(@Nullable
                  NetworkParameters params,
                  String input)
           throws BitcoinURIParseException
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

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 BigInteger 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 String getLabel()
Returns:
The label from the URI.

getMessage

public String getMessage()
Returns:
The message from the URI.

getPaymentRequestUrl

public String getPaymentRequestUrl()
Returns:
The URL where a payment request (as specified in BIP 70) may be fetched.

getParameterByName

public Object getParameterByName(String name)
Parameters:
name - The name of the parameter
Returns:
The parameter value, or null if not present

toString

public String toString()
Overrides:
toString in class Object

convertToBitcoinURI

public static String convertToBitcoinURI(Address address,
                                         BigInteger amount,
                                         String label,
                                         String message)

convertToBitcoinURI

public static String convertToBitcoinURI(String address,
                                         @Nullable
                                         BigInteger amount,
                                         @Nullable
                                         String label,
                                         @Nullable
                                         String message)
Simple Bitcoin URI builder using known good fields.

Parameters:
address - The Bitcoin address
amount - The amount in nanocoins (decimal)
label - A label
message - A message
Returns:
A String containing the Bitcoin URI


Copyright © 2014. All rights reserved.