mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 21:32:35 +01:00
LegacyAddress: Deprecate fromP2SHScript() static constructor.
This commit is contained in:
parent
c7acfee1a4
commit
4971d3fc25
@ -119,14 +119,10 @@ public class LegacyAddress extends Address {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link LegacyAddress} that represents the script hash extracted from the given scriptPubKey.
|
||||
*
|
||||
* @param params
|
||||
* network this address is valid for
|
||||
* @param scriptPubKey
|
||||
* scriptPubKey
|
||||
* @return constructed address
|
||||
* @deprecated use {@link #fromScriptHash(NetworkParameters, byte[])} in combination with
|
||||
* {@link ScriptPattern#extractHashFromPayToScriptHash(Script)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static LegacyAddress fromP2SHScript(NetworkParameters params, Script scriptPubKey) {
|
||||
checkArgument(ScriptPattern.isPayToScriptHash(scriptPubKey), "Not a P2SH script");
|
||||
return fromScriptHash(params, ScriptPattern.extractHashFromPayToScriptHash(scriptPubKey));
|
||||
|
@ -293,7 +293,7 @@ public class Script {
|
||||
if (ScriptPattern.isPayToPubKeyHash(this))
|
||||
return LegacyAddress.fromPubKeyHash(params, ScriptPattern.extractHashFromPayToPubKeyHash(this));
|
||||
else if (ScriptPattern.isPayToScriptHash(this))
|
||||
return LegacyAddress.fromP2SHScript(params, this);
|
||||
return LegacyAddress.fromScriptHash(params, ScriptPattern.extractHashFromPayToScriptHash(this));
|
||||
else if (forcePayToPubKey && ScriptPattern.isPayToPubKey(this))
|
||||
return LegacyAddress.fromKey(params, ECKey.fromPublicOnly(ScriptPattern.extractKeyFromPayToPubKey(this)));
|
||||
else if (ScriptPattern.isPayToWitnessHash(this))
|
||||
|
@ -246,7 +246,8 @@ public class KeyChainGroup implements KeyBag {
|
||||
if (chain.isMarried()) {
|
||||
Script outputScript = chain.freshOutputScript(purpose);
|
||||
checkState(ScriptPattern.isPayToScriptHash(outputScript)); // Only handle P2SH for now
|
||||
LegacyAddress freshAddress = LegacyAddress.fromP2SHScript(params, outputScript);
|
||||
LegacyAddress freshAddress = LegacyAddress.fromScriptHash(params,
|
||||
ScriptPattern.extractHashFromPayToScriptHash(outputScript));
|
||||
maybeLookaheadScripts();
|
||||
currentAddresses.put(purpose, freshAddress);
|
||||
return freshAddress;
|
||||
|
@ -1115,7 +1115,8 @@ public class Wallet extends BaseTaggableObject
|
||||
byte[] pubkeyHash = ScriptPattern.extractHashFromPayToPubKeyHash(script);
|
||||
keyChainGroup.markPubKeyHashAsUsed(pubkeyHash);
|
||||
} else if (ScriptPattern.isPayToScriptHash(script)) {
|
||||
LegacyAddress a = LegacyAddress.fromP2SHScript(tx.getParams(), script);
|
||||
LegacyAddress a = LegacyAddress.fromScriptHash(tx.getParams(),
|
||||
ScriptPattern.extractHashFromPayToScriptHash(script));
|
||||
keyChainGroup.markP2SHAddressAsUsed(a);
|
||||
}
|
||||
} catch (ScriptException e) {
|
||||
|
@ -22,6 +22,7 @@ import org.bitcoinj.params.Networks;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptBuilder;
|
||||
import org.bitcoinj.script.ScriptPattern;
|
||||
import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -168,7 +169,8 @@ public class LegacyAddressTest {
|
||||
assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", a.toString());
|
||||
LegacyAddress b = LegacyAddress.fromScriptHash(TESTNET, HEX.decode("18a0e827269b5211eb51a4af1b2fa69333efa722"));
|
||||
assertEquals("2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe", b.toString());
|
||||
LegacyAddress c = LegacyAddress.fromP2SHScript(MAINNET, ScriptBuilder.createP2SHOutputScript(hex));
|
||||
LegacyAddress c = LegacyAddress.fromScriptHash(MAINNET,
|
||||
ScriptPattern.extractHashFromPayToScriptHash(ScriptBuilder.createP2SHOutputScript(hex)));
|
||||
assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", c.toString());
|
||||
}
|
||||
|
||||
@ -184,7 +186,8 @@ public class LegacyAddressTest {
|
||||
|
||||
List<ECKey> keys = Arrays.asList(key1, key2, key3);
|
||||
Script p2shScript = ScriptBuilder.createP2SHOutputScript(2, keys);
|
||||
LegacyAddress address = LegacyAddress.fromP2SHScript(MAINNET, p2shScript);
|
||||
LegacyAddress address = LegacyAddress.fromScriptHash(MAINNET,
|
||||
ScriptPattern.extractHashFromPayToScriptHash(p2shScript));
|
||||
assertEquals("3N25saC4dT24RphDAwLtD8LUN4E2gZPJke", address.toString());
|
||||
}
|
||||
|
||||
|
@ -445,7 +445,8 @@ public class ScriptTest {
|
||||
assertEquals(toAddress, ScriptBuilder.createOutputScript(toAddress).getToAddress(TESTNET, true));
|
||||
// pay to script hash
|
||||
Script p2shScript = ScriptBuilder.createP2SHOutputScript(new byte[20]);
|
||||
LegacyAddress scriptAddress = LegacyAddress.fromP2SHScript(TESTNET, p2shScript);
|
||||
LegacyAddress scriptAddress = LegacyAddress.fromScriptHash(TESTNET,
|
||||
ScriptPattern.extractHashFromPayToScriptHash(p2shScript));
|
||||
assertEquals(scriptAddress, p2shScript.getToAddress(TESTNET, true));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user