Package org.bitcoinj.core
Class Address
- java.lang.Object
-
- org.bitcoinj.core.PrefixedChecksummedBytes
-
- org.bitcoinj.core.Address
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<Address>
- Direct Known Subclasses:
LegacyAddress
,SegwitAddress
public abstract class Address extends PrefixedChecksummedBytes implements java.lang.Comparable<Address>
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:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.bitcoinj.core.PrefixedChecksummedBytes
bytes, params
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Address(NetworkParameters params, byte[] bytes)
Construct an address from its binary form.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected int
compareAddressPartial(Address o)
Comparator for the first two comparison fields inAddress
comparisons, seecompareTo(Address)
.abstract int
compareTo(Address o)
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, java.lang.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
getOutputScriptType()
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 Detail
-
Address
protected Address(NetworkParameters params, byte[] bytes)
Construct an address from its binary form.- Parameters:
params
- the network this address is valid forbytes
- the binary address data
-
-
Method Detail
-
fromString
public static Address fromString(@Nullable NetworkParameters params, java.lang.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
public abstract Script.ScriptType getOutputScriptType()
Get the type of output script that will be used for sending to the address.- Returns:
- type of output script
-
compareTo
public abstract int compareTo(Address o)
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 interfacejava.lang.Comparable<Address>
- Parameters:
o
- otherAddress
object- Returns:
- comparison result
-
compareAddressPartial
protected int compareAddressPartial(Address o)
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
-
-