Package org.bitcoinj.core
Class Address
java.lang.Object
org.bitcoinj.core.PrefixedChecksummedBytes
org.bitcoinj.core.Address
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<Address>
- Direct Known Subclasses:
LegacyAddress
,SegwitAddress
Base class for addresses, e.g. native segwit addresses (
SegwitAddress
) or legacy addresses (LegacyAddress
).
Use fromString(NetworkParameters, String)
to conveniently construct any kind of address from its textual
form.
- See Also:
-
Field Summary
Fields inherited from class org.bitcoinj.core.PrefixedChecksummedBytes
bytes, params
-
Constructor Summary
ModifierConstructorDescriptionprotected
Address
(NetworkParameters params, byte[] bytes) Construct an address from its binary form. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Comparator for the first two comparison fields inAddress
comparisons, seecompareTo(Address)
.abstract int
Comparison field order for addresses is:NetworkParameters.getId()
Legacy vs.static Address
fromKey
(NetworkParameters params, ECKey key, Script.ScriptType outputScriptType) static Address
fromString
(NetworkParameters params, String str) Construct an address from its textual form.abstract byte[]
getHash()
Get either the public key hash or script hash that is encoded in the address.abstract Script.ScriptType
Get the type of output script that will be used for sending to the address.Methods inherited from class org.bitcoinj.core.PrefixedChecksummedBytes
clone, equals, getParameters, hashCode
-
Constructor Details
-
Address
Construct an address from its binary form.- Parameters:
params
- the network this address is valid forbytes
- the binary address data
-
-
Method Details
-
fromString
public static Address fromString(@Nullable NetworkParameters params, String str) throws AddressFormatException Construct an address from its textual form.- Parameters:
params
- the expected network this address is valid for, or null if the network should be derived from the textual formstr
- the textual form of the address, such as "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL" or "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"- Returns:
- constructed address
- Throws:
AddressFormatException
- if the given string doesn't parse or the checksum is invalidAddressFormatException.WrongNetwork
- if the given string is valid but not for the expected network (eg testnet vs mainnet)
-
fromKey
public static Address fromKey(NetworkParameters params, ECKey key, Script.ScriptType outputScriptType) - Parameters:
params
- network this address is valid forkey
- only the public part is usedoutputScriptType
- script type the address should use- Returns:
- constructed address
-
getHash
public abstract byte[] getHash()Get either the public key hash or script hash that is encoded in the address.- Returns:
- hash that is encoded in the address
-
getOutputScriptType
Get the type of output script that will be used for sending to the address.- Returns:
- type of output script
-
compareTo
Comparison field order for addresses is:NetworkParameters.getId()
- Legacy vs. Segwit
- (Legacy only) Version byte
- remaining
bytes
Implementations may use
compareAddressPartial
for tests 1 and 2.- Specified by:
compareTo
in interfaceComparable<Address>
- Parameters:
o
- otherAddress
object- Returns:
- comparison result
-
compareAddressPartial
Comparator for the first two comparison fields inAddress
comparisons, seecompareTo(Address)
. Used byLegacyAddress.compareTo(Address)
andSegwitAddress.compareTo(Address)
.- Parameters:
o
- otherAddress
object- Returns:
- comparison result
-