LegacyAddress: Rename fromP2SHHash() static constructor to fromScriptHash(), keeping the old method as deprecated.

This commit is contained in:
Andreas Schildbach
2018-03-04 16:57:12 +01:00
parent bc8828c858
commit c7acfee1a4
4 changed files with 12 additions and 6 deletions

View File

@@ -108,10 +108,16 @@ public class LegacyAddress extends Address {
* P2SH script hash
* @return constructed address
*/
public static LegacyAddress fromP2SHHash(NetworkParameters params, byte[] hash160) throws AddressFormatException {
public static LegacyAddress fromScriptHash(NetworkParameters params, byte[] hash160) throws AddressFormatException {
return new LegacyAddress(params, true, hash160);
}
/** @deprecated use {@link #fromScriptHash(NetworkParameters, byte[])} */
@Deprecated
public static LegacyAddress fromP2SHHash(NetworkParameters params, byte[] hash160) {
return fromScriptHash(params, hash160);
}
/**
* Constructs a {@link LegacyAddress} that represents the script hash extracted from the given scriptPubKey.
*
@@ -123,7 +129,7 @@ public class LegacyAddress extends Address {
*/
public static LegacyAddress fromP2SHScript(NetworkParameters params, Script scriptPubKey) {
checkArgument(ScriptPattern.isPayToScriptHash(scriptPubKey), "Not a P2SH script");
return fromP2SHHash(params, ScriptPattern.extractHashFromPayToScriptHash(scriptPubKey));
return fromScriptHash(params, ScriptPattern.extractHashFromPayToScriptHash(scriptPubKey));
}
/**

View File

@@ -132,7 +132,7 @@ public class TransactionOutput extends ChildMessage {
@Deprecated
public LegacyAddress getAddressFromP2SH(NetworkParameters params) throws ScriptException {
if (ScriptPattern.isPayToScriptHash(getScriptPubKey()))
return LegacyAddress.fromP2SHHash(params, ScriptPattern.extractHashFromPayToScriptHash(getScriptPubKey()));
return LegacyAddress.fromScriptHash(params, ScriptPattern.extractHashFromPayToScriptHash(getScriptPubKey()));
return null;
}

View File

@@ -164,9 +164,9 @@ public class LegacyAddressTest {
// Test that we can convert them from hashes
byte[] hex = HEX.decode("2ac4b0b501117cc8119c5797b519538d4942e90e");
LegacyAddress a = LegacyAddress.fromP2SHHash(MAINNET, hex);
LegacyAddress a = LegacyAddress.fromScriptHash(MAINNET, hex);
assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", a.toString());
LegacyAddress b = LegacyAddress.fromP2SHHash(TESTNET, HEX.decode("18a0e827269b5211eb51a4af1b2fa69333efa722"));
LegacyAddress b = LegacyAddress.fromScriptHash(TESTNET, HEX.decode("18a0e827269b5211eb51a4af1b2fa69333efa722"));
assertEquals("2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe", b.toString());
LegacyAddress c = LegacyAddress.fromP2SHScript(MAINNET, ScriptBuilder.createP2SHOutputScript(hex));
assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", c.toString());

View File

@@ -153,7 +153,7 @@ public class WalletTest extends TestWithWallet {
@Test
public void basicSpendingToP2SH() throws Exception {
LegacyAddress destination = LegacyAddress.fromP2SHHash(UNITTEST, HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
LegacyAddress destination = LegacyAddress.fromScriptHash(UNITTEST, HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
basicSpendingCommon(wallet, myAddress, destination, null);
}