Address: add network() helper to allow migrating away from using NetworkParameters

This commit is contained in:
Sean Gilligan 2022-06-24 14:44:06 -07:00 committed by Andreas Schildbach
parent 1d5e752917
commit 26117bbda8

View file

@ -18,6 +18,7 @@ package org.bitcoinj.core;
import org.bitcoinj.base.ScriptType;
import org.bitcoinj.base.exceptions.AddressFormatException;
import org.bitcoinj.utils.Network;
import javax.annotation.Nullable;
import java.util.Arrays;
@ -148,6 +149,15 @@ public abstract class Address implements Comparable<Address> {
@Override
abstract public int compareTo(Address o);
/**
* Get the network this address works on. Use of {@link Network} is preferred to use of {@link NetworkParameters}
* when you need to know what network an address is for.
* @return the Network.
*/
public Network network() {
return params.network();
}
/**
* Comparator for the first two comparison fields in {@code Address} comparisons, see {@link Address#compareTo(Address)}.
* Used by {@link LegacyAddress#compareTo(Address)} and {@link SegwitAddress#compareTo(Address)}.