Address, AddressParser: improve JavaDoc regarding network normalization

This commit is contained in:
Sean Gilligan 2023-10-02 09:59:00 -07:00 committed by Andreas Schildbach
parent a5ab229f9f
commit fea737b39b
2 changed files with 15 additions and 9 deletions

View file

@ -107,8 +107,13 @@ public interface Address extends Comparable<Address> {
int compareTo(Address o); int compareTo(Address o);
/** /**
* Get the network this address works on. Use of {@link BitcoinNetwork} is preferred to use of {@link NetworkParameters} * Get the network this address is used on. Returns the <i>normalized</i> network (see below.)
* when you need to know what network an address is for. * <p>
* <b>Note:</b> The network value returned is <i>normalized</i>. For example the address {@code "tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx"}
* may be used on either {@link BitcoinNetwork#TESTNET} or {@link BitcoinNetwork#SIGNET}, but the value returned by
* this method will always be {@link BitcoinNetwork#TESTNET}. Similarly, the address {@code "mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R"}
* may be used on {@link BitcoinNetwork#TESTNET}, {@link BitcoinNetwork#REGTEST}, or {@link BitcoinNetwork#REGTEST}, but
* the value returned by this method will always be {@link BitcoinNetwork#TESTNET}.
* @return the Network. * @return the Network.
*/ */
Network network(); Network network();

View file

@ -22,17 +22,18 @@ import org.bitcoinj.core.NetworkParameters;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
* Functional interface for address parsing. It takes a single parameter, but its behavior is context-specific. For example if the * Functional interface for parsing an {@link Address}. It takes a {@link String} parameter and will parse address
* function was created with ({@link AddressParser#getDefault(Network)} it will only parse addresses for a single expected * strings for a configured set of {@link Network}s. For example, if the parser was created with ({@link AddressParser#getDefault(Network)}
* value of {@link Network}. Or, if created with {@link AddressParser#getDefault()} it will parse addresses matching any * it will only parse addresses for the provided value of {@link Network}. If created with {@link AddressParser#getDefault()} it will parse
* network. The default set of known networks is defined by {@link BitcoinNetwork}, but be aware that the {@link Address#network()} value * addresses matching any known network. The default set of known networks is defined by {@link BitcoinNetwork}.
* is normalized (see {@link Address} for details. * <p>
* Note: Be aware that the value returned by {@link Address#network()} will be normalized. See {@link Address#network()} for details.
*/ */
@FunctionalInterface @FunctionalInterface
public interface AddressParser { public interface AddressParser {
/** /**
* Parse an address for any known/configured network * Parse an address for a configured set of {@link Network}s.
* @param addressString string representation of address * @param addressString string representation of an address
* @return A validated address object * @return A validated address object
* @throws AddressFormatException invalid address string * @throws AddressFormatException invalid address string
*/ */