Class SegwitAddress

    • Field Detail

      • WITNESS_PROGRAM_LENGTH_PKH

        public static final int WITNESS_PROGRAM_LENGTH_PKH
        See Also:
        Constant Field Values
      • WITNESS_PROGRAM_LENGTH_SH

        public static final int WITNESS_PROGRAM_LENGTH_SH
        See Also:
        Constant Field Values
      • WITNESS_PROGRAM_LENGTH_TR

        public static final int WITNESS_PROGRAM_LENGTH_TR
        See Also:
        Constant Field Values
      • WITNESS_PROGRAM_MIN_LENGTH

        public static final int WITNESS_PROGRAM_MIN_LENGTH
        See Also:
        Constant Field Values
      • WITNESS_PROGRAM_MAX_LENGTH

        public static final int WITNESS_PROGRAM_MAX_LENGTH
        See Also:
        Constant Field Values
      • network

        protected final Network network
      • witnessVersion

        protected final short witnessVersion
      • witnessProgram

        protected final byte[] witnessProgram
    • Method Detail

      • getWitnessVersion

        public int getWitnessVersion()
        Returns the witness version in decoded form. Only versions 0 and 1 are in use right now.
        Returns:
        witness version, between 0 and 16
      • getWitnessProgram

        public byte[] getWitnessProgram()
        Returns the witness program in decoded form.
        Returns:
        witness program
      • getHash

        public byte[] getHash()
        Description copied from interface: Address
        Get either the public key hash or script hash that is encoded in the address.
        Specified by:
        getHash in interface Address
        Returns:
        hash that is encoded in the address
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • fromBech32

        @Deprecated
        public static SegwitAddress fromBech32​(@Nullable
                                               NetworkParameters params,
                                               java.lang.String bech32)
                                        throws AddressFormatException
        Deprecated.
        Construct a SegwitAddress from its textual form.
        Parameters:
        params - expected network this address is valid for, or null if the network should be derived from the bech32
        bech32 - bech32-encoded textual form of the address
        Returns:
        constructed address
        Throws:
        AddressFormatException - if something about the given bech32 address isn't right
      • fromBech32

        public static SegwitAddress fromBech32​(java.lang.String bech32,
                                               @Nonnull
                                               Network network)
                                        throws AddressFormatException
        Construct a SegwitAddress from its textual form.
        Parameters:
        bech32 - bech32-encoded textual form of the address
        network - expected network this address is valid for
        Returns:
        constructed address
        Throws:
        AddressFormatException - if something about the given bech32 address isn't right
      • fromHash

        @Deprecated
        public static SegwitAddress fromHash​(NetworkParameters params,
                                             byte[] hash)
        Deprecated.
        Construct a 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.
        Parameters:
        params - network this address is valid for
        hash - 20-byte pubkey hash or 32-byte script hash
        Returns:
        constructed address
      • fromHash

        public static SegwitAddress fromHash​(Network network,
                                             byte[] hash)
        Construct a 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.
        Parameters:
        network - network this address is valid for
        hash - 20-byte pubkey hash or 32-byte script hash
        Returns:
        constructed address
      • fromProgram

        @Deprecated
        public static SegwitAddress fromProgram​(NetworkParameters params,
                                                int witnessVersion,
                                                byte[] witnessProgram)
        Construct a SegwitAddress that represents the given program, which is either a pubkey, a pubkey hash or a script hash – depending on the script version. The resulting address will be either a P2WPKH, a P2WSH or a P2TR type of address.
        Parameters:
        params - network this address is valid for
        witnessVersion - version number between 0 and 16
        witnessProgram - version dependent witness program
        Returns:
        constructed address
      • fromProgram

        public static SegwitAddress fromProgram​(Network network,
                                                int witnessVersion,
                                                byte[] witnessProgram)
        Construct a SegwitAddress that represents the given program, which is either a pubkey, a pubkey hash or a script hash – depending on the script version. The resulting address will be either a P2WPKH, a P2WSH or a P2TR type of address.
        Parameters:
        network - network this address is valid for
        witnessVersion - version number between 0 and 16
        witnessProgram - version dependent witness program
        Returns:
        constructed address
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • toBech32

        public java.lang.String toBech32()
        Returns the textual form of the address.
        Returns:
        textual form encoded in bech32
      • compareTo

        public int compareTo​(Address o)
        Comparison field order for addresses is:
        1. Network.id()
        2. Legacy vs. Segwit
        3. (Legacy only) Version byte
        4. remaining bytes

        Implementations use Address.PARTIAL_ADDRESS_COMPARATOR for tests 1 and 2.

        Specified by:
        compareTo in interface Address
        Specified by:
        compareTo in interface java.lang.Comparable<Address>
        Parameters:
        o - other Address object
        Returns:
        comparison result