mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-30 19:41:24 +00:00
LegacyAddress: Rename fromP2SHHash() static constructor to fromScriptHash(), keeping the old method as deprecated.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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());
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user