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)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
Address |
clone()
This implementation narrows the return type to
Address . |
static Address |
fromBase58(NetworkParameters params,
String base58)
Construct an address from its Base58 representation.
|
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()
Returns true if this address is a Pay-To-Script-Hash (P2SH) address.
|
compareTo, equals, getVersion, hashCode, toBase58, toString
public static final int LENGTH
public Address(NetworkParameters params, int version, byte[] hash160) throws WrongNetworkException
new Address(MainNetParams.get(), NetworkParameters.getAddressHeader(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
WrongNetworkException
public Address(NetworkParameters params, byte[] hash160)
new Address(MainNetParams.get(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
@Deprecated public Address(@Nullable NetworkParameters params, String address) throws AddressFormatException
fromBase58(NetworkParameters, String)
AddressFormatException
public static Address fromP2SHHash(NetworkParameters params, byte[] hash160)
public static Address fromP2SHScript(NetworkParameters params, Script scriptPubKey)
public static Address fromBase58(@Nullable NetworkParameters params, String base58) throws AddressFormatException
params
- The expected NetworkParameters or null if you don't want validation.base58
- The textual form of the address, such as "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL".AddressFormatException
- if the given base58 doesn't parse or the checksum is invalidWrongNetworkException
- if the given address is valid but for a different chain (eg testnet vs mainnet)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 versionpublic Address clone() throws CloneNotSupportedException
Address
.clone
in class VersionedChecksummedBytes
CloneNotSupportedException
Copyright © 2016. All rights reserved.