mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 21:32:35 +01:00
LegacyAddress: Deprecate isP2SHAddress().
This commit is contained in:
parent
c0d8039c82
commit
d2caf699e1
@ -209,10 +209,8 @@ public class LegacyAddress extends Address {
|
||||
return p2sh ? ScriptType.P2SH : ScriptType.P2PKH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this address is a Pay-To-Script-Hash (P2SH) address.
|
||||
* See also https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki: Address Format for pay-to-script-hash
|
||||
*/
|
||||
/** @deprecated Use {@link #getOutputScriptType()} */
|
||||
@Deprecated
|
||||
public boolean isP2SHAddress() {
|
||||
return p2sh;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import com.google.protobuf.*;
|
||||
import org.bitcoinj.core.*;
|
||||
import org.bitcoinj.crypto.*;
|
||||
import org.bitcoinj.script.*;
|
||||
import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.bitcoinj.utils.*;
|
||||
import org.bitcoinj.wallet.listeners.KeyChainEventListener;
|
||||
import org.slf4j.*;
|
||||
@ -357,7 +358,7 @@ public class KeyChainGroup implements KeyBag {
|
||||
}
|
||||
|
||||
public void markP2SHAddressAsUsed(LegacyAddress address) {
|
||||
checkArgument(address.isP2SHAddress());
|
||||
checkArgument(address.getOutputScriptType() == ScriptType.P2SH);
|
||||
RedeemData data = findRedeemDataFromScriptHash(address.getHash());
|
||||
if (data == null)
|
||||
return; // Not our P2SH address.
|
||||
@ -400,7 +401,7 @@ public class KeyChainGroup implements KeyBag {
|
||||
|
||||
/** If the given P2SH address is "current", advance it to a new one. */
|
||||
private void maybeMarkCurrentAddressAsUsed(LegacyAddress address) {
|
||||
checkArgument(address.isP2SHAddress());
|
||||
checkArgument(address.getOutputScriptType() == ScriptType.P2SH);
|
||||
for (Map.Entry<KeyChain.KeyPurpose, LegacyAddress> entry : currentAddresses.entrySet()) {
|
||||
if (entry.getValue() != null && entry.getValue().equals(address)) {
|
||||
log.info("Marking P2SH address as used: {}", address);
|
||||
|
@ -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.Script.ScriptType;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@ -60,11 +61,11 @@ public class LegacyAddressTest {
|
||||
// Test a testnet address.
|
||||
LegacyAddress a = LegacyAddress.fromPubKeyHash(TESTNET, HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc"));
|
||||
assertEquals("n4eA2nbYqErp7H6jebchxAN59DmNpksexv", a.toString());
|
||||
assertFalse(a.isP2SHAddress());
|
||||
assertEquals(ScriptType.P2PKH, a.getOutputScriptType());
|
||||
|
||||
LegacyAddress b = LegacyAddress.fromPubKeyHash(MAINNET, HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
|
||||
assertEquals("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL", b.toString());
|
||||
assertFalse(b.isP2SHAddress());
|
||||
assertEquals(ScriptType.P2PKH, a.getOutputScriptType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -150,10 +151,10 @@ public class LegacyAddressTest {
|
||||
// Test that we can construct P2SH addresses
|
||||
LegacyAddress mainNetP2SHAddress = LegacyAddress.fromBase58(MainNetParams.get(), "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
|
||||
assertEquals(mainNetP2SHAddress.getVersion(), MAINNET.p2shHeader);
|
||||
assertTrue(mainNetP2SHAddress.isP2SHAddress());
|
||||
assertEquals(ScriptType.P2SH, mainNetP2SHAddress.getOutputScriptType());
|
||||
LegacyAddress testNetP2SHAddress = LegacyAddress.fromBase58(TestNet3Params.get(), "2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe");
|
||||
assertEquals(testNetP2SHAddress.getVersion(), TESTNET.p2shHeader);
|
||||
assertTrue(testNetP2SHAddress.isP2SHAddress());
|
||||
assertEquals(ScriptType.P2SH, testNetP2SHAddress.getOutputScriptType());
|
||||
|
||||
// Test that we can determine what network a P2SH address belongs to
|
||||
NetworkParameters mainNetParams = LegacyAddress.getParametersFromAddress("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
|
||||
|
@ -19,6 +19,7 @@ package org.bitcoinj.wallet;
|
||||
import org.bitcoinj.core.*;
|
||||
import org.bitcoinj.crypto.*;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.bitcoinj.utils.BriefLogFormatter;
|
||||
import org.bitcoinj.utils.Threading;
|
||||
import org.bitcoinj.wallet.listeners.KeyChainEventListener;
|
||||
@ -170,7 +171,7 @@ public class KeyChainGroupTest {
|
||||
public void currentP2SHAddress() throws Exception {
|
||||
group = createMarriedKeyChainGroup();
|
||||
LegacyAddress a1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertTrue(a1.isP2SHAddress());
|
||||
assertEquals(ScriptType.P2SH, a1.getOutputScriptType());
|
||||
LegacyAddress a2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertEquals(a1, a2);
|
||||
LegacyAddress a3 = group.currentAddress(KeyChain.KeyPurpose.CHANGE);
|
||||
@ -182,7 +183,7 @@ public class KeyChainGroupTest {
|
||||
group = createMarriedKeyChainGroup();
|
||||
LegacyAddress a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
LegacyAddress a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertTrue(a1.isP2SHAddress());
|
||||
assertEquals(ScriptType.P2SH, a1.getOutputScriptType());
|
||||
assertNotEquals(a1, a2);
|
||||
group.getBloomFilterElementCount();
|
||||
assertEquals(((group.getLookaheadSize() + group.getLookaheadThreshold()) * 2) // * 2 because of internal/external
|
||||
|
Loading…
Reference in New Issue
Block a user