Address: Make main constructor private.

There is no reason to call it directly.
This commit is contained in:
Andreas Schildbach
2018-02-27 11:19:04 +01:00
parent ebd402eb4b
commit cc2e8ba935
2 changed files with 12 additions and 5 deletions

View File

@@ -51,11 +51,18 @@ public class Address extends VersionedChecksummedBytes {
private transient NetworkParameters params;
/**
* Construct an address from parameters, the address version, and the hash160 form. Example:<p>
*
* <pre>new Address(MainNetParams.get(), NetworkParameters.getAddressHeader(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));</pre>
* Private constructor. Use {@link #fromBase58(NetworkParameters, String)},
* {@link #Address(NetworkParameters, byte[])}, {@link #fromP2SHHash(NetworkParameters, byte[])} or
* {@link #fromKey(NetworkParameters, ECKey)}.
*
* @param params
* network this address is valid for
* @param version
* version header of the address
* @param hash160
* 20-byte hash of pubkey or script
*/
public Address(NetworkParameters params, int version, byte[] hash160) throws WrongNetworkException {
private Address(NetworkParameters params, int version, byte[] hash160) throws WrongNetworkException {
super(version, hash160);
checkNotNull(params);
checkArgument(hash160.length == 20, "Addresses are 160-bit hashes, so you must provide 20 bytes");

View File

@@ -152,7 +152,7 @@ public class WalletTest extends TestWithWallet {
@Test
public void basicSpendingToP2SH() throws Exception {
Address destination = new Address(PARAMS, PARAMS.getP2SHHeader(), HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
Address destination = Address.fromP2SHHash(PARAMS, HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
basicSpendingCommon(wallet, myAddress, destination, null);
}