Package org.bitcoinj.base
Interface Address
- All Superinterfaces:
Comparable<Address>
- All Known Implementing Classes:
LegacyAddress
,SegwitAddress
Interface for addresses, e.g. native segwit addresses (
SegwitAddress
) or legacy addresses (LegacyAddress
).
Use AddressParser
to construct any kind of address from its textual form.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Comparator<Address>
Comparator for the first two comparison fields inAddress
comparisons, seecompareTo(Address)
. -
Method Summary
Modifier and TypeMethodDescriptionint
Comparison field order for addresses is:Network.id()
Legacy vs.static int
compareTypes
(Address a, Address b) static Address
fromKey
(NetworkParameters params, ECKey key, ScriptType outputScriptType) Deprecated.static Address
fromString
(NetworkParameters params, String str) Deprecated.byte[]
getHash()
Get either the public key hash or script hash that is encoded in the address.Get the type of output script that will be used for sending to the address.default NetworkParameters
Deprecated.Usenetwork()
network()
Get the network this address is used on.
-
Field Details
-
PARTIAL_ADDRESS_COMPARATOR
Comparator for the first two comparison fields inAddress
comparisons, seecompareTo(Address)
. Used byLegacyAddress.compareTo(Address)
andSegwitAddress.compareTo(Address)
. For use by implementing classes only.
-
-
Method Details
-
fromString
@Deprecated static Address fromString(@Nullable NetworkParameters params, String str) throws AddressFormatException Deprecated.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 (e.g. testnet vs mainnet)
-
fromKey
@Deprecated static Address fromKey(NetworkParameters params, ECKey key, ScriptType outputScriptType) Deprecated.- Parameters:
params
- network this address is valid forkey
- only the public part is usedoutputScriptType
- script type the address should use- Returns:
- constructed address
-
getParameters
Deprecated.Usenetwork()
- Returns:
- network this data is valid for
-
getHash
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
ScriptType 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:Network.id()
- Legacy vs. Segwit
- (Legacy only) Version byte
- remaining
bytes
Implementations use
PARTIAL_ADDRESS_COMPARATOR
for tests 1 and 2.- Specified by:
compareTo
in interfaceComparable<Address>
- Parameters:
o
- otherAddress
object- Returns:
- comparison result
-
network
Network network()Get the network this address is used on. Returns the normalized network (see below.)Note: The network value returned is normalized. For example the address
"tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx"
may be used on eitherBitcoinNetwork.TESTNET
orBitcoinNetwork.SIGNET
, but the value returned by this method will always beBitcoinNetwork.TESTNET
. Similarly, the address"mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R"
may be used onBitcoinNetwork.TESTNET
,BitcoinNetwork.REGTEST
, orBitcoinNetwork.REGTEST
, but the value returned by this method will always beBitcoinNetwork.TESTNET
.- Returns:
- the Network.
-
compareTypes
-
ECKey.toAddress(ScriptType, Network)