public class SegwitAddress extends Address
Implementation of native segwit addresses. They are composed of two parts:
NetworkParameters.getSegwitAddressHrp().See BIP173 for details.
However, you don't need to care about the internals. Use fromBech32(NetworkParameters, String),
fromHash(NetworkParameters, byte[]) or fromKey(NetworkParameters, ECKey) to construct a native
segwit address.
| Modifier and Type | Field and Description |
|---|---|
static int |
WITNESS_PROGRAM_LENGTH_PKH |
static int |
WITNESS_PROGRAM_LENGTH_SH |
static int |
WITNESS_PROGRAM_MAX_LENGTH |
static int |
WITNESS_PROGRAM_MIN_LENGTH |
bytes, params| Modifier and Type | Method and Description |
|---|---|
static SegwitAddress |
fromBech32(NetworkParameters params,
java.lang.String bech32)
Construct a
SegwitAddress from its textual form. |
static SegwitAddress |
fromHash(NetworkParameters params,
byte[] hash)
Construct a
SegwitAddress that represents the given hash, which is either a pubkey hash or a script hash. |
static SegwitAddress |
fromKey(NetworkParameters params,
ECKey key)
Construct a
SegwitAddress that represents the public part of the given ECKey. |
byte[] |
getHash()
Get either the public key hash or script hash that is encoded in the address.
|
Script.ScriptType |
getOutputScriptType()
Get the type of output script that will be used for sending to the address.
|
byte[] |
getWitnessProgram()
Returns the witness program in decoded form.
|
int |
getWitnessVersion()
Returns the witness version in decoded form.
|
java.lang.String |
toBech32()
Returns the textual form of the address.
|
java.lang.String |
toString() |
fromKey, fromStringclone, compareTo, equals, getParameters, hashCodepublic static final int WITNESS_PROGRAM_LENGTH_PKH
public static final int WITNESS_PROGRAM_LENGTH_SH
public static final int WITNESS_PROGRAM_MIN_LENGTH
public static final int WITNESS_PROGRAM_MAX_LENGTH
public int getWitnessVersion()
public byte[] getWitnessProgram()
public byte[] getHash()
Addresspublic Script.ScriptType getOutputScriptType()
Script.ScriptType#P2WPKH or Script.ScriptType#P2WSH.getOutputScriptType in class Addresspublic java.lang.String toString()
toString in class java.lang.Objectpublic static SegwitAddress fromBech32(@Nullable NetworkParameters params, java.lang.String bech32) throws AddressFormatException
SegwitAddress from its textual form.params - expected network this address is valid for, or null if the network should be derived from the bech32bech32 - bech32-encoded textual form of the addressAddressFormatException - if something about the given bech32 address isn't rightpublic static SegwitAddress fromHash(NetworkParameters params, byte[] hash)
SegwitAddress that represents the given hash, which is either a pubkey hash or a script hash.
The resulting address will be either a P2WPKH or a P2WSH type of address.params - network this address is valid forhash - 20-byte pubkey hash or 32-byte script hashpublic static SegwitAddress fromKey(NetworkParameters params, ECKey key)
SegwitAddress that represents the public part of the given ECKey. Note that an
address is derived from a hash of the public key and is not the public key itself.params - network this address is valid forkey - only the public part is usedpublic java.lang.String toBech32()