public class Address extends VersionedChecksummedBytes
A Bitcoin address looks like 1MsScoe2fTJoq4ZPdQgqyhgWeoNamYPevy and is derived from an elliptic curve public key
plus a set of network parameters. Not to be confused with a PeerAddress
or AddressMessage
which are about network (TCP) addresses.
A standard address is built by taking the RIPE-MD160 hash of the public key bytes, with a version prefix and a
checksum suffix, then encoding it textually as base58. The version prefix is used to both denote the network for
which the address is valid (see NetworkParameters
, and also to indicate how the bytes inside the address
should be interpreted. Whilst almost all addresses today are hashes of public keys, another (currently unsupported
type) can contain a hash of a script instead.
Modifier and Type | Field and Description |
---|---|
static int |
LENGTH
An address is a RIPEMD160 hash of a public key, therefore is always 160 bits or 20 bytes.
|
bytes, version
Constructor and Description |
---|
Address(NetworkParameters params,
byte[] hash160)
Construct an address from parameters and the hash160 form.
|
Address(NetworkParameters params,
int version,
byte[] hash160)
Construct an address from parameters, the address version, and the hash160 form.
|
Address(NetworkParameters params,
String address)
Construct an address from parameters and the standard "human readable" form.
|
Modifier and Type | Method and Description |
---|---|
static Address |
fromP2SHHash(NetworkParameters params,
byte[] hash160)
Returns an Address that represents the given P2SH script hash.
|
static Address |
fromP2SHScript(NetworkParameters params,
Script scriptPubKey)
Returns an Address that represents the script hash extracted from the given scriptPubKey
|
byte[] |
getHash160()
The (big endian) 20 byte hash that is the core of a Bitcoin address.
|
NetworkParameters |
getParameters()
Examines the version byte of the address and attempts to find a matching NetworkParameters.
|
static NetworkParameters |
getParametersFromAddress(String address)
Given an address, examines the version byte and attempts to find a matching NetworkParameters.
|
boolean |
isP2SHAddress() |
equals, getVersion, hashCode, toString
public static final int LENGTH
public Address(NetworkParameters params, int version, byte[] hash160) throws WrongNetworkException
new Address(NetworkParameters.prodNet(), NetworkParameters.getAddressHeader(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
WrongNetworkException
public Address(NetworkParameters params, byte[] hash160)
new Address(NetworkParameters.prodNet(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
public Address(@Nullable NetworkParameters params, String address) throws AddressFormatException
new Address(NetworkParameters.prodNet(), "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL");
params
- The expected NetworkParameters or null if you don't want validation.address
- The textual form of the address, such as "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL"AddressFormatException
- if the given address doesn't parse or the checksum is invalidWrongNetworkException
- if the given address is valid but for a different chain (eg testnet vs prodnet)public static Address fromP2SHHash(NetworkParameters params, byte[] hash160)
public static Address fromP2SHScript(NetworkParameters params, Script scriptPubKey)
public byte[] getHash160()
public boolean isP2SHAddress()
public NetworkParameters getParameters()
public static NetworkParameters getParametersFromAddress(String address) throws AddressFormatException
AddressFormatException
- if the string wasn't of a known versionCopyright © 2014. All rights reserved.